Skip to content

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

Merged
merged 1 commit into from
May 22, 2015
Merged

Validate project and image stream namespaces and names #2351

merged 1 commit into from
May 22, 2015

Conversation

liggitt
Copy link
Contributor

@liggitt liggitt commented May 19, 2015

To ensure we end up with valid image repository paths derived from ImageStreams, add the following validation:

  • Require Project names to be >= 2 characters on creation
  • Require ImageStream namespaces to be >= 2 characters
  • Require ImageStream namespace+'/'+name to be <= 255 characters
  • Require ImageStream names to be valid docker image repository names

To ensure we don't break updating an existing project/namespace that was created with a single character name:

  • Allow updating projects with names < 2 characters

Fixes #1232

@liggitt
Copy link
Contributor Author

liggitt commented May 19, 2015

@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"))
Copy link
Contributor

Choose a reason for hiding this comment

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

<= 255, < 256

@liggitt
Copy link
Contributor Author

liggitt commented May 19, 2015

@ncdc imagestream comments addressed, ParseDockerImageReference validation added as well

repo := ns + "/" + ref.Name

// Length checking
if len(ns) < DockerMinNamespaceLength {
Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

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

@liggitt
Copy link
Contributor Author

liggitt commented May 19, 2015

@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
Copy link
Contributor

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.

Copy link
Contributor Author

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

@ncdc
Copy link
Contributor

ncdc commented May 19, 2015

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 {
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

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

Copy link
Contributor Author

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

@liggitt
Copy link
Contributor Author

liggitt commented May 19, 2015

[test]

@openshift-bot
Copy link
Contributor

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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Very scary.

Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor

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 for name. What code do we
have that expects no namespace in a pull spec?

Is library even present in v2?

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

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

@liggitt
Copy link
Contributor Author

liggitt commented May 21, 2015

@smarterclayton, you ok with this now?

@liggitt
Copy link
Contributor Author

liggitt commented May 21, 2015

@ncdc @smarterclayton backed out the changes in ParseDockerImageReference to limit the scope of this PR. PTAL

@ncdc
Copy link
Contributor

ncdc commented May 21, 2015

LGTM

@liggitt
Copy link
Contributor Author

liggitt commented May 21, 2015

[merge]

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/merge_pull_requests_origin/2052/) (Image: devenv-fedora_1595)

@openshift-bot
Copy link
Contributor

Evaluated for origin up to de47827

openshift-bot pushed a commit that referenced this pull request May 22, 2015
@openshift-bot openshift-bot merged commit ccdb67d into openshift:master May 22, 2015
@liggitt liggitt deleted the name_length_validation branch May 23, 2015 02:01
@ghost ghost mentioned this pull request May 26, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add name length validations to project creation
5 participants