Skip to content

KEP-3488: Implement Enforcement Actions and Audit Annotations - #115973

Merged
k8s-ci-robot merged 3 commits into
kubernetes:masterfrom
jpbetz:enforcement-actions
Mar 7, 2023
Merged

KEP-3488: Implement Enforcement Actions and Audit Annotations#115973
k8s-ci-robot merged 3 commits into
kubernetes:masterfrom
jpbetz:enforcement-actions

Conversation

@jpbetz

@jpbetz jpbetz commented Feb 22, 2023

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind feature

What this PR does / why we need it:

Implements the Enforcement Actions and Audit Annotations sections of CEL for Admission Control.

Special notes for your reviewer:

Adding validationActions as a required field is a intentional (alpha stability) breaking change. We want developers setting this explicitly going forward.

Something we missed when writing the KEP: If multiple bindings for a policy match the same resource, I'd decided to have all the unique audit annotation values produced by the auditAnnotations concatenated into a comma-separated value. For simple cases where all the bindings produce the same audit annotation value, this results in that single value being published to the audit event. For cases where bindings produce different values, the values are concatenated into a comma-separated list so no information is lost. Better ideas on how to best combine the values into a single audit annotation value are welcome.

Deviations from the KEP:

  • Switched from {policyName}/validation_failure to the validation.policy.admission.k8s.io/validation_failure to adhere better to the conventions of audit annotations.
  • Custom audit annotations remain in the form {ValidatingPolicyDefinition name}/{auditAnnotation key}. We had wanted to offer a way to prevent a validating or mutating webhook from producing the exact same audit annotation as a ValidatingPolicyDefinition, but the structure of audit annotation keys makes this awkward because only one / is allowed and there is a length restriction on audit annotation keys.

Does this PR introduce a user-facing change?

Adds auditAnnotations to ValidatingAdmissionPolicy, enabling CEL to be used to add audit annotations to request audit events.
Adds validationActions to ValidatingAdmissionPolicyBinding, enabling validation failures to be handled by any combination of the warn, audit and deny enforcement actions.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. kind/feature Categorizes issue or PR as related to a new feature. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Feb 22, 2023
@jpbetz jpbetz changed the title Enforcement actions KEP-3488: Implement Enforcement Actions and Audit Annotations Feb 22, 2023
@jpbetz

jpbetz commented Feb 22, 2023

Copy link
Copy Markdown
Contributor Author

/sig api-machinery
/priority important-soon
/api-review

@k8s-ci-robot k8s-ci-robot added sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. labels Feb 22, 2023
@jpbetz

jpbetz commented Feb 22, 2023

Copy link
Copy Markdown
Contributor Author

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. area/apiserver and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Feb 22, 2023
@k8s-ci-robot k8s-ci-robot added area/code-generation area/test kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API sig/testing Categorizes an issue or PR as relevant to SIG Testing. labels Feb 22, 2023
@jpbetz
jpbetz force-pushed the enforcement-actions branch from d8c042d to ea772d8 Compare February 22, 2023 19:49
Comment thread pkg/apis/admissionregistration/types.go Outdated
Comment thread staging/src/k8s.io/api/admissionregistration/v1alpha1/types.go Outdated
Comment thread pkg/apis/admissionregistration/types.go Outdated
Comment thread staging/src/k8s.io/api/admissionregistration/v1alpha1/types.go Outdated
Comment thread staging/src/k8s.io/api/admissionregistration/v1alpha1/types.go Outdated
Comment thread staging/src/k8s.io/api/admissionregistration/v1alpha1/types.go Outdated
Comment thread pkg/apis/admissionregistration/validation/validation.go Outdated
Comment thread pkg/apis/admissionregistration/types.go Outdated
@jpbetz
jpbetz force-pushed the enforcement-actions branch from ea772d8 to d5537b1 Compare February 22, 2023 22:17
@k8s-triage-robot

Copy link
Copy Markdown

This PR may require API review.

If so, when the changes are ready, complete the pre-review checklist and request an API review.

Status of requested reviews is tracked in the API Review project.

@jpbetz

jpbetz commented Feb 22, 2023

Copy link
Copy Markdown
Contributor Author

@cici37 Feedback applied, thanks!

@jpbetz

jpbetz commented Feb 23, 2023

Copy link
Copy Markdown
Contributor Author

/retest

@sftim

sftim commented Feb 23, 2023

Copy link
Copy Markdown
Contributor

We had wanted to offer a way to prevent a validating or mutating webhook from producing the exact same audit annotation as a ValidatingPolicyDefinition, but the structure of audit annotation keys makes this awkward because only one / is allowed and there is a length restriction on audit annotation keys.

Does anything stop me from abusing this to write a well-known annotation key, or to try to fool someone into thinking I did?

@sftim

sftim commented Feb 27, 2023

Copy link
Copy Markdown
Contributor

I think the question of webhooks and what audit annotations those can write feels like a separate thing. We might still want to think about restricting those too.

Comment thread staging/src/k8s.io/api/admissionregistration/v1alpha1/types.go Outdated
Comment thread staging/src/k8s.io/api/admissionregistration/v1alpha1/types.go Outdated
Comment thread staging/src/k8s.io/api/admissionregistration/v1alpha1/types.go Outdated
Comment thread staging/src/k8s.io/api/admissionregistration/v1alpha1/types.go Outdated
Comment thread staging/src/k8s.io/api/admissionregistration/v1alpha1/types.go Outdated
Comment thread staging/src/k8s.io/api/admissionregistration/v1alpha1/types.go Outdated
Comment thread staging/src/k8s.io/api/admissionregistration/v1alpha1/types.go Outdated
Comment thread staging/src/k8s.io/api/admissionregistration/v1alpha1/types.go Outdated
Comment thread pkg/apis/admissionregistration/validation/validation.go Outdated
Comment thread pkg/apis/admissionregistration/validation/validation.go Outdated
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 2, 2023
@jpbetz
jpbetz force-pushed the enforcement-actions branch from 924a506 to 1d8bda2 Compare March 3, 2023 03:28
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 3, 2023
@jpbetz

jpbetz commented Mar 3, 2023

Copy link
Copy Markdown
Contributor Author

Rebased and API review feedback applied!

Comment thread pkg/apis/admissionregistration/validation/validation.go Outdated
Comment thread pkg/apis/admissionregistration/validation/validation.go Outdated
Comment thread pkg/apis/admissionregistration/validation/validation.go Outdated
Comment thread staging/src/k8s.io/apiserver/pkg/admission/plugin/cel/compile.go Outdated

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.

Why to remove this nil check?

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.

Now that we have both validations and auditAnnotations, it is possible for one of the calls to Compile to have an empty slice. We could write special case cost to avoid the compile call, but it is less error prone to make the compile calls safe by not returning an error here.

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.

Here is not really a err handling but rather a short circus. I am ok with either since it is nit and not a blocker any way :)

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.

Why this is different than the number in validation?
Also, maybe have a comment to remind keeping it same as it is in validation if it should be the same.
A following up PR might be add this to celconfig file we used in #115747

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.

An expressions that concatenate strings will often produce a longer value than the expression, so the expression limit is set at 5kb and the annotation value limits is set at 10k.

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.

Maybe use PolicyName and BindingName here since we only assign name not the entire policy/binding?

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.

I was trying to save space since I'm already concerned with the data volume produced by these audit annotation values. It should be clear enough? Let me know if you feel strongly about 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.

Just thought we have Policy/Binding all over and it's easily confused in terms of code maintenance.
It is not a merging blocker though :)

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.

Is that possible that evalResult.ExpressionAccessor is nil and evalResult.Error saved the err?
Looks at the code path checks evalResult.ExpressionAccessor.(*AuditAnnotationCondition) before evalResult.Error and the error might be ignored?

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 is the same order as for validations above. This !ok check is a failure that should never be reached if the code is working as expected (and will go away when we switch to using generics here).

@liggitt liggitt left a comment

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.

A couple nits/suggestions, but API types, validation, and docs lgtm.

Once the compile/admission/impl bits are reviewed/approved, tag me back in and I can approve.

Comment thread pkg/apis/admissionregistration/validation/validation.go Outdated
Comment thread pkg/apis/admissionregistration/validation/validation.go Outdated
Comment thread pkg/apis/admissionregistration/validation/validation.go Outdated
@jpbetz
jpbetz force-pushed the enforcement-actions branch from 5df742e to 5d7aa42 Compare March 6, 2023 22:40
Comment thread staging/src/k8s.io/apiserver/pkg/admission/plugin/cel/filter_test.go Outdated
@cici37

cici37 commented Mar 6, 2023

Copy link
Copy Markdown
Contributor

Looks like the tests messages need to be updated with the code updates. Couple nits. Overall LGTM :)

@jpbetz
jpbetz force-pushed the enforcement-actions branch from 7157751 to 012ef09 Compare March 6, 2023 23:56
@jpbetz

jpbetz commented Mar 6, 2023

Copy link
Copy Markdown
Contributor Author

Feedback applied and commits squashed to minimal set (with codegen separated out)

@jpbetz
jpbetz force-pushed the enforcement-actions branch from 012ef09 to c2b3871 Compare March 7, 2023 02:56
@cici37

cici37 commented Mar 7, 2023

Copy link
Copy Markdown
Contributor

/lgtm
/approve

/test pull-kubernetes-e2e-kind-ipv6

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 7, 2023
@k8s-ci-robot

Copy link
Copy Markdown
Contributor

LGTM label has been added.

DetailsGit tree hash: fbbfb21bd33f40a55ccdbfc530ec543351172d47

@liggitt

liggitt commented Mar 7, 2023

Copy link
Copy Markdown
Member

/approve
for API changes

@k8s-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cici37, jpbetz, liggitt

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-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 7, 2023
@k8s-ci-robot
k8s-ci-robot merged commit 0467542 into kubernetes:master Mar 7, 2023
@k8s-ci-robot k8s-ci-robot added this to the v1.27 milestone Mar 7, 2023
@jpbetz jpbetz mentioned this pull request Mar 9, 2023
mhan8796 pushed a commit to mhan8796/kubernetes that referenced this pull request Jun 27, 2026
KEP-3488: Implement Enforcement Actions and Audit Annotations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-review Categorizes an issue or PR as actively needing an API review. approved Indicates a PR has been approved by an approver from all required OWNERS files. area/apiserver area/code-generation area/test 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-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. 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/testing Categorizes an issue or PR as relevant to SIG Testing. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.

Projects

Status: API review completed, 1.27

Development

Successfully merging this pull request may close these issues.

6 participants