Skip to content

Commit 2edd5fc

Browse files
committed
Apply feedback
1 parent 21cade5 commit 2edd5fc

File tree

1 file changed

+61
-52
lines changed
  • keps/sig-api-machinery/3488-cel-admission-control

1 file changed

+61
-52
lines changed

keps/sig-api-machinery/3488-cel-admission-control/README.md

Lines changed: 61 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
- [Limits](#limits)
2727
- [Phase 2](#phase-2)
2828
- [Enforcement Actions](#enforcement-actions)
29+
- [Audit Annotations](#audit-annotations)
2930
- [Audit Events](#audit-events)
3031
- [Namespace scoped policy binding](#namespace-scoped-policy-binding)
3132
- [CEL Expression Composition](#cel-expression-composition)
@@ -37,7 +38,7 @@
3738
- [Safety Features](#safety-features)
3839
- [Aggregated API servers](#aggregated-api-servers)
3940
- [CEL function library](#cel-function-library)
40-
- [Audit Annotations](#audit-annotations)
41+
- [Audit Annotations](#audit-annotations-1)
4142
- [Client visibility](#client-visibility)
4243
- [Metrics](#metrics)
4344
- [User Stories](#user-stories)
@@ -1024,66 +1025,36 @@ this enhancement.
10241025

10251026
#### Enforcement Actions
10261027

1027-
For parity with admission webhooks, a validating policy may also emit audit
1028-
annotations and warnings:
1029-
1030-
- [Audit
1031-
annotations](https://github.com/kubernetes/kubernetes/blob/97bbf07d3f3f20332912ee411fdf75ce84425e28/staging/src/k8s.io/api/admission/v1/types.go#L142)
1032-
are key/value pairs included in the audit event for an admission request. The
1033-
audit annotation key supplied by the policy definition author will be prefixed
1034-
with the name of the `ValidatingAdmissionPolicy` and policy binding, e.g.:
1035-
`mypolicy.mygroup.example.com/mybinding.mygroup.example.com/<annotation-key>`.
1036-
- [Warnings](https://kubernetes.io/blog/2020/09/03/warnings/#admission-webhooks)
1037-
are string messages that are returned to API clients. Warning are returned for
1038-
both requests that are accepted and requests that are rejected.
1039-
1040-
`ValidatingAdmissionPolicy` may declare audit annotations in the policy
1041-
definition. E.g.:
1042-
1043-
```yaml
1044-
apiVersion: admissionregistration.k8s.io/v1alpha1
1045-
kind: ValidatingAdmissionPolicy
1046-
...
1047-
spec:
1048-
...
1049-
validations:
1050-
- expression: <expression>
1051-
auditAnnotations:
1052-
- includeWhen: <expression> # optional field
1053-
key: "my-audit-key"
1054-
valueExpression: <expression that evaluates to a string>
1055-
```
1056-
1057-
Additionally, `ValidatingAdmissionPolicyBinding` resource may control how
1058-
admission is enforced. This is performed using a single field. E.g.:
1028+
`ValidatingAdmissionPolicyBinding` resources may control how admission is
1029+
enforced. This is performed using a single field. E.g.:
10591030

10601031
```yaml
10611032
apiVersion: admissionregistration.k8s.io/v1alpha1
10621033
kind: ValidatingAdmissionPolicyBinding
10631034
...
10641035
spec:
1065-
enforcement: warn # optional field
1036+
validationActions: [warn, audit] # optional field
10661037
```
10671038

1039+
The enum options will be:
1040+
10681041
- `deny`: Validation failures result in a denied request. (default beahvior if
10691042
field is unset)
1070-
- `warn`: Validation failures are reported as warnings to the client.
1071-
- `silent`: Validation failures are not reported to clients. Audit annotations
1072-
for any failed validations are still included in audit events (see
1073-
below).
1074-
- (To disable audit annotations, delete the binding)
1043+
- `warn`: Validation failures are reported as warnings to the client. (xref: [Admisssion Webhook Warnings](https://kubernetes.io/blog/2020/09/03/warnings/#admission-webhooks))
1044+
- `audit`: Validation failures are published as audit events (see below Audit
1045+
Annotations section for details).
10751046

10761047
Systems that need to aggregate validation failures may implement an [audit
10771048
webhook
10781049
backend](https://kubernetes.io/docs/tasks/debug/debug-cluster/audit/#webhook-backend). See
10791050
below "Audit Events" for details.
10801051

1081-
For singleton policies, the enforcement field will be set on the policy definition.
1052+
For singleton policies, the `validationActions` field will be set on the policy definition.
10821053

1083-
Metrics will include enforcement so that cluster administrators can monitor the
1084-
validation failures of a binding before setting enforcement to `deny`.
1054+
Metrics will include validation action so that cluster administrators can monitor the
1055+
validation failures of a binding before setting `validationActions` to `deny`.
10851056

1086-
Supported use cases:
1057+
This enables the following use cases:
10871058

10881059
- A policy framework captures enforcement violations during dry run and
10891060
aggregates them. (E.g. When in DryRun mode, OPA Gatekeeper aggregates
@@ -1094,18 +1065,56 @@ Supported use cases:
10941065
knowing all the details of the policies. During rollout the cluster admin
10951066
needs a state where the policies being rolled out cannot result in admission
10961067
rejection. With the enforcement field on bindings, cluster admins can decide
1097-
between `silent` and `warn` as the initial state and then transition through
1098-
the states until the binding reaches `deny`, monitoring metrics and audit
1099-
events along the way.
1068+
which initial actions to enable and then add actions until `deny` is enabled.
1069+
The cluster admin may monitoring metrics, warnings and audit events along the
1070+
way.
11001071
- A policy framework needs different enforcement actions at different
11011072
enforcement points. Since this API defines the behavior of only the admission
1102-
enforcement point, higher level constructs can map to this enforcement point
1103-
as needed.
1073+
enforcement point, higher level constructs can map to the actions of this
1074+
enforcement point as needed.
1075+
1076+
Future work:
1077+
1078+
ValidatingAdmissionPolicy resources might, in the future, add a `warnings` field
1079+
adjacent to the `validations` and `auditAnnotations` fields to declare
1080+
expressions only ever result in warnings. This would allow
1081+
ValidatingAdmissionPolicy authors to declare a expression as non-enforcing
1082+
regardless of `validationActions`.
1083+
1084+
#### Audit Annotations
1085+
1086+
`ValidatingAdmissionPolicy` may declare [Audit
1087+
annotations](https://github.com/kubernetes/kubernetes/blob/97bbf07d3f3f20332912ee411fdf75ce84425e28/staging/src/k8s.io/api/admission/v1/types.go#L142)
1088+
in the policy definition. E.g.:
1089+
1090+
```yaml
1091+
apiVersion: admissionregistration.k8s.io/v1alpha1
1092+
kind: ValidatingAdmissionPolicy
1093+
...
1094+
spec:
1095+
...
1096+
validations:
1097+
- expression: <expression>
1098+
auditAnnotations:
1099+
- key: "my-audit-key"
1100+
valueExpression: <expression that evaluates to a string>
1101+
```
1102+
1103+
The published annotation key will be of the form `<ValidatingPolicyDefinition
1104+
name>/<auditAnnotation key>` and will be validated as a
1105+
[QualifiedName](https://github.com/kubernetes/kubernetes/blob/dfa4143086bf504c6c72d5eee8a2210b8ed41b9a/staging/src/k8s.io/apimachinery/pkg/util/validation/validation.go#L43).
1106+
1107+
The validation rule will be: `len(key) < QualifierName.maxLength - len(policy
1108+
name) - 1` to accommodate the `<ValidatingPolicyDefinition
1109+
name>/<auditAnnotation key>` audit annotation key format.
1110+
1111+
If `valueExpression` returns a string, the audit annotation is published. If
1112+
`valueExpression` returns null, the audit annotation is omitted. No other return
1113+
types will be supported.
11041114

11051115
#### Audit Events
11061116

1107-
All audit event keys are prefixed by
1108-
`<ValidatingPolicyDefinition name>/<ValidatingPolicyDefinitionBinding name>/`.
1117+
All audit event keys are prefixed by `<ValidatingPolicyDefinition name>/`.
11091118

11101119
At Metadata audit level or higher, when a validating admission binding fails any
11111120
validation expression, details are included in the audit annotations
@@ -1117,7 +1126,7 @@ for the audit event under the key `validation_failures`. E.g.:
11171126
"kind": "Event",
11181127
"apiVersion": "audit.k8s.io/v1",
11191128
"annotations": {
1120-
"mypolicy.mygroup.example.com/mybinding.mygroup.example.com/validation_failure": "{\"expression\": 1, \"message\": \"x must be greater than y\", \"enforcement\": \"deny\"}"
1129+
"mypolicy.mygroup.example.com/validation_failure": "{\"expression\": 1, \"message\": \"x must be greater than y\", \"enforcement\": \"deny\", \"binding\": \"mybinding.mygroup.example.com\"}"
11211130
# other annotations
11221131
...
11231132
}
@@ -1135,7 +1144,7 @@ are included with the key provided. E.g.:
11351144
"kind": "Event",
11361145
"apiVersion": "audit.k8s.io/v1",
11371146
"annotations": {
1138-
"mypolicy.mygroup.example.com/mybinding.mygroup.example.com/myauditkey": "my audit value"
1147+
"mypolicy.mygroup.example.com/myauditkey": "my audit value"
11391148
# other annotations
11401149
...
11411150
}

0 commit comments

Comments
 (0)