support annotations for admission webhook#58679
support annotations for admission webhook#58679k8s-github-robot merged 3 commits intokubernetes:masterfrom
Conversation
1d0b1cd to
0c96dec
Compare
0c96dec to
9def9cf
Compare
|
@liggitt @tallclair @sttts This is also ready for review. |
9def9cf to
7db77c5
Compare
There was a problem hiding this comment.
there should be a specified format. What are the keys?
There was a problem hiding this comment.
This Annotation is a little bit different from annotation in admission attribute.
It doesn't contain the fully qualified plugin name.
I use this plugin name to call attributesRecord.SetAnnotations().
There was a problem hiding this comment.
plugin_name + ".admission.k8s.io/" + key ?
There was a problem hiding this comment.
We also have to check that the key is a DNS segment.
There was a problem hiding this comment.
We also have to check that the key is a DNS segment.
Done.
plugin_name + ".admission.k8s.io/" + key ?
plugin_name is already fully qualified.
Webhook plugin do not use .admission.k8s.io in their plugin name, I think.
There was a problem hiding this comment.
can this be queried by plugins in the chain? I don't like to open up this channel without good reasons.
There was a problem hiding this comment.
What about we move this mutex into SetAnnotations()?
There was a problem hiding this comment.
yes. And get rid of the single k/v SetAnnotations variant, but only for a whole map.
7db77c5 to
bdb4e11
Compare
There was a problem hiding this comment.
these names can theoretically overlap with the built in names. I guess we need h.Name + ".mutatingwebhook".
There was a problem hiding this comment.
This h.Name is already full qualified, like imagepolicy.kubernetes.io.
This name is set by cluster administrator.
What about we trust cluster administrator that he will not set a name overlap with the built in names?
There was a problem hiding this comment.
Not sure it's obvious that this name shows up in auditing. But imagepolicy.kubernetes.io.mutatingwebhook.admission.k8s.io is not nice either.
There was a problem hiding this comment.
What about we ignore h.Name?
And allow remote admission to set pluginName themselves?
If so, remote admsssion will be consistent with the build-in admission.
There was a problem hiding this comment.
we could also enforce that webhooks use *.mutatingwebhook.admission.k8s.io as key.
bdb4e11 to
43d7def
Compare
57bfb50 to
88b0dba
Compare
88b0dba to
dc9b1e8
Compare
|
/test pull-kubernetes-e2e-kops-aws |
There was a problem hiding this comment.
Should we consider this an admission error, or just log the error to the debug log? I guess considering it an admission error is failing closed.
There was a problem hiding this comment.
Actually, looking more closely I think this should be:
&webhookerrors.ErrCallingWebhook{WebhookName: h.name, Reason: err}
This type of error is either ignored or blocking depending on the webhook configuration. It is important to be able to ignore errors to avoid a misconfigured webhook from locking up the cluster.
There was a problem hiding this comment.
or just log the error to the debug log?
Done.
&webhookerrors.ErrCallingWebhook{WebhookName: h.name, Reason: err}
ErrCallingWebhook is returned for transport-layer errors calling webhooks. It represents a failure to talk to the webhook. So I log the error to the debug log rather than use ErrCallingWebhook
There was a problem hiding this comment.
Actually, looking more closely I think this should be:
&webhookerrors.ErrCallingWebhook{WebhookName: h.name, Reason: err}
Done. And I removed the transport-layer description about ErrCallingWebhook in comment.
Thanks.
There was a problem hiding this comment.
Instead of adding yet another argument to this, prefer exposing FakeAttributes and FakeAttributes.Annotations (or if you prefer, FakeAttributes.GetAnnotations)
There was a problem hiding this comment.
nit: initialize the map in this case, especially if exposing it directly.
pkg/apis/admission/types.go
Outdated
There was a problem hiding this comment.
Add more about the intent, e.g. Annotations may be provided by the admission webhook to add additional context to the audit log for this request
dc9b1e8 to
1eaa39d
Compare
There was a problem hiding this comment.
@tallclair Thanks for you review.
What do you think about current behavior?
|
/milestone v1.12 |
|
/retest |
|
/lgtm |
|
/assign @liggitt for api approval. |
|
[MILESTONENOTIFIER] Milestone Pull Request: Up-to-date for process @CaoShuFeng @liggitt @tallclair Pull Request Labels
|
pkg/apis/admission/types.go
Outdated
There was a problem hiding this comment.
will this be confused with the Annotations field on the API object being admitted? If we leave this named "Annotations", the documentation needs to be very clear that this is only audit logging. Alternately we could name it something like AuditAnnotations.
There was a problem hiding this comment.
We should also (in a separate PR) clarify the documentation on the audit.Event type that the map does not contain the annotations of the submitted object
There was a problem hiding this comment.
Agreed. I thought we discussed calling it ExtraAuditInfo, but can't find the reference. AuditAnnotations is ok too.
There was a problem hiding this comment.
AuditAnnotations is ok too.
Done.
We should also (in a separate PR) clarify the documentation on the audit.Event type that the map does not contain the annotations of the submitted object
Will do this after #65891 gets merged.
There was a problem hiding this comment.
#65891 is merged, can we queue up the change to the audit.Event annotations field doc?
pkg/apis/admission/types.go
Outdated
There was a problem hiding this comment.
replace "will fill in" with "will prefix the keys"
There was a problem hiding this comment.
if the key already is already namespaced to the webhook, noop?
edit: that would require the webhook to know the name by which it was registered, which isn't great, so forget that
There was a problem hiding this comment.
erroring on an existing key means that a mutating and validating webhook with the same name cannot set the same key, since they share a namespace
There was a problem hiding this comment.
erroring on an existing key means that a mutating and validating webhook with the same name cannot set the same key, since they share a namespace
Local mutating and validating admission may have same problem.
What about we trust the cluster admin here?
There was a problem hiding this comment.
message should say "validating webhook"
There was a problem hiding this comment.
I'm not sure this should be a fatal error... the in-tree annotation error handling just logs a warning:
kubernetes/plugin/pkg/admission/security/podsecuritypolicy/admission.go
Lines 168 to 170 in 4d5d266
There was a problem hiding this comment.
Updated to glog.Warningf and make them consistent with each other.
|
/test pull-kubernetes-e2e-kops-aws |
There was a problem hiding this comment.
should probably indicate the reason why in the warning message like the other places we do this (e.g. glog.Warningf("Failed to set annotations[%q] to %q for audit:%q, it has already been set to %q", key, value, ae.AuditID, ae.Annotations[key]))
|
@CaoShuFeng do you have a PR for the 1.12 docs branch for this? Thanks! |
Will work on it. |
|
@CaoShuFeng: The following test failed, say
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. DetailsInstructions 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. |
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: CaoShuFeng, liggitt, tallclair The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/test all [submit-queue is verifying that this PR is safe to merge] |
|
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions here. |
Depends on: #58143
Release note: