Skip to content

image name must not have leading or trailing whitespace #47491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

derekwaynecarr
Copy link
Member

@derekwaynecarr derekwaynecarr commented Jun 14, 2017

What this PR does / why we need it:
verifies that an image name can not have leading or trailing whitespace

Which issue this PR fixes
fixes #47490

Special notes for your reviewer:
i was surprised we had not caught this, so if there is an image spec that says leading and trailing whitespace is a good thing, i am open to correction.

i was made aware of downstream users of validate pod template spec that used " " as a special token. as a result, i only do the validation of image name " " in the Pod only.

Release note:

NONE

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jun 14, 2017
@k8s-github-robot k8s-github-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. release-note-none Denotes a PR that doesn't merit a release note. labels Jun 14, 2017
@derekwaynecarr
Copy link
Member Author

@eparis @smarterclayton -- in debugging events on our cluster, i observed 3 pods had an image name set to " ", and this resulted in ImageFailed events happening about 47k times for this pod over ~7d.

"name > 63 characters": {{Name: strings.Repeat("a", 64), Image: "image", ImagePullPolicy: "IfNotPresent", TerminationMessagePolicy: "File"}},
"name not a DNS label": {{Name: "a.b.c", Image: "image", ImagePullPolicy: "IfNotPresent", TerminationMessagePolicy: "File"}},
"zero-length name": {{Name: "", Image: "image", ImagePullPolicy: "IfNotPresent", TerminationMessagePolicy: "File"}},
"image leading and trailing whitespace": {{Name: "", Image: " image ", ImagePullPolicy: "IfNotPresent", TerminationMessagePolicy: "File"}},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about add another case of enabling image = " " like what you did in the test?

@derekwaynecarr derekwaynecarr force-pushed the fix-image-name-validation branch from 6d588bf to 73fdbbc Compare June 14, 2017 13:07
@derekwaynecarr
Copy link
Member Author

@gyliu513 - done

@derekwaynecarr derekwaynecarr added this to the v1.7 milestone Jun 14, 2017
@derekwaynecarr derekwaynecarr added the kind/bug Categorizes issue or PR as related to a bug. label Jun 14, 2017
@eparis
Copy link
Contributor

eparis commented Jun 14, 2017

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 14, 2017
@smarterclayton
Copy link
Contributor

/approve

This can't break anyone (docker daemon won't pull), it's confusing and accidental, and it causes issues for the rest of the cluster

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 14, 2017
Copy link
Contributor

@gyliu513 gyliu513 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@marun marun added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Jun 14, 2017
@@ -1975,6 +1975,9 @@ func validateContainers(containers []api.Container, volumes sets.String, fldPath
if len(ctr.Image) == 0 {
allErrs = append(allErrs, field.Required(idxPath.Child("image"), ""))
}
if len(strings.TrimSpace(ctr.Image)) != len(ctr.Image) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this used to validate all objects with pod specs, or just pods?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, can only be final pods.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, anyone that calls ValidatePodSpec, so this is picked up by all the job/rc/...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't see how image is special. we validate every other aspect of the pod spec when doing a validate pod template (volumes, affinity, etc.)

@smarterclayton smarterclayton removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 14, 2017
@smarterclayton
Copy link
Contributor

My concern is that for everything that uses a pod spec template today, "image": " " is valid JSON. In practice, you'd need an admission controller to leverage that, so it's unlikely to be a serious hole for anyone.

@derekwaynecarr
Copy link
Member Author

@smarterclayton - opened openshift/origin#14659

i will update this pr and reference that issue for rationale until we transitioned.

@derekwaynecarr derekwaynecarr force-pushed the fix-image-name-validation branch from 73fdbbc to 59b1bac Compare June 14, 2017 23:52
@k8s-github-robot k8s-github-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 14, 2017
@derekwaynecarr
Copy link
Member Author

@smarterclayton @liggitt - updated per request.

@smarterclayton
Copy link
Contributor

/lgtm

with the restricted scope

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 15, 2017
@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: derekwaynecarr, eparis, smarterclayton

Associated issue: 47490

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot
Copy link

Automatic merge from submit-queue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pod container image is allowed to just be a space character
10 participants