Remove restrictions on docker env vars

Docker doesn't impose any restrictions on the contents of an env
var, and neither does the CLI and API so it doesn't make much sense
for the env var to be as restrictive.

Change-type: patch
This commit is contained in:
Felipe Lalanne 2022-03-31 16:45:11 -03:00
parent ffc61ee0b4
commit 1d4614c969
2 changed files with 12 additions and 9 deletions

View File

@ -82,13 +82,20 @@ export const NumericIdentifier = new t.Type<number, StringOrNumber>(
export type NumericIdentifier = t.TypeOf<typeof NumericIdentifier>;
/**
* Valid variable names are between 0 and 255 characters
* and match /^[a-zA-Z_][a-zA-Z0-9_]*$/
* Valid variable names are between 0 and 255 characters and do not contain `=`
*
* Docker has no restriction on what an environment variable name can be
* the shell may not be able to read non alphanumeric variable names,
* see https://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap08.html,
* but other processes (e.g. Node) may be able to read them.
*
* https://github.com/moby/moby/blob/88e1fec49011c539c9da299f8e58ec2e25dbf8f1/opts/env.go#L10-L17
*/
const VAR_NAME_REGEX = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
const VAR_NAME_REGEX = /^[^=]+$/;
export const VariableName = new t.Type<string, string>(
'VariableName',
// The variable length is a limitation from the cloud side and not from docker
(s: unknown): s is string => ShortString.is(s) && VAR_NAME_REGEX.test(s),
(i, c) =>
pipe(
@ -96,11 +103,7 @@ export const VariableName = new t.Type<string, string>(
chain((s) =>
VAR_NAME_REGEX.test(s)
? t.success(s)
: t.failure(
s,
c,
"needs to start with a letter and may only contain alphanumeric characters plus '_'",
),
: t.failure(s, c, "cannot have the '=' character"),
),
),
t.identity,

View File

@ -330,7 +330,7 @@ describe('validation', () => {
id: 45,
image_id: 34,
image: 'foo',
environment: { ' aaa': '123' },
environment: { 'bbb=aaa': '123' },
labels: {},
},
},