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 ImageReview backend to add audit annotations. #64597

Merged
merged 1 commit into from Aug 28, 2018

Conversation

wteiken
Copy link
Contributor

@wteiken wteiken commented Jun 1, 2018

What this PR does / why we need it:
This can be used to create annotations that will allow auditing of the created
pods.

The change also introduces "fail open" audit annotations in addition to the
previously existing pod annotation for fail open. The pod annotations for
fail open will be deprecated soon.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

Special notes for your reviewer:

Release note:

Allow ImageReview backend to return annotations to be added to the created pod.

@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/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 1, 2018
@k8s-ci-robot
Copy link
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


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.

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 1, 2018
@k8s-github-robot k8s-github-robot added the kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API label Jun 1, 2018
@wteiken wteiken changed the title Add an option for the ImageReview backend to add annotations to the pods Allow ImageReview backend to return annotations to be added to the pod Jun 1, 2018
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. 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. cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jun 1, 2018
@wteiken
Copy link
Contributor Author

wteiken commented Jun 1, 2018

/assign @derekwaynecarr @liggitt

@wteiken
Copy link
Contributor Author

wteiken commented Jun 1, 2018

Ideally this would to into the 1.11 release, given that this is a minor change.

@k8s-ci-robot
Copy link
Contributor

@wteiken: You must be a member of the kubernetes-milestone-maintainers github team to set the milestone.

In response to this:

/milestone v1.11

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.

@dims
Copy link
Member

dims commented Jun 13, 2018

/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 Jun 13, 2018
@k8s-ci-robot k8s-ci-robot removed the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 13, 2018
@k8s-ci-robot
Copy link
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


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.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Aug 13, 2018
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Aug 13, 2018
@wteiken
Copy link
Contributor Author

wteiken commented Aug 13, 2018

/assign @derekwaynecarr @liggitt

@wteiken
Copy link
Contributor Author

wteiken commented Aug 13, 2018

/test pull-kubernetes-e2e-gce-100-performance

@wteiken wteiken force-pushed the add_review_annotations2 branch 3 times, most recently from 2be487d to a17e101 Compare August 23, 2018 06:29
@wteiken
Copy link
Contributor Author

wteiken commented Aug 23, 2018

/test pull-kubernetes-e2e-kops-aws

@wteiken
Copy link
Contributor Author

wteiken commented Aug 23, 2018

@liggitt @tallclair Updated the PR to use the attributes annotations

// prefix-less (i.e., the admission controller will add an appropriate
// prefix). Annotations are only added to the attributes if the the
// creation is allowed.
AttributeAnnotations map[string]string
Copy link
Member

Choose a reason for hiding this comment

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

let's match the admission webhook response field name of auditAnnotations

Copy link
Contributor Author

Choose a reason for hiding this comment

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

k, will do.

// Annotations that should be added to the annotations in the attributes
// object of the admission controller request. The keys should be
// prefix-less (i.e., the admission controller will add an appropriate
// prefix). Annotations are only added to the attributes if the the
Copy link
Member

Choose a reason for hiding this comment

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

I'd expect to be able to add annotations to the audit event even for rejected requests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Up to now I assumed you'd just put the data in the error, but I can see that constraint is a bit artificial, will change.

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

return nil
}
for k, v := range review.Status.AttributeAnnotations {
attributes.AddAnnotation(AuditKeyPrefix+k, v)
Copy link
Member

Choose a reason for hiding this comment

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

check error and log a warning if if failed

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


// AuditKeyPrefix is used as the prefix for all audit keys handled by
// this pluggin. Some well known suffixes are listed below.
AuditKeyPrefix = PluginName + ".image-policy.k8s.io/"
Copy link
Member

Choose a reason for hiding this comment

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

are upper-case prefix names allowed in audit annotations? I didn't think they were

Copy link
Member

Choose a reason for hiding this comment

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

@tallclair @sttts seems like audit annotations should allow the qualified keys metadata annotations does

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The spec says it should be the plugin name. Should we just change the plugin name to all lower case?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, lowercase is required. We should update the documentation to clarify.

BTW - here is the validation we use on the annotation key:
https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apimachinery/pkg/util/validation/validation.go#L37-L70

Copy link
Member

Choose a reason for hiding this comment

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

that was for webhook-returned audit annotations... webhook admission plugin names are lowercase... I would lowercase the name for purposes of this annotation


// AuditKeyPrefix is used as the prefix for all audit keys handled by
// this pluggin. Some well known suffixes are listed below.
AuditKeyPrefix = PluginName + ".image-policy.k8s.io/"
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, lowercase is required. We should update the documentation to clarify.

BTW - here is the validation we use on the annotation key:
https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apimachinery/pkg/util/validation/validation.go#L37-L70

@@ -181,6 +199,12 @@ func (a *Plugin) admitPod(pod *api.Pod, attributes admission.Attributes, review
return errors.New("one or more images rejected by webhook backend")
}

if review.Status.AttributeAnnotations == nil {
return nil
}
Copy link
Member

Choose a reason for hiding this comment

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

nit: you don't need this - nil in go is equivalent to an empty slice, so the for loop will just skip.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Done

}
for _, tt := range tests {
// Use a closure so defer statements trigger between loop iterations.
func() {
Copy link
Member

Choose a reason for hiding this comment

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

prefer:

t.Run(tt.test, func(t *testing.T) { ... })

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

@liggitt
Copy link
Member

liggitt commented Aug 24, 2018

LGTM, please squash down (can leave the generated files in their own commit if you like), then will tag for merge

@wteiken wteiken changed the title Allow ImageReview backend to return annotations to be added to the pod Allow ImageReview backend to add audit annotations. Aug 24, 2018
This can be used to create annotations that will allow auditing of the created
pods.

The change also introduces "fail open" audit annotations in addition to the
previously existing pod annotation for fail open.  The pod annotations for
fail open will be deprecated soon.
@wteiken
Copy link
Contributor Author

wteiken commented Aug 24, 2018

@liggitt @tallclair Thanks for the review!

Squashed the branch, all tests pass.

@liggitt
Copy link
Member

liggitt commented Aug 24, 2018

/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 24, 2018
@wteiken
Copy link
Contributor Author

wteiken commented Aug 24, 2018

/assign @derekwaynecarr

@wteiken
Copy link
Contributor Author

wteiken commented Aug 27, 2018

@liggitt @tallclair Will this be picked up at some point or do I need to ping @derekwaynecarr explicitly?

@liggitt
Copy link
Member

liggitt commented Aug 27, 2018

ping is fine or add @deads2k for approval

@derekwaynecarr
Copy link
Member

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: derekwaynecarr, liggitt, wteiken

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 28, 2018
@k8s-github-robot
Copy link

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

@k8s-github-robot
Copy link

/test all

Tests are more than 96 hours old. Re-running tests.

@k8s-ci-robot
Copy link
Contributor

@wteiken: The following tests failed, say /retest to rerun them all:

Test name Commit Details Rerun command
pull-kubernetes-e2e-gce 73c522f link /test pull-kubernetes-e2e-gce
pull-kubernetes-kubemark-e2e-gce-big 73c522f link /test pull-kubernetes-kubemark-e2e-gce-big
pull-kubernetes-e2e-gce-100-performance 73c522f link /test pull-kubernetes-e2e-gce-100-performance

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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.

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 64597, 67854, 67734, 67917, 67688). If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit 583dd0f into kubernetes:master Aug 28, 2018
@wteiken
Copy link
Contributor Author

wteiken commented Aug 28, 2018

/retest

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. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API 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. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/apps Categorizes an issue or PR as relevant to SIG Apps. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants