Skip to content

support annotations for admission webhook#58679

Merged
k8s-github-robot merged 3 commits intokubernetes:masterfrom
CaoShuFeng:admission_webhook
Aug 22, 2018
Merged

support annotations for admission webhook#58679
k8s-github-robot merged 3 commits intokubernetes:masterfrom
CaoShuFeng:admission_webhook

Conversation

@CaoShuFeng
Copy link
Copy Markdown
Contributor

@CaoShuFeng CaoShuFeng commented Jan 23, 2018

Depends on: #58143
Release note:

Support annotations for remote admission webhooks.

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jan 23, 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 Jan 23, 2018
@CaoShuFeng CaoShuFeng force-pushed the admission_webhook branch 2 times, most recently from 1d0b1cd to 0c96dec Compare January 24, 2018 06:30
@CaoShuFeng CaoShuFeng changed the title [WIP] support annotations for admission webhook support annotations for admission webhook Jan 28, 2018
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 28, 2018
@CaoShuFeng
Copy link
Copy Markdown
Contributor Author

@liggitt @tallclair @sttts This is also ready for review.
I had deployed a little remote admission controller to test it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

there should be a specified format. What are the keys?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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().

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

plugin_name + ".admission.k8s.io/" + key ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We also have to check that the key is a DNS segment.

Copy link
Copy Markdown
Contributor Author

@CaoShuFeng CaoShuFeng Jan 31, 2018

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can this be queried by plugins in the chain? I don't like to open up this channel without good reasons.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is ugly

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What about we move this mutex into SetAnnotations()?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yes. And get rid of the single k/v SetAnnotations variant, but only for a whole map.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

these names can theoretically overlap with the built in names. I guess we need h.Name + ".mutatingwebhook".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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?

// Name should be fully qualified, e.g., imagepolicy.kubernetes.io, where

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure it's obvious that this name shows up in auditing. But imagepolicy.kubernetes.io.mutatingwebhook.admission.k8s.io is not nice either.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we could also enforce that webhooks use *.mutatingwebhook.admission.k8s.io as key.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@CaoShuFeng CaoShuFeng force-pushed the admission_webhook branch from 57bfb50 to 88b0dba Compare July 5, 2018 01:41
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 5, 2018
@CaoShuFeng
Copy link
Copy Markdown
Contributor Author

/test pull-kubernetes-e2e-kops-aws

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

@CaoShuFeng CaoShuFeng Jul 12, 2018

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of adding yet another argument to this, prefer exposing FakeAttributes and FakeAttributes.Annotations (or if you prefer, FakeAttributes.GetAnnotations)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: initialize the map in this case, especially if exposing it directly.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ditto (ErrCallingWebhook)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@tallclair Thanks for you review.
What do you think about current behavior?

@tallclair
Copy link
Copy Markdown
Member

/milestone v1.12
/status approved-for-milestone

@tallclair
Copy link
Copy Markdown
Member

/retest

@tallclair
Copy link
Copy Markdown
Member

/lgtm

@sttts
Copy link
Copy Markdown
Contributor

sttts commented Jul 27, 2018

/assign @liggitt

for api approval.

@k8s-github-robot
Copy link
Copy Markdown

[MILESTONENOTIFIER] Milestone Pull Request: Up-to-date for process

@CaoShuFeng @liggitt @tallclair

Pull Request Labels
  • sig/api-machinery sig/auth: Pull Request will be escalated to these SIGs if needed.
  • priority/important-longterm: Escalate to the pull request owners; move out of the milestone after 1 attempt.
  • kind/feature: New functionality.
Help

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

@liggitt liggitt Jul 27, 2018

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Agreed. I thought we discussed calling it ExtraAuditInfo, but can't find the reference. AuditAnnotations is ok too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

@liggitt liggitt Aug 10, 2018

Choose a reason for hiding this comment

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

#65891 is merged, can we queue up the change to the audit.Event annotations field doc?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.
#67386

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

replace "will fill in" with "will prefix the keys"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Copy Markdown
Member

@liggitt liggitt Jul 27, 2018

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

message should say "validating webhook"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Copy Markdown
Member

@liggitt liggitt Jul 27, 2018

Choose a reason for hiding this comment

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

I'm not sure this should be a fatal error... the in-tree annotation error handling just logs a warning:

if err := a.AddAnnotation(key, pspName); err != nil {
glog.Warningf("failed to set admission audit annotation %s to %s: %v", key, pspName, err)
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated to glog.Warningf and make them consistent with each other.

@CaoShuFeng
Copy link
Copy Markdown
Contributor Author

/test pull-kubernetes-e2e-kops-aws

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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]))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@jimangel
Copy link
Copy Markdown
Member

@CaoShuFeng do you have a PR for the 1.12 docs branch for this? Thanks!

@CaoShuFeng
Copy link
Copy Markdown
Contributor Author

@CaoShuFeng do you have a PR for the 1.12 docs branch for this? Thanks!

Will work on it.

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

k8s-ci-robot commented Aug 17, 2018

@CaoShuFeng: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
pull-kubernetes-unit ad223e87a26cc4fd0f1017a93d55a5e10b879215 link /test pull-kubernetes-unit

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.

Details

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.

@liggitt
Copy link
Copy Markdown
Member

liggitt commented Aug 22, 2018

/lgtm

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[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

Details 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-github-robot
Copy link
Copy Markdown

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

@k8s-github-robot
Copy link
Copy Markdown

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions here.

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/audit 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 kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. 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/auth Categorizes an issue or PR as relevant to SIG Auth. 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.

9 participants