Skip to content
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

feat(provider/kubernetes): v2 restrict namespaces for uploading manifests #2410

Merged
merged 3 commits into from
Mar 9, 2018

Conversation

gardleopard
Copy link
Contributor

@gardleopard gardleopard commented Mar 6, 2018

Solves spinnaker/spinnaker#2325

Depends on #2409

@gardleopard gardleopard changed the title feat(provider/kubernetes): v2 restrict namespaces for uploading manifests DNMY feat(provider/kubernetes): v2 restrict namespaces for uploading manifests Mar 6, 2018
@gardleopard
Copy link
Contributor Author

I have tested this now and it works, except I think the default namespace handling is strange.
It gets to this line

I think maybe I cannot use that method and also that it needs to check for the ommitnamespaces and ignore all of this if no namespaces are explicitly defined.

@@ -93,6 +100,11 @@ public boolean validateV2Credentials(AccountCredentialsProvider provider, String
return false;
}

if (!((KubernetesV2Credentials)credentials.getCredentials()).containsNamespace(namespace)) {
Copy link
Member

Choose a reason for hiding this comment

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

missing space after first )

@lwander
Copy link
Member

lwander commented Mar 7, 2018

Checking the omit namespace is definitely important - I don't think this should be the place to check the default namespace. I'm thinking some sort of validation should fail if someone specifies a "Default namespace" that they can't deploy to because it's not listed in the "namespaces", or omitted by the "omitNamespaces".

@gardleopard gardleopard changed the title DNMY feat(provider/kubernetes): v2 restrict namespaces for uploading manifests feat(provider/kubernetes): v2 restrict namespaces for uploading manifests Mar 8, 2018
@gardleopard
Copy link
Contributor Author

@lwander I have changed the logic and added tests for this now. I think the tests clearly shows the behaviour now.

@@ -115,6 +115,14 @@ public String getDefaultNamespace() {
return cachedDefaultNamespace;
}

public List<String> getNamespaces() {
Copy link
Member

Choose a reason for hiding this comment

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

I would just annotated the namespaces and omitNamespaces fields with @Getter like the properties above around line 77

protected boolean validateNamespace(String namespace, KubernetesV2Credentials credentials) {
final List<String> configuredNamespaces = credentials.getNamespaces();
if (configuredNamespaces != null && !configuredNamespaces.isEmpty() && !configuredNamespaces.contains(namespace)) {
reject( "wrongNamespace", "namespace");
Copy link
Member

Choose a reason for hiding this comment

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

Extra space before "

Copy link
Member

Choose a reason for hiding this comment

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

Also, should the string "namespace" be replaced with the actual requested namespace?


final List<String> omitNamespaces = credentials.getOmitNamespaces();
if (omitNamespaces != null && omitNamespaces.contains(namespace)) {
reject( "omittedNamespace", "namespace");
Copy link
Member

Choose a reason for hiding this comment

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

Extra space before "

if (!validateNotEmpty("account", accountName)) {
return false;
}

if (!validateNotEmpty("account", namespace)) {
Copy link
Member

Choose a reason for hiding this comment

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

Should this be "namespace"?

return true;
}

protected boolean validateNamespace(String namespace, KubernetesV2Credentials credentials) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm thinking we should skip this (e.g. return true) when namespace is empty. If none is supplied, the default will be used which should be valid.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in line 88 we check if the namespace is empty, so it wont reach this part of the code if a namespace is not supplied.

Copy link
Member

Choose a reason for hiding this comment

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

Ah I missed that - thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

Line 89 returns false, which is not correct for resources without a namespace. I've submitted #2422 to change this.

Copy link
Member

@lwander lwander left a comment

Choose a reason for hiding this comment

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

Great work!

@lwander lwander merged commit 299d35d into spinnaker:master Mar 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants