Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

Validate space name with a regexp in the controller (OSIO#3580) #2100

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

xcoulon
Copy link
Contributor

@xcoulon xcoulon commented May 24, 2018

This will prevent creating spaces with a name that cannot be used
as a value in pod labels.
The regexp used in the controller replaces the validation function
that was previously used at the design level, which allows for returning
proper JSON-API errors to the clients.

Fixes openshiftio/openshift.io#3580

Signed-off-by: Xavier Coulon [email protected]

@xcoulon xcoulon requested review from surajssd, kwk and aslakknutsen May 24, 2018 20:06
@xcoulon xcoulon force-pushed the IssueOSIO3580_delete_space branch from 553c482 to f595e14 Compare May 24, 2018 20:44
This will prevent creating spaces with a name that cannot be used
as a value in pod labels (matching max length and pattern).
The regexp and length checks in the controller replace the validation function
that was previously used at the design level, which allows for returning
proper JSON-API errors to the clients.

Fixes openshiftio/openshift.io#3580

Signed-off-by: Xavier Coulon <[email protected]>
@xcoulon xcoulon force-pushed the IssueOSIO3580_delete_space branch from f595e14 to 87bf371 Compare May 24, 2018 20:49
@@ -546,6 +547,18 @@ func (c *SpaceController) Update(ctx *app.UpdateSpaceContext) error {
return ctx.OK(&response)
}

const (
// see https://github.com/kubernetes/community/blob/master/contributors/design-proposals/architecture/identifiers.md
spaceNameMaxLength int = 63
Copy link
Contributor

Choose a reason for hiding this comment

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

@xcoulon space_max_length is hard coded at link. See if you can have shared variable here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, but I remove the use of the nameValidationFunction at the design level to validate the space name, actually. I'm not sure why the same length rule applies to area, etc., though...

Signed-off-by: Xavier Coulon <[email protected]>
@codecov-io
Copy link

codecov-io commented May 25, 2018

Codecov Report

Merging #2100 into master will decrease coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2100      +/-   ##
==========================================
- Coverage   69.05%   69.03%   -0.02%     
==========================================
  Files         162      162              
  Lines       15115    15105      -10     
==========================================
- Hits        10437    10428       -9     
- Misses       3730     3734       +4     
+ Partials      948      943       -5
Impacted Files Coverage Δ
controller/space.go 70.46% <100%> (+0.56%) ⬆️
migration/migration.go 60% <100%> (+0.13%) ⬆️
errors/errors.go 86.31% <100%> (ø) ⬆️
remoteworkitem/jira.go 75% <0%> (-25%) ⬇️
remoteworkitem/scheduler.go 53.65% <0%> (-7.32%) ⬇️
controller/workitem.go 79.41% <0%> (+0.62%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1e08ef3...fb8ba42. Read the comment docs.

@centos-ci
Copy link
Collaborator

@xcoulon Your image is available in the registry. Run docker pull registry.devshift.net/fabric8-services/fabric8-wit:SNAPSHOT-PR-2100 to get it.

@DhritiShikhar
Copy link
Contributor

The PR looks good to me.

xcoulon added 2 commits June 15, 2018 10:24
Also, enforce name requirement in the creatio operation, which
requires its own type in the design
also, rename the legacy `system.space` to `system-space` to avoid
test failures, and replace all ` ` with `-` in other tests as well.

Signed-off-by: Xavier Coulon <[email protected]>
@kwk
Copy link
Collaborator

kwk commented Jun 18, 2018

This will prevent creating spaces with a name that cannot be used
as a value in pod labels.

@xcoulon I find it highly interesting in the first place that we let ourselves dictated space name rules by some architecture. Shouldn't this architecture below, namely k8, just not care about space names?

@xcoulon
Copy link
Contributor Author

xcoulon commented Jun 19, 2018

@kwk right, the space name rule is bound to the namespace rule, indeed. That's for now the simplest way to create resources in relation with a given space on k8s, without having to deal with conflicting names if we decided to have a transformation from space name to namespace.

@kwk
Copy link
Collaborator

kwk commented Jun 19, 2018

@kwk right, the space name rule is bound to the namespace rule, indeed. That's for now the simplest way to create resources in relation with a given space on k8s, without having to deal with conflicting names if we decided to have a transformation from space name to namespace.

But if we need a name in k8 for something, can't we use the space's ID instead? That's unique.

var spacenameValidationFunction = func() {
a.MaxLength(63) // maximum name length is 63 characters
a.MinLength(1) // minimum name length is 1 characters
a.Pattern("^([A-Za-z0-9][-A-Za-z0-9]*)?[A-Za-z0-9]$")
Copy link
Contributor

Choose a reason for hiding this comment

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

So Kubernetes follows the RFC 1123 with respect to naming the namespaces. This RFC talks about the naming of hosts, since the namespace name then becomes the route/FQDN.

So the regex for the validation seems wrong, here is a reference from upstream
https://github.com/kubernetes/apimachinery/blob/241e268dc8e07223510442ab7d7902695c585d80/pkg/util/validation/validation.go#L106-L107

@xcoulon @kwk

Copy link
Collaborator

Choose a reason for hiding this comment

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

@surajssd if RFC 1123 can also handle UUIDs, then I'd says we use a space's ID in pods. @aslakknutsen is that possible? I don't see a good reason for why the pod naming conventions should block us from having more relaxed space naming conventions.

Copy link
Contributor

Choose a reason for hiding this comment

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

@kwk we don't name pods directly, I think we name things like the namespaces that are created in the user's account viz. run, stage, jenkins, etc. These are appended with their usernames, so they are unique across the cluster username-nstype as combination.

And about the pod names, pod get their names from the deployment or deploymentconfig we create, for example if you create a deployment with name foo then the pods get names like foo-xxx-xxxx. (here x are random strings)

And sorry my bad about the comment on the regex being wrong the rightful regex for validating the label value is

https://github.com/kubernetes/apimachinery/blob/241e268dc8e07223510442ab7d7902695c585d80/pkg/util/validation/validation.go#L29-L33

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants