Skip to content

Commit 5903e11

Browse files
committed
polish.
1 parent 0874c22 commit 5903e11

File tree

1 file changed

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

1 file changed

+9
-5
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ 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-
If you have already heard about Validating Admission Policy and you are eager to try it out, there is no better way to
16-
start using it by replacing an existing webhook.
15+
If you have already heard about Validating Admission Policy and you are eager to try it out, there is no better time to do it now.
16+
17+
Let's have a taste of Validating Admission Policy by replacing a simple webhook.
1718

1819
# The Webhook
19-
First, let's take a look at an example of a webhook that can be a good candidate. Here is an excerpt from a webhook that
20+
First, let's take a look at an example of a simple webhook. Here is an excerpt from a webhook that
2021
enforce `runAsNonRoot`, `readOnlyRootFilesystem`, `allowPrivilegeEscalation`, and `privileged` to be set to the least permissive values.
2122

2223
```go
@@ -47,7 +48,7 @@ func verifyDeployment(deploy *appsv1.Deployment) error {
4748
```
4849

4950
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.
5152

5253
# The Policy
5354
Now let's try to recreate the validation faithfully with a ValidatingAdmissionPolicy.
@@ -75,6 +76,9 @@ spec:
7576
message: 'all containers must NOT set privileged to true'
7677
```
7778
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+
```
7882
```yaml
7983
status:
8084
typeChecking:
@@ -169,7 +173,7 @@ Warning: Validation failed for ValidatingAdmissionPolicy 'pod-security.policy.ex
169173
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
170174
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
171175
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]
173177
```
174178
Looks great! The policy and the webhook give equivalent results.
175179
After a few other cases, when we are confident with our policy, maybe it is time to do some cleanup.

0 commit comments

Comments
 (0)