Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mutation policies for some Pod Security Standards controls #1121

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: set-privilege-escalation
status:
ready: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
creationTimestamp: null
name: set-privilege-escalation
spec:
steps:
- name: step-01
try:
- apply:
file: ../set-privilege-escalation.yaml
- patch:
resource:
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: set-privilege-escalation
spec:
validationFailureAction: Enforce
- assert:
file: chainsaw-step-01-assert-1.yaml
- name: step-02
try:
- apply:
file: pod-bad.yaml
- assert:
file: pod-bad-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
apiVersion: v1
kind: Pod
metadata:
name: badpod01
spec:
containers:
- name: container01
image: busybox:1.35
---
apiVersion: v1
kind: Pod
metadata:
name: badpod02
spec:
containers:
- name: container01
image: busybox:1.35
securityContext:
allowPrivilegeEscalation: false
---
apiVersion: v1
kind: Pod
metadata:
name: badpod03
spec:
containers:
- name: container01
image: busybox:1.35
- name: container02
image: busybox:1.35
securityContext:
allowPrivilegeEscalation: false
---
apiVersion: v1
kind: Pod
metadata:
name: badpod04
spec:
containers:
- name: container01
image: busybox:1.35
securityContext:
allowPrivilegeEscalation: false
- name: container02
image: busybox:1.35
securityContext:
allowPrivilegeEscalation: false
---
apiVersion: v1
kind: Pod
metadata:
name: badpod05
spec:
initContainers:
- name: initcontainer01
image: busybox:1.35
containers:
- name: container01
image: busybox:1.35
securityContext:
allowPrivilegeEscalation: false
---
apiVersion: v1
kind: Pod
metadata:
name: badpod06
spec:
initContainers:
- name: initcontainer01
image: busybox:1.35
- name: initcontainer02
image: busybox:1.35
securityContext:
allowPrivilegeEscalation: false
containers:
- name: container01
image: busybox:1.35
securityContext:
allowPrivilegeEscalation: false
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
apiVersion: v1
kind: Pod
metadata:
name: badpod01
spec:
containers:
- name: container01
image: busybox:1.35
---
apiVersion: v1
kind: Pod
metadata:
name: badpod02
spec:
containers:
- name: container01
image: busybox:1.35
securityContext:
allowPrivilegeEscalation: true
---
apiVersion: v1
kind: Pod
metadata:
name: badpod03
spec:
containers:
- name: container01
image: busybox:1.35
- name: container02
image: busybox:1.35
securityContext:
allowPrivilegeEscalation: false
---
apiVersion: v1
kind: Pod
metadata:
name: badpod04
spec:
containers:
- name: container01
image: busybox:1.35
securityContext:
allowPrivilegeEscalation: true
- name: container02
image: busybox:1.35
securityContext:
allowPrivilegeEscalation: false
---
apiVersion: v1
kind: Pod
metadata:
name: badpod05
spec:
initContainers:
- name: initcontainer01
image: busybox:1.35
containers:
- name: container01
image: busybox:1.35
securityContext:
allowPrivilegeEscalation: false
---
apiVersion: v1
kind: Pod
metadata:
name: badpod06
spec:
initContainers:
- name: initcontainer01
image: busybox:1.35
- name: initcontainer02
image: busybox:1.35
securityContext:
allowPrivilegeEscalation: true
containers:
- name: container01
image: busybox:1.35
securityContext:
allowPrivilegeEscalation: false
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
apiVersion: cli.kyverno.io/v1alpha1
kind: Test
metadata:
name: set-privilege-escalation
policies:
- ../set-privilege-escalation.yaml
resources:
- resource.yaml
results:
- policy: set-privilege-escalation
rule: set-containers-privilege-escalation-to-false
kind: Pod
resource: badpod01
patchedResource: patched-resource-01.yaml
result: skip
- policy: set-privilege-escalation
rule: set-containers-privilege-escalation-to-false
kind: Pod
resource: badpod02
patchedResource: patched-resource-02.yaml
result: pass
- policy: set-privilege-escalation
rule: set-containers-privilege-escalation-to-false
kind: Pod
resource: badpod03
patchedResource: patched-resource-03.yaml
result: skip
- policy: set-privilege-escalation
rule: set-containers-privilege-escalation-to-false
kind: Pod
resource: badpod04
patchedResource: patched-resource-04.yaml
result: pass
- policy: set-privilege-escalation
rule: set-containers-privilege-escalation-to-false
kind: Pod
resource: badpod05
patchedResource: patched-resource-05.yaml
result: skip
- policy: set-privilege-escalation
rule: set-initContainers-privilege-escalation-to-false
kind: Pod
resource: badpod06
patchedResource: patched-resource-06.yaml
result: pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Pod
metadata:
name: badpod01
spec:
containers:
- name: container01
image: dummyimagename
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: Pod
metadata:
name: badpod02
spec:
containers:
- name: container01
image: dummyimagename
securityContext:
allowPrivilegeEscalation: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Pod
metadata:
name: badpod03
spec:
containers:
- name: container01
image: dummyimagename
- name: container02
image: dummyimagename
securityContext:
allowPrivilegeEscalation: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: Pod
metadata:
name: badpod04
spec:
containers:
- name: container01
image: dummyimagename
securityContext:
allowPrivilegeEscalation: false
- name: container02
image: dummyimagename
securityContext:
allowPrivilegeEscalation: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Pod
metadata:
name: badpod05
spec:
initContainers:
- name: initcontainer01
image: dummyimagename
containers:
- name: container01
image: dummyimagename
securityContext:
allowPrivilegeEscalation: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: v1
kind: Pod
metadata:
name: badpod06
spec:
initContainers:
- name: initcontainer01
image: dummyimagename
- name: initcontainer02
image: dummyimagename
securityContext:
allowPrivilegeEscalation: false
containers:
- name: container01
image: dummyimagename
securityContext:
allowPrivilegeEscalation: false
Loading
Loading