-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Validate project and image stream namespaces and names #2351
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
Validate project and image stream namespaces and names #2351
Conversation
@derekwaynecarr @ncdc PTAL |
result = append(result, fielderrors.NewFieldInvalid("metadata.namespace", stream.Namespace, "must be at least 2 characters long")) | ||
} | ||
if len(stream.Namespace+"/"+stream.Name) > 255 { | ||
result = append(result, fielderrors.NewFieldInvalid("metadata.name", stream.Name, "'namespace/name' must be less than 255 characters long")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<= 255, < 256
@ncdc imagestream comments addressed, |
repo := ns + "/" + ref.Name | ||
|
||
// Length checking | ||
if len(ns) < DockerMinNamespaceLength { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each component must be at least 2 chars - meaning both ns and ref.Name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can call this if you want https://github.com/docker/distribution/blob/master/registry/api/v2/names.go#L78
@ncdc updated to use docker constants/validation |
@@ -43,6 +44,17 @@ func ValidateImageStream(stream *api.ImageStream) fielderrors.ValidationErrorLis | |||
|
|||
result = append(result, validation.ValidateObjectMeta(&stream.ObjectMeta, true, MinimalNameValidation).Prefix("metadata")...) | |||
|
|||
// Ensure we can generate a valid docker image repository from namespace/name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is technically only relevant if the stream is using our internal registry. If spec.dockerImageRepository is set, it's ok to have a 1-char ns or name, since they won't be used in the push/pull spec. Not sure if it's worth making that distinction in the code, however.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since they can switch between internal/external post-creation, I'd rather keep this "strict" for now
ImageStream & DockerImageReference changes LGTM |
@@ -12,12 +11,14 @@ import ( | |||
) | |||
|
|||
// ValidateProject tests required fields for a Project. | |||
func ValidateProject(project *api.Project) fielderrors.ValidationErrorList { | |||
func ValidateProject(project *api.Project, create bool) fielderrors.ValidationErrorList { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need to change this signature.
On create we call:
https://github.com/openshift/origin/blob/master/pkg/project/registry/project/rest.go#L57
On update we call:
https://github.com/openshift/origin/blob/master/pkg/project/registry/project/rest.go#L67
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was calling ValidateProject()
, and I couldn't tell how it was used: https://github.com/openshift/origin/pull/2351/files#diff-f19a7777a36882029db668a427f950feL71
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was only used in an examples test, removed the signature change
[test] |
continuous-integration/openshift-jenkins/test FAILURE (https://ci.openshift.redhat.com/jenkins/job/test_pull_requests_origin/2330/) |
default: | ||
return ref, fmt.Errorf("the docker pull spec %q must be two or three segments separated by slashes", spec) | ||
} | ||
|
||
if len(ref.Namespace) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very scary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this code is used by things where this is not a safe assumption.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We had the defaulting for registry/name
but not for name
. What code do we have that expects no namespace in a pull spec?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
----- Original Message -----
default: return ref, fmt.Errorf("the docker pull spec %q must be two or three segments separated by slashes", spec) }
- if len(ref.Namespace) == 0 {
We had the defaulting for
registry/name
but not forname
. What code do we
have that expects no namespace in a pull spec?
Is library even present in v2?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm putting back the "library" defaulting where we had it before, and only validating what they passed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Library isn't a strict requirement in v2, but the Docker daemon still prepends library if you only specify foo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm less concerned if they give us an invalid spec and it fails. The crux of this PR was preventing them from giving us namespace/imagestream pieces we would assemble into an invalid image repository
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with keeping the library default the way it was originally
@smarterclayton, you ok with this now? |
@ncdc @smarterclayton backed out the changes in |
LGTM |
[merge] |
continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/merge_pull_requests_origin/2052/) (Image: devenv-fedora_1595) |
Evaluated for origin up to de47827 |
Merged by openshift-bot
To ensure we end up with valid image repository paths derived from ImageStreams, add the following validation:
To ensure we don't break updating an existing project/namespace that was created with a single character name:
Fixes #1232