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

Allow the strict IAM policies to be optional #3210

Conversation

KashifSaadat
Copy link
Contributor

@KashifSaadat KashifSaadat commented Aug 16, 2017

The stricter IAM policies could potentially cause regression for some edge-cases, or may rely on nodeup image changes that haven't yet been deployed / tagged officially (currently the case on master branch since PR #3158 was merged in).

This PR just wraps the new IAM policy rules around a cluster spec flag, EnableStrictIAM, so will default to the original behaviour (where the S3 policies were completely open). Could also be used to wrap PR #3186 if it progresses any further.

  • Or we could reject this and have the policies always strict! :)

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 16, 2017
@k8s-ci-robot
Copy link
Contributor

Hi @KashifSaadat. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@KashifSaadat
Copy link
Contributor Author

/assign @justinsb

@justinsb
Copy link
Member

We may yet need this, but I think that pushing a new nodeup (1.7.1.-beta.1) will unbreak master.

We should also get brew not building from HEAD :-)

@KashifSaadat KashifSaadat force-pushed the feature-gate-strict-iam-policies branch 2 times, most recently from 72532f3 to a761fa9 Compare August 18, 2017 12:28
@KashifSaadat
Copy link
Contributor Author

@justinsb I've updated this PR with your feedback from #3186, let me know what you think! :)

@justinsb
Copy link
Member

justinsb commented Aug 22, 2017

This looks great - I think this is absolutely the right approach.

One suggestion, to try to really encourage people to use strict mode.

Should it look like this:

iam:
  legacy: true

And deleting legacy: true or setting it to false would get us strict IAM. Also, in future we can make the type of legacy a BoolOrString or something like that (a similar type is used in memory resources), so that we could have degrees of legacy.

But I think legacy or maybe legacyCompatible would be clear - it isn't exactly insecure, but it is very much recommended to use the newer stricter IAM policies.

The problem though is that because the field's default value will be false, that isn't what we want for existing clusters - and the answer is defaults in apimachinery, i.e. something like this: https://github.com/kubernetes/kops/pull/3190/files#diff-2809c5296bfde5846dec21103f658f3f

(you'll need to do that for both v1alpha1 and v1alpha2, but not internal, because the defaults are applied as part of unmarshalling)

Then I also think kops create cluster should default to legacy: false, i.e. we should default to strict mode for new clusters; it is easy to switch (just a kops edit cluster, or we could expose a flag, or someone on slack was proposing a generic way of specifying fields).

What do you think @KashifSaadat ?

@justinsb
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 22, 2017
@KashifSaadat KashifSaadat force-pushed the feature-gate-strict-iam-policies branch from 4c58c2c to f965ebc Compare August 22, 2017 11:12
@KashifSaadat
Copy link
Contributor Author

Hey @justinsb. Thanks for the feedback, all sounds sensible and I agree with the changes. :)

I've had a go at this:

  • Changed switch to legacy
  • Default to false on cluster creation, so new clusters will use the stricter IAM policies
  • Updated apimachinery defaults, setting legacy to true if it's unset
  • Updated related tests

Manual tests:

  • Create new cluster, validate that strict policies are deployed: OK
  • Edit existing cluster, including IAM block and setting legacy to true: OK
  • Edit existing cluster, drop the IAM block (existing clusters won't have this API field in their Spec): Fails with the following:
# Found fields that are not recognized
# ...
#         name: c
#       name: events
# -   iam:
# -     legacy: true
#     kubernetesApiAccess:
#     - 0.0.0.0/0
# ...

It looks like those settings are being pulled from defaults correctly, but not sure why it's complaining. Are all users now required to manually include those settings within their spec, or am I missing something to silently include within the spec file?

@KashifSaadat
Copy link
Contributor Author

KashifSaadat commented Aug 22, 2017

Correction: This is working as expected, my manual test was wrong :)

I created a cluster from master, ran edit from my branch and it automatically includes the following within the spec file:

  iam:
    legacy: true

So this PR shouldn't force IAM changes to existing clusters.

@KashifSaadat KashifSaadat force-pushed the feature-gate-strict-iam-policies branch from f965ebc to 0e5c393 Compare August 22, 2017 12:28
@KashifSaadat
Copy link
Contributor Author

@justinsb by any chance are you able to spot any obvious errors in the work I've done, which may cause the e2e tests to fail? I've tested the cluster creation and operation locally (both with the legacy flag as true and false) and it seems to operate fine.

I've gone through the logs for the api server and the other services on the master node, can't see any specific correlation between the logs at the timestamp of the errors occurring. The only major change in this PR is the inclusion of the API flag. The stricter S3 IAM policies have already been deployed, so I don't believe it's related to that. Any pointers would be appreciated!

@justinsb
Copy link
Member

e2e tests are a flake I believe @KashifSaadat - I've seen them on docs PRs. There was a suspicious related PR that went in to k8s earlier today, so I suspect that's it, but I haven't yet had time to dig in. I will do it if it continues though!

/retest

@justinsb
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 22, 2017
}

type Assets struct {
ContainerRegistry *string `json:"containerRegistry,omitempty"`
FileRepository *string `json:"fileRepository,omitempty"`
}

// IAMSpec adds control over the IAM security policies applied to resources
type IAMSpec struct {
Legacy bool `json:"legacy"`
Copy link
Member

Choose a reason for hiding this comment

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

My preference is to include omitempty here (false is considered empty), but we can add that later - that's not breaking (I believe)

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 specified omitempty initially to have consistency with the other API fields. I was unsure if it may cause some problems with having the cluster creation default to a legacy value of false (not present in spec), and then the apimachinery defaults check for a nil value and set legacy to true. I should have done more validation before pushing up! :D

@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: KashifSaadat, justinsb

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 k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 22, 2017
@justinsb
Copy link
Member

Flakiness is being tracked in upstream issue: kubernetes/kubernetes#51128, hopefully fixed by kubernetes/kubernetes#51144

@eparis
Copy link
Contributor

eparis commented Aug 23, 2017

/retest
merged the referenced fix

@k8s-github-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@k8s-github-robot
Copy link

Automatic merge from submit-queue

@k8s-github-robot k8s-github-robot merged commit 34473e8 into kubernetes:master Aug 23, 2017
@KashifSaadat
Copy link
Contributor Author

Great, thanks guys!

@KashifSaadat KashifSaadat deleted the feature-gate-strict-iam-policies branch August 23, 2017 07:55
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. lgtm "Looks good to me", indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants