You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Check out [the doc](https://kubernetes.io/docs/reference/access-authn-authz/extensible-admission-controllers/#what-are-admission-webhooks)
50
-
for a refresher on how admission webhooks work. Or, see the [full code](https://gist.github.com/jiahuif/2653f2ce41fe6a2e5739ea7cd76b182b) of this webhook to follow along this tutorial.
51
+
for a refresher on how admission webhooks work. Or, see the [full code](https://gist.github.com/jiahuif/2653f2ce41fe6a2e5739ea7cd76b182b) of this webhook to follow along this walkthrough.
51
52
52
53
# The Policy
53
54
Now let's try to recreate the validation faithfully with a ValidatingAdmissionPolicy.
@@ -75,6 +76,9 @@ spec:
75
76
message: 'all containers must NOT set privileged to true'
76
77
```
77
78
Create the policy with `kubectl`. Great, no complain so far. But let's get the policy object back and take a look at its status.
79
+
```shell
80
+
kubectl get -oyaml validatingadmissionpolicies/pod-security.policy.example.com
81
+
```
78
82
```yaml
79
83
status:
80
84
typeChecking:
@@ -169,7 +173,7 @@ Warning: Validation failed for ValidatingAdmissionPolicy 'pod-security.policy.ex
169
173
Warning: Validation failed for ValidatingAdmissionPolicy 'pod-security.policy.example.com' with binding 'pod-security.policy-binding.example.com': all containers must set readOnlyRootFilesystem to true
170
174
Warning: Validation failed for ValidatingAdmissionPolicy 'pod-security.policy.example.com' with binding 'pod-security.policy-binding.example.com': all containers must NOT set allowPrivilegeEscalation to true
171
175
Warning: Validation failed for ValidatingAdmissionPolicy 'pod-security.policy.example.com' with binding 'pod-security.policy-binding.example.com': all containers must NOT set privileged to true
172
-
Error from server: error when creating "STDIN": admission webhook "cel-shim.example.com" denied the request: [container "nginx" must set RunAsNonRoot to true in its SecurityContext, container "nginx" must set ReadOnlyRootFilesystem to true in its SecurityContext, container "nginx" must NOT set AllowPrivilegeEscalation to true in its SecurityContext, container "nginx" must NOT set Privileged to true in its SecurityContext]
176
+
Error from server: error when creating "STDIN": admission webhook "webhook.example.com" denied the request: [container "nginx" must set RunAsNonRoot to true in its SecurityContext, container "nginx" must set ReadOnlyRootFilesystem to true in its SecurityContext, container "nginx" must NOT set AllowPrivilegeEscalation to true in its SecurityContext, container "nginx" must NOT set Privileged to true in its SecurityContext]
173
177
```
174
178
Looks great! The policy and the webhook give equivalent results.
175
179
After a few other cases, when we are confident with our policy, maybe it is time to do some cleanup.
0 commit comments