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

Seccomp mutation for both notations #411

Closed
wants to merge 11 commits into from
Closed
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,13 @@
apiVersion: v1
kind: Pod
metadata:
name: nginx-seccomp-allowed3
labels:
app: nginx-seccomp
spec:
securityContext:
seccompProfile:
type: RuntimeDefault
containers:
- name: nginx
image: nginx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Pod
metadata:
name: nginx-seccomp-disallowed3
labels:
app: nginx-seccomp
spec:
securityContext:
seccompProfile:
type: Unconfined
containers:
- name: nginx
image: nginx
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,12 @@ tests:
assertions:
- violations: 1
message: "Seccomp profile 'unconfined' is not allowed for container 'nginx'. Found at: annotation container.seccomp.security.alpha.kubernetes.io/nginx"
- name: example-allowed-global-securityContext
object: samples/psp-seccomp/example_allowed3.yaml
assertions:
- violations: no
- name: example-disallowed-global-securityContext
object: samples/psp-seccomp/example_disallowed3.yaml
assertions:
- violations: 1
message: "Seccomp profile 'Unconfined' is not allowed for container 'nginx'. Found at: pod securityContext"
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Pod
metadata:
name: nginx-seccomp-allowed3
labels:
app: nginx-seccomp
spec:
securityContext:
seccompProfile:
type: RuntimeDefault
containers:
- name: nginx
image: nginx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Pod
metadata:
name: nginx-seccomp-disallowed3
labels:
app: nginx-seccomp
spec:
securityContext:
seccompProfile:
type: Unconfined
containers:
- name: nginx
image: nginx
9 changes: 9 additions & 0 deletions library/pod-security-policy/seccomp/suite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,12 @@ tests:
assertions:
- violations: 1
message: "Seccomp profile 'unconfined' is not allowed for container 'nginx'. Found at: annotation container.seccomp.security.alpha.kubernetes.io/nginx"
- name: example-allowed-global-securityContext
object: samples/psp-seccomp/example_allowed3.yaml
assertions:
- violations: no
- name: example-disallowed-global-securityContext
object: samples/psp-seccomp/example_disallowed3.yaml
assertions:
- violations: 1
message: "Seccomp profile 'Unconfined' is not allowed for container 'nginx'. Found at: pod securityContext"
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: mutations.gatekeeper.sh/v1alpha1
kind: AssignMetadata
metadata:
name: k8spspseccomp
name: k8spspseccompannotation
spec:
match:
scope: Namespaced
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: mutations.gatekeeper.sh/v1alpha1
kind: Assign
metadata:
name: k8spspseccompcontext
spec:
applyTo:
- groups: [""]
kinds: ["Pod"]
versions: ["v1"]
match:
scope: Namespaced
kinds:
- apiGroups: ["*"]
kinds: ["Pod"]
location: "spec.securityContext.seccompProfile.type"
parameters:
pathTests:
- subPath: "spec.securityContext.seccompProfile.type"
condition: MustNotExist
assign:
value: RuntimeDefault
19 changes: 13 additions & 6 deletions website/docs/mutation-examples/seccomp.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,30 @@ title: seccomp

### Usage
```shell
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/mutation/pod-security-policy/seccomp/samples/mutation.yaml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, looks like we are missing mutation-annotation.

@nilekhc Looks like the website generator currently will only retain the final mutation sample per directory? https://github.com/open-policy-agent/gatekeeper-library/blob/master/scripts/website/generate.go#L226

kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/mutation/pod-security-policy/seccomp/samples/mutation-securityContext.yaml
```
## Mutation Examples
```yaml
apiVersion: mutations.gatekeeper.sh/v1alpha1
kind: AssignMetadata
kind: Assign
metadata:
name: k8spspseccomp
name: k8spspseccompcontext
spec:
applyTo:
- groups: [""]
kinds: ["Pod"]
versions: ["v1"]
match:
scope: Namespaced
kinds:
- apiGroups: [""]
- apiGroups: ["*"]
kinds: ["Pod"]
location: metadata.annotations."seccomp.security.alpha.kubernetes.io/pod"
location: "spec.securityContext.seccompProfile.type"
parameters:
pathTests:
- subPath: "spec.securityContext.seccompProfile.type"
condition: MustNotExist
assign:
value: runtime/default
value: RuntimeDefault

```
54 changes: 54 additions & 0 deletions website/docs/validation/seccomp.md
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,60 @@ Usage
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/library/pod-security-policy/seccomp/samples/psp-seccomp/disallowed_ephemeral.yaml
```

</details>
<details>
<summary>example-allowed-global-securityContext</summary>

```yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx-seccomp-allowed3
labels:
app: nginx-seccomp
spec:
securityContext:
seccompProfile:
type: RuntimeDefault
containers:
- name: nginx
image: nginx

```

Usage

```shell
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/library/pod-security-policy/seccomp/samples/psp-seccomp/example_allowed3.yaml
```

</details>
<details>
<summary>example-disallowed-global-securityContext</summary>

```yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx-seccomp-disallowed3
labels:
app: nginx-seccomp
spec:
securityContext:
seccompProfile:
type: Unconfined
containers:
- name: nginx
image: nginx

```

Usage

```shell
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/library/pod-security-policy/seccomp/samples/psp-seccomp/example_disallowed3.yaml
```

</details>


Expand Down