|
26 | 26 | - [Limits](#limits)
|
27 | 27 | - [Phase 2](#phase-2)
|
28 | 28 | - [Enforcement Actions](#enforcement-actions)
|
| 29 | + - [Audit Events](#audit-events) |
29 | 30 | - [Namespace scoped policy binding](#namespace-scoped-policy-binding)
|
30 | 31 | - [CEL Expression Composition](#cel-expression-composition)
|
31 | 32 | - [Variables](#variables)
|
@@ -1023,26 +1024,125 @@ this enhancement.
|
1023 | 1024 |
|
1024 | 1025 | #### Enforcement Actions
|
1025 | 1026 |
|
1026 |
| -For phase 1, all violations implicitly result in a `deny` enforcement action. |
| 1027 | +For parity with admission webhooks, a validating policy may also emit audit |
| 1028 | +annotations and warnings: |
1027 | 1029 |
|
1028 |
| -For phase 2, we intend to support multiple enforcement actions. |
| 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. |
1029 | 1039 |
|
1030 |
| -Use cases: |
| 1040 | +`ValidatingAdmissionPolicy` may declare audit annotations in the policy |
| 1041 | +definition. E.g.: |
1031 | 1042 |
|
1032 |
| -- Cluster admin would like to rollout a policies, sometimes in bulk, without |
| 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.: |
| 1059 | + |
| 1060 | +```yaml |
| 1061 | +apiVersion: admissionregistration.k8s.io/v1alpha1 |
| 1062 | +kind: ValidatingAdmissionPolicyBinding |
| 1063 | +... |
| 1064 | +spec: |
| 1065 | + enforcement: warn # optional field |
| 1066 | +``` |
| 1067 | + |
| 1068 | +- `deny`: Validation failures result in a denied request. (default beahvior if |
| 1069 | + 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) |
| 1075 | + |
| 1076 | +Systems that need to aggregate validation failures may implement an [audit |
| 1077 | +webhook |
| 1078 | +backend](https://kubernetes.io/docs/tasks/debug/debug-cluster/audit/#webhook-backend). See |
| 1079 | +below "Audit Events" for details. |
| 1080 | + |
| 1081 | +For singleton policies, the enforcement field will be set on the policy definition. |
| 1082 | + |
| 1083 | +Metrics will include enforcement so that cluster administrators can monitor the |
| 1084 | +validation failures of a binding before setting enforcement to `deny`. |
| 1085 | + |
| 1086 | +Supported use cases: |
| 1087 | + |
| 1088 | +- A policy framework captures enforcement violations during dry run and |
| 1089 | + aggregates them. (E.g. When in DryRun mode, OPA Gatekeeper aggregates |
| 1090 | + violations and records them to the status of the constraint resource). |
| 1091 | + Including validation failures in audit events makes this possible to do |
| 1092 | + using a audit webhook backend. |
| 1093 | +- Cluster admin would like to rollout policies, sometimes in bulk, without |
1033 | 1094 | knowing all the details of the policies. During rollout the cluster admin
|
1034 | 1095 | needs a state where the policies being rolled out cannot result in admission
|
1035 |
| - rejection. |
| 1096 | + 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. |
1036 | 1100 | - A policy framework needs different enforcement actions at different
|
1037 |
| - enforcement points. |
1038 |
| -- Cluster admin would like to set specific enforcement actions for policy |
1039 |
| - violations. |
| 1101 | + 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. |
| 1104 | + |
| 1105 | +#### Audit Events |
| 1106 | + |
| 1107 | +All audit event keys are prefixed by |
| 1108 | +`<ValidatingPolicyDefinition name>/<ValidatingPolicyDefinitionBinding name>/`. |
1040 | 1109 |
|
1041 |
| -We also intend to support multiple enforcement actions: |
| 1110 | +At Metadata audit level or higher, when a validating admission binding fails any |
| 1111 | +validation expression, details are included in the audit annotations |
| 1112 | +for the audit event under the key `validation_failures`. E.g.: |
1042 | 1113 |
|
1043 |
| -- Deny |
1044 |
| -- Audit annotation |
1045 |
| -- Client warnings |
| 1114 | +```yaml |
| 1115 | +# the audit event recorded |
| 1116 | +{ |
| 1117 | + "kind": "Event", |
| 1118 | + "apiVersion": "audit.k8s.io/v1", |
| 1119 | + "annotations": { |
| 1120 | + "mypolicy.mygroup.example.com/mybinding.mygroup.example.com/validation_failure": "{\"expression\": 1, \"message\": \"x must be greater than y\", \"enforcement\": \"deny\"}" |
| 1121 | + # other annotations |
| 1122 | + ... |
| 1123 | + } |
| 1124 | + # other fields |
| 1125 | + ... |
| 1126 | +} |
| 1127 | +``` |
| 1128 | + |
| 1129 | +Also, at Metadata audit level or higher, any audit annotations declared by the policy definition |
| 1130 | +are included with the key provided. E.g.: |
| 1131 | + |
| 1132 | +```yaml |
| 1133 | +# the audit event recorded |
| 1134 | +{ |
| 1135 | + "kind": "Event", |
| 1136 | + "apiVersion": "audit.k8s.io/v1", |
| 1137 | + "annotations": { |
| 1138 | + "mypolicy.mygroup.example.com/mybinding.mygroup.example.com/myauditkey": "my audit value" |
| 1139 | + # other annotations |
| 1140 | + ... |
| 1141 | + } |
| 1142 | + # other fields |
| 1143 | + ... |
| 1144 | +} |
| 1145 | +``` |
1046 | 1146 |
|
1047 | 1147 | #### Namespace scoped policy binding
|
1048 | 1148 |
|
|
0 commit comments