|
26 | 26 | - [Phase 2](#phase-2)
|
27 | 27 | - [Informational type checking](#informational-type-checking)
|
28 | 28 | - [Enforcement Actions](#enforcement-actions)
|
| 29 | + - [Audit Annotations](#audit-annotations) |
| 30 | + - [Audit Events](#audit-events) |
29 | 31 | - [Namespace scoped policy binding](#namespace-scoped-policy-binding)
|
30 | 32 | - [CEL Expression Composition](#cel-expression-composition)
|
31 | 33 | - [Use Cases](#use-cases)
|
|
38 | 40 | - [Safety Features](#safety-features)
|
39 | 41 | - [Aggregated API servers](#aggregated-api-servers)
|
40 | 42 | - [CEL function library](#cel-function-library)
|
41 |
| - - [Audit Annotations](#audit-annotations) |
| 43 | + - [Audit Annotations](#audit-annotations-1) |
42 | 44 | - [Client visibility](#client-visibility)
|
43 | 45 | - [Metrics](#metrics)
|
44 | 46 | - [User Stories](#user-stories)
|
@@ -1037,26 +1039,152 @@ status:
|
1037 | 1039 |
|
1038 | 1040 | #### Enforcement Actions
|
1039 | 1041 |
|
1040 |
| -For phase 1, all violations implicitly result in a `deny` enforcement action. |
| 1042 | +`ValidatingAdmissionPolicyBinding` resources may control how admission is |
| 1043 | +enforced. This is performed using a single field. E.g.: |
| 1044 | + |
| 1045 | +```yaml |
| 1046 | +apiVersion: admissionregistration.k8s.io/v1alpha1 |
| 1047 | +kind: ValidatingAdmissionPolicyBinding |
| 1048 | +... |
| 1049 | +spec: |
| 1050 | + validationActions: [Warn, Audit] # required field |
| 1051 | +``` |
| 1052 | + |
| 1053 | +The enum options will be: |
| 1054 | + |
| 1055 | +- `Deny`: Validation failures result in a denied request. |
| 1056 | +- `Warn`: Validation failures are reported as warnings to the client. (xref: [Admisssion Webhook Warnings](https://kubernetes.io/blog/2020/09/03/warnings/#admission-webhooks)) |
| 1057 | +- `Audit`: Validation failures are published as audit events (see below Audit |
| 1058 | + Annotations section for details). |
1041 | 1059 |
|
1042 |
| -For phase 2, we intend to support multiple enforcement actions. |
| 1060 | +If, in the future, `ValidatingAdmissionPolicy` also introduces enforcement |
| 1061 | +action fields, this effective enforcement will be the set to the intersection of the |
| 1062 | +the policy enforcement actions and the binding enforcement actions. |
1043 | 1063 |
|
1044 |
| -Use cases: |
| 1064 | +Systems that need to aggregate validation failures may implement an [audit |
| 1065 | +webhook |
| 1066 | +backend](https://kubernetes.io/docs/tasks/debug/debug-cluster/audit/#webhook-backend). See |
| 1067 | +below "Audit Events" for details. |
1045 | 1068 |
|
1046 |
| -- Cluster admin would like to rollout a policies, sometimes in bulk, without |
| 1069 | +For singleton policies, since there is no separate binding resource, the |
| 1070 | +`validationActions` field will be set on the policy definition in the same way |
| 1071 | +that other binding fields are. |
| 1072 | + |
| 1073 | +Metrics will include validation action so that cluster administrators can monitor the |
| 1074 | +validation failures of a binding before setting `validationActions` to `Deny`. |
| 1075 | + |
| 1076 | +This enables the following use cases: |
| 1077 | + |
| 1078 | +- A policy framework captures enforcement violations during dry run and |
| 1079 | + aggregates them. (E.g. When in DryRun mode, OPA Gatekeeper aggregates |
| 1080 | + violations and records them to the status of the constraint resource). |
| 1081 | + Including validation failures in audit events makes this possible to do |
| 1082 | + using a audit webhook backend. |
| 1083 | +- Cluster admin would like to rollout policies, sometimes in bulk, without |
1047 | 1084 | knowing all the details of the policies. During rollout the cluster admin
|
1048 | 1085 | needs a state where the policies being rolled out cannot result in admission
|
1049 |
| - rejection. |
| 1086 | + rejection. With the enforcement field on bindings, cluster admins can decide |
| 1087 | + which initial actions to enable and then add actions until `Deny` is enabled. |
| 1088 | + The cluster admin may monitoring metrics, warnings and audit events along the |
| 1089 | + way. |
1050 | 1090 | - A policy framework needs different enforcement actions at different
|
1051 |
| - enforcement points. |
1052 |
| -- Cluster admin would like to set specific enforcement actions for policy |
1053 |
| - violations. |
| 1091 | + enforcement points. Since this API defines the behavior of only the admission |
| 1092 | + enforcement point, higher level constructs can map to the actions of this |
| 1093 | + enforcement point as needed. |
| 1094 | + |
| 1095 | +Future work: |
| 1096 | + |
| 1097 | +- ValidatingAdmissionPolicy resources might, in the future, add a `warnings` |
| 1098 | + field adjacent to the `validations` and `auditAnnotations` fields to declare |
| 1099 | + expressions only ever result in warnings. This would allow |
| 1100 | + ValidatingAdmissionPolicy authors to declare a expression as non-enforcing |
| 1101 | + regardless of `validationActions`. |
| 1102 | + |
| 1103 | +- ValidatingAdmissionPolicy resources, might, in the future, offer |
| 1104 | + per-expression enforcement actions (instead of a separate `warnings` field) |
| 1105 | + and combine these enforcement actions with the |
| 1106 | + ValidatingAdmissionPolicyBinding enforcement action to determine the effective |
| 1107 | + enforcement. This would be designed to simplify the workflow required to add |
| 1108 | + or update expression on an existing ValidatingAdmissionPolicy. |
| 1109 | + |
| 1110 | +#### Audit Annotations |
| 1111 | + |
| 1112 | +`ValidatingAdmissionPolicy` may declare [Audit |
| 1113 | + annotations](https://github.com/kubernetes/kubernetes/blob/97bbf07d3f3f20332912ee411fdf75ce84425e28/staging/src/k8s.io/api/admission/v1/types.go#L142) |
| 1114 | + in the policy definition. E.g.: |
| 1115 | + |
| 1116 | +```yaml |
| 1117 | +apiVersion: admissionregistration.k8s.io/v1alpha1 |
| 1118 | +kind: ValidatingAdmissionPolicy |
| 1119 | +... |
| 1120 | +spec: |
| 1121 | + ... |
| 1122 | + validations: |
| 1123 | + - expression: <expression> |
| 1124 | + auditAnnotations: |
| 1125 | + - key: "my-audit-key" |
| 1126 | + valueExpression: <expression that evaluates to a string (and is recorded) or null (and is not recorded)> |
| 1127 | +``` |
| 1128 | + |
| 1129 | +`auditAnnotations` are independent of `validations`. A `ValidatingAdmissionPolicy` |
| 1130 | +may contain only `validations`, only `auditAnnotations` or both. |
| 1131 | + |
| 1132 | +Auudit annotations are recorded regardless of whether a |
| 1133 | +ValidatingAdmissionPolicyBinding's `validationActions` include `Audit`. |
| 1134 | + |
| 1135 | +The published annotation key will be of the form `<ValidatingPolicyDefinition |
| 1136 | +name>/<auditAnnotation key>` and will be validated as a |
| 1137 | +[QualifiedName](https://github.com/kubernetes/kubernetes/blob/dfa4143086bf504c6c72d5eee8a2210b8ed41b9a/staging/src/k8s.io/apimachinery/pkg/util/validation/validation.go#L43). |
| 1138 | + |
| 1139 | +The validation rule will be: `len(key) < QualifierName.maxLength - len(policy |
| 1140 | +name) - 1` to accommodate the `<ValidatingPolicyDefinition |
| 1141 | +name>/<auditAnnotation key>` audit annotation key format. |
1054 | 1142 |
|
1055 |
| -We also intend to support multiple enforcement actions: |
| 1143 | +If `valueExpression` returns a string, the audit annotation is published. If |
| 1144 | +`valueExpression` returns null, the audit annotation is omitted. No other return |
| 1145 | +types will be supported. |
1056 | 1146 |
|
1057 |
| -- Deny |
1058 |
| -- Audit annotation |
1059 |
| -- Client warnings |
| 1147 | +#### Audit Events |
| 1148 | + |
| 1149 | +All audit event keys are prefixed by `<ValidatingPolicyDefinition name>/`. |
| 1150 | + |
| 1151 | +At Metadata audit level or higher, when a validating admission binding fails, |
| 1152 | +and the binding's `validationActions` includes `Audit`, any validation |
| 1153 | +expression, details are included in the audit annotations for the audit event |
| 1154 | +under the key `validation_failures`. E.g.: |
| 1155 | + |
| 1156 | +```yaml |
| 1157 | +# the audit event recorded |
| 1158 | +{ |
| 1159 | + "kind": "Event", |
| 1160 | + "apiVersion": "audit.k8s.io/v1", |
| 1161 | + "annotations": { |
| 1162 | + "ValidatingAdmissionPolicy/mypolicy.mygroup.example.com/validation_failure": "{\"expression\": 1, \"message\": \"x must be greater than y\", \"enforcement\": \"Deny\", \"binding\": \"mybinding.mygroup.example.com\"}" |
| 1163 | + # other annotations |
| 1164 | + ... |
| 1165 | + } |
| 1166 | + # other fields |
| 1167 | + ... |
| 1168 | +} |
| 1169 | +``` |
| 1170 | + |
| 1171 | +Also, at Metadata audit level or higher, any audit annotations declared by the policy definition |
| 1172 | +are included with the key provided. E.g.: |
| 1173 | + |
| 1174 | +```yaml |
| 1175 | +# the audit event recorded |
| 1176 | +{ |
| 1177 | + "kind": "Event", |
| 1178 | + "apiVersion": "audit.k8s.io/v1", |
| 1179 | + "annotations": { |
| 1180 | + "ValidatingAdmissionPolicy/mypolicy.mygroup.example.com/myauditkey": "my audit value" |
| 1181 | + # other annotations |
| 1182 | + ... |
| 1183 | + } |
| 1184 | + # other fields |
| 1185 | + ... |
| 1186 | +} |
| 1187 | +``` |
1060 | 1188 |
|
1061 | 1189 | #### Namespace scoped policy binding
|
1062 | 1190 |
|
|
0 commit comments