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

admission: don't update psp annotation on update #55486

Merged

Conversation

sttts
Copy link
Contributor

@sttts sttts commented Nov 10, 2017

Follow-up of #54689.

Related to #55435 as istio-like initializer-based container injection cannot contribute to SC mutations.

The PodSecurityPolicy annotation `kubernetes.io/psp` on pods is only set once on create.

@k8s-ci-robot k8s-ci-robot added do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Nov 10, 2017
@sttts sttts force-pushed the sttts-psp-admission-annotation branch from 264ef95 to 65ce2e0 Compare November 10, 2017 15:05
// if failOnNoPolicies is false.
// TODO: if failOnNoPolicies is toggled from false to true, we will never update the annotation anymore. Is this desired?
pod.ObjectMeta.Annotations[psputil.ValidatedPSPAnnotation] = pspName
pod.ObjectMeta.Annotations[psputil.InitiallyValidatedPSPAnnotation] = pspName
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note that before this PR we did not allow mutation in updates either (i.e. no serious mutation), but we were updating the annotation. Now we completely skip the mutating admission phase for update requests.

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Nov 10, 2017
@sttts
Copy link
Contributor Author

sttts commented Nov 10, 2017

We need the annotation in tests. An alternative would be to define a secret annotation on a pod: if that is found during admission, we update it to the chosen PSP. This secret annotation can be kubernetes.io/psp or kubernetes.io/initial-psp-on-create, or anything else.

@@ -26,7 +26,7 @@ import (
)

const (
ValidatedPSPAnnotation = "kubernetes.io/psp"
Copy link
Member

Choose a reason for hiding this comment

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

I wouldn't change the existing annotation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@liggitt
Copy link
Member

liggitt commented Nov 10, 2017

nit on not changing the annotation name, LGTM otherwise

@sttts sttts force-pushed the sttts-psp-admission-annotation branch 3 times, most recently from 3b5fb6f to 8a3a102 Compare November 10, 2017 17:30
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 10, 2017
@sttts
Copy link
Contributor Author

sttts commented Nov 10, 2017

@liggitt addressed the annotation comment. Will give the west-coast reviewers some time to review.

@liggitt
Copy link
Member

liggitt commented Nov 10, 2017

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 10, 2017
@tallclair
Copy link
Member

We need the annotation in tests.

This feels to me like the tests are testing the internal implementation, not the public interface. Maybe the solution is to rewrite those tests to not depend on this annotation?

As a longer term solution, this feels like something that might be useful in audit logs, along with things like which RBAC role authorized a user. I'm not sure exactly how that should be incorporated, but it seems like a more appropriate place for this sort of information. /cc @crassirostris

@@ -395,7 +400,7 @@ func TestAdmitPreferNonmutating(t *testing.T) {
pod: unprivilegedRunAsAnyPod.DeepCopy(),
oldPod: changedPod.DeepCopy(),
psps: []*extensions.PodSecurityPolicy{mutating2, mutating1},
shouldPassAdmit: false,
shouldPassAdmit: true,
Copy link
Member

Choose a reason for hiding this comment

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

"pod should not allow mutation on update"

Change the description of this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

pod: unprivilegedRunAsAnyPod.DeepCopy(),
oldPod: changedPod.DeepCopy(),
pod: podWithSC.DeepCopy(),
oldPod: changedPodWithSC.DeepCopy(),
Copy link
Member

Choose a reason for hiding this comment

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

nit: I think these names are backwards... changedPod* sohuld be the new one, not the "oldPod". Same for other test cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tried to follow the existing pattern there, but it confused me as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@sttts
Copy link
Contributor Author

sttts commented Nov 13, 2017

This feels to me like the tests are testing the internal implementation, not the public interface. Maybe the solution is to rewrite those tests to not depend on this annotation?

Our API is implicit, i.e. not introspectable. Our tests want to verify that the right PSP was chosen. If we don't want such an annotation, we have to find another way to detect that. Might be tricky.

@sttts
Copy link
Contributor Author

sttts commented Nov 13, 2017

As a longer term solution, this feels like something that might be useful in audit logs, along with things like which RBAC role authorized a user. I'm not sure exactly how that should be incorporated, but it seems like a more appropriate place for this sort of information. /cc @crassirostris

I like that idea. @crassirostris can you create an issue of audit+admission? With webhooks this will get even more important.

@sttts sttts force-pushed the sttts-psp-admission-annotation branch from 8a3a102 to b21b23b Compare November 13, 2017 10:16
@k8s-ci-robot k8s-ci-robot removed the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Nov 13, 2017
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Nov 13, 2017
@k8s-github-robot k8s-github-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 13, 2017
@sttts
Copy link
Contributor Author

sttts commented Nov 13, 2017

@tallclair updated. ptal

@sttts sttts added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 13, 2017
@@ -119,11 +119,15 @@ func (c *PodSecurityPolicyPlugin) Admit(a admission.Attributes) error {
return nil
}

// TODO(liggitt): allow spec mutation during initializing updates?
if a.GetOperation() != admission.Create {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not move this check into the shouldIgnore()?

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's not the same for Admit and Validate. We only skip the mutation on non-Create requests in mutating admission (= Admit).

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, thanks!

The logic become more and more sophisticated... If you will add a comment here, it would be good addition IMHO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@sttts
Copy link
Contributor Author

sttts commented Nov 13, 2017

/retest

@sttts sttts force-pushed the sttts-psp-admission-annotation branch from b21b23b to 3d5849f Compare November 13, 2017 16:10
@k8s-github-robot k8s-github-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 13, 2017
@sttts sttts added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 13, 2017
@sttts
Copy link
Contributor Author

sttts commented Nov 13, 2017

@tallclair @liggitt this is waiting for approval.

@liggitt
Copy link
Member

liggitt commented Nov 13, 2017

/approve

@sttts
Copy link
Contributor Author

sttts commented Nov 13, 2017

/retest

@deads2k
Copy link
Contributor

deads2k commented Nov 13, 2017

/approve no-issue

@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: deads2k, liggitt, sttts

Associated issue: 55435

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 Nov 13, 2017
@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 54005, 55127, 53850, 55486, 53440). If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit 560a310 into kubernetes:master Nov 14, 2017
@crassirostris
Copy link

@sttts @tallclair Sorry I'm little bit late to the party. Could you please clarify what you're suggesting here:

I like that idea. @crassirostris can you create an issue of audit+admission? With webhooks this will get even more important.

I'm not sure I understand the context

@sttts
Copy link
Contributor Author

sttts commented Nov 20, 2017

I'm not sure I understand the context

The PSP admission plugin matches a pod with a PodSecurityPolicy. If no policy matches, the pod is rejected. It would be helpful to know which policy made the pod pass the admission step.

@crassirostris
Copy link

@sttts Thanks! Created #56209

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. area/admission-control area/security 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. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants