mirror of https://github.com/docker/cli.git
Add back validation for invalid label values on containers
This adds validation to `docker container run` / `docker container create`; Validation of labels provided through flags was removed in31dc5c0a9a
, after the validation was changed to fix labels without values, and to prevent labels from being expanded with environment variables in2b17f4c8a8
However, now empty label names from _files_ (`--label-file`) followed different validation rules than labels passed through `--label`. This patch adds back minimal validation for labels passed through the command-line Before this patch: ```bash docker container create \ --name label \ --label==with-leading-equal-sign \ --label=without-value \ --label=somelabel=somevalue \ --label " = " \ --label=with-quotes-in-value='{"foo"}' \ --label='with"quotes"in-key=test' \ busybox docker container inspect --format '{{json .Config.Labels}}' label ``` ```json { "": "with-leading-equal-sign", " ": " ", "somelabel": "somevalue", "with\"quotes\"in-key": "test", "with-quotes-in-value": "{\"foo\"}", "without-value": "" } ``` After this patch: ```bash docker container create \ --name label \ --label==with-leading-equal-sign \ --label=without-value \ --label=somelabel=somevalue \ --label " = " \ --label=with-quotes-in-value='{"foo"}' \ --label='with"quotes"in-key=test' \ busybox invalid argument "=with-leading-equal-sign" for "-l, --label" flag: invalid label format: "=with-leading-equal-sign" ``` Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
f2424bd375
commit
b5d0d179e7
|
@ -147,7 +147,7 @@ func addFlags(flags *pflag.FlagSet) *containerOptions {
|
||||||
expose: opts.NewListOpts(nil),
|
expose: opts.NewListOpts(nil),
|
||||||
extraHosts: opts.NewListOpts(opts.ValidateExtraHost),
|
extraHosts: opts.NewListOpts(opts.ValidateExtraHost),
|
||||||
groupAdd: opts.NewListOpts(nil),
|
groupAdd: opts.NewListOpts(nil),
|
||||||
labels: opts.NewListOpts(nil),
|
labels: opts.NewListOpts(opts.ValidateLabel),
|
||||||
labelsFile: opts.NewListOpts(nil),
|
labelsFile: opts.NewListOpts(nil),
|
||||||
linkLocalIPs: opts.NewListOpts(nil),
|
linkLocalIPs: opts.NewListOpts(nil),
|
||||||
links: opts.NewListOpts(opts.ValidateLink),
|
links: opts.NewListOpts(opts.ValidateLink),
|
||||||
|
|
Loading…
Reference in New Issue