Skip to content

Commit 94bb8ec

Browse files
committed
set to false -> NOT set to true
1 parent a464300 commit 94bb8ec

File tree

1 file changed

+9
-10
lines changed
  • content/en/blog/_posts/2024-04-01-validating-admission-policy-ga

1 file changed

+9
-10
lines changed

content/en/blog/_posts/2024-04-01-validating-admission-policy-ga/index.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ We are excited to announce that Validating Admission Policy has reached its Gene
1212
as part of Kubernetes 1.30 release. If you have not yet read about this new declarative alternative to
1313
validating admission webhooks, it may be interesting to read our
1414
[previous post](/blog/2022/12/20/validating-admission-policies-alpha/) about the new feature.
15-
1615
If you have already heard about Validating Admission Policy and you are eager to try it out, there is no better way to
1716
start using it by replacing an existing webhook.
1817

@@ -50,7 +49,7 @@ Check out [the doc](https://kubernetes.io/docs/reference/access-authn-authz/exte
5049
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.
5150

5251
# The Policy
53-
Now let's try to recreate the validation with a ValidatingAdmissionPolicy.
52+
Now let's try to recreate the validation faithfully with a ValidatingAdmissionPolicy.
5453
```yaml
5554
apiVersion: admissionregistration.k8s.io/v1
5655
kind: ValidatingAdmissionPolicy
@@ -70,9 +69,9 @@ spec:
7069
- expression: object.spec.template.spec.containers.all(c, has(c.securityContext) && has(c.securityContext.readOnlyRootFilesystem) && c.securityContext.readOnlyRootFilesystem)
7170
message: 'all containers must set readOnlyRootFilesystem to true'
7271
- expression: object.spec.template.spec.containers.all(c, !has(c.securityContext) || !has(c.securityContext.allowPrivilegeEscalation) || !c.securityContext.allowPrivilegeEscalation)
73-
message: 'all containers must set allowPrivilegeEscalation to false'
72+
message: 'all containers must NOT set allowPrivilegeEscalation to true'
7473
- expression: object.spec.template.spec.containers.all(c, !has(c.securityContext) || !has(c.securityContext.Privileged) || !c.securityContext.Privileged)
75-
message: 'all containers must set privileged to false'
74+
message: 'all containers must NOT set privileged to true'
7675
```
7776
Create the policy with `kubectl`. Great, no complain so far. But let's take a look at its status.
7877
```yaml
@@ -109,9 +108,9 @@ spec:
109108
- expression: object.spec.template.spec.containers.all(c, has(c.securityContext) && has(c.securityContext.readOnlyRootFilesystem) && c.securityContext.readOnlyRootFilesystem)
110109
message: 'all containers must set readOnlyRootFilesystem to true'
111110
- expression: object.spec.template.spec.containers.all(c, !has(c.securityContext) || !has(c.securityContext.allowPrivilegeEscalation) || !c.securityContext.allowPrivilegeEscalation)
112-
message: 'all containers must set allowPrivilegeEscalation to false'
111+
message: 'all containers must NOT set allowPrivilegeEscalation to true'
113112
- expression: object.spec.template.spec.containers.all(c, !has(c.securityContext) || !has(c.securityContext.privileged) || !c.securityContext.privileged)
114-
message: 'all containers must set privileged to false'
113+
message: 'all containers must NOT set privileged to true'
115114
```
116115
Check its status again, and you should see all warnings cleared.
117116

@@ -163,8 +162,8 @@ EOF
163162
```text
164163
Warning: Validation failed for ValidatingAdmissionPolicy 'pod-security.policy.example.com' with binding 'pod-security.policy-binding.example.com': all containers must set runAsNonRoot to true
165164
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
166-
Warning: Validation failed for ValidatingAdmissionPolicy 'pod-security.policy.example.com' with binding 'pod-security.policy-binding.example.com': all containers must set allowPrivilegeEscalation to false
167-
Warning: Validation failed for ValidatingAdmissionPolicy 'pod-security.policy.example.com' with binding 'pod-security.policy-binding.example.com': all containers must set privileged to false
165+
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
166+
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
168167
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
169168
```
170169
Not quite the exact same behavior but good enough. After a few other cases, when we are confident with our policy, maybe it is time for some refactoring.
@@ -195,7 +194,7 @@ spec:
195194
- expression: variables.securityContexts.all(c, c.?readOnlyRootFilesystem == optional.of(true))
196195
message: 'all containers must set readOnlyRootFilesystem to true'
197196
- expression: variables.securityContexts.all(c, c.?allowPrivilegeEscalation != optional.of(true))
198-
message: 'all containers must set allowPrivilegeEscalation to false'
197+
message: 'all containers must NOT set allowPrivilegeEscalation to true'
199198
- expression: variables.securityContexts.all(c, c.?privileged != optional.of(true))
200-
message: 'all containers must set privileged to false'
199+
message: 'all containers must NOT set privileged to true'
201200
```

0 commit comments

Comments
 (0)