forked from hashicorp/vault-helm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support PodSecurityPolicy (hashicorp#177)
* Add PSP for server * Add PSP for Injector * Allow annotations to be templated Co-authored-by: Theron Voran <[email protected]>
- Loading branch information
Showing
14 changed files
with
834 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{{- if and (eq (.Values.injector.enabled | toString) "true" ) (and (eq (.Values.global.enabled | toString) "true") (eq (.Values.global.psp.enable | toString) "true") ) }} | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: Role | ||
metadata: | ||
name: {{ template "vault.fullname" . }}-agent-injector-psp | ||
namespace: {{ .Release.Namespace }} | ||
labels: | ||
app.kubernetes.io/name: {{ include "vault.name" . }} | ||
app.kubernetes.io/instance: {{ .Release.Name }} | ||
app.kubernetes.io/managed-by: {{ .Release.Service }} | ||
rules: | ||
- apiGroups: ['policy'] | ||
resources: ['podsecuritypolicies'] | ||
verbs: ['use'] | ||
resourceNames: | ||
- {{ template "vault.fullname" . }}-agent-injector | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{{- if and (eq (.Values.injector.enabled | toString) "true" ) (and (eq (.Values.global.enabled | toString) "true") (eq (.Values.global.psp.enable | toString) "true") ) }} | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: {{ template "vault.fullname" . }}-agent-injector-psp | ||
namespace: {{ .Release.Namespace }} | ||
labels: | ||
app.kubernetes.io/name: {{ include "vault.name" . }} | ||
app.kubernetes.io/instance: {{ .Release.Name }} | ||
app.kubernetes.io/managed-by: {{ .Release.Service }} | ||
roleRef: | ||
kind: Role | ||
name: {{ template "vault.fullname" . }}-agent-injector-psp | ||
apiGroup: rbac.authorization.k8s.io | ||
subjects: | ||
- kind: ServiceAccount | ||
name: {{ template "vault.fullname" . }}-agent-injector | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{{- if and (eq (.Values.injector.enabled | toString) "true" ) (and (eq (.Values.global.enabled | toString) "true") (eq (.Values.global.psp.enable | toString) "true") ) }} | ||
apiVersion: policy/v1beta1 | ||
kind: PodSecurityPolicy | ||
metadata: | ||
name: {{ template "vault.fullname" . }}-agent-injector | ||
labels: | ||
app.kubernetes.io/name: {{ include "vault.name" . }} | ||
app.kubernetes.io/instance: {{ .Release.Name }} | ||
app.kubernetes.io/managed-by: {{ .Release.Service }} | ||
{{- template "vault.psp.annotations" . }} | ||
spec: | ||
privileged: false | ||
# Required to prevent escalations to root. | ||
allowPrivilegeEscalation: false | ||
volumes: | ||
- configMap | ||
- emptyDir | ||
- projected | ||
- secret | ||
- downwardAPI | ||
hostNetwork: false | ||
hostIPC: false | ||
hostPID: false | ||
runAsUser: | ||
# Require the container to run without root privileges. | ||
rule: MustRunAsNonRoot | ||
seLinux: | ||
# This policy assumes the nodes are using AppArmor rather than SELinux. | ||
rule: RunAsAny | ||
supplementalGroups: | ||
rule: MustRunAs | ||
ranges: | ||
# Forbid adding the root group. | ||
- min: 1 | ||
max: 65535 | ||
fsGroup: | ||
rule: MustRunAs | ||
ranges: | ||
# Forbid adding the root group. | ||
- min: 1 | ||
max: 65535 | ||
readOnlyRootFilesystem: false | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{{ template "vault.mode" . }} | ||
{{- if and (ne .mode "") (and (eq (.Values.global.enabled | toString) "true") (eq (.Values.global.psp.enable | toString) "true") ) }} | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: Role | ||
metadata: | ||
name: {{ template "vault.fullname" . }}-psp | ||
namespace: {{ .Release.Namespace }} | ||
labels: | ||
app.kubernetes.io/name: {{ include "vault.name" . }} | ||
app.kubernetes.io/instance: {{ .Release.Name }} | ||
app.kubernetes.io/managed-by: {{ .Release.Service }} | ||
rules: | ||
- apiGroups: ['policy'] | ||
resources: ['podsecuritypolicies'] | ||
verbs: ['use'] | ||
resourceNames: | ||
- {{ template "vault.fullname" . }} | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{{ template "vault.mode" . }} | ||
{{- if and (ne .mode "") (and (eq (.Values.global.enabled | toString) "true") (eq (.Values.global.psp.enable | toString) "true") ) }} | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: {{ template "vault.fullname" . }}-psp | ||
namespace: {{ .Release.Namespace }} | ||
labels: | ||
app.kubernetes.io/name: {{ include "vault.name" . }} | ||
app.kubernetes.io/instance: {{ .Release.Name }} | ||
app.kubernetes.io/managed-by: {{ .Release.Service }} | ||
roleRef: | ||
kind: Role | ||
name: {{ template "vault.fullname" . }}-psp | ||
apiGroup: rbac.authorization.k8s.io | ||
subjects: | ||
- kind: ServiceAccount | ||
name: {{ template "vault.fullname" . }} | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{{ template "vault.mode" . }} | ||
{{- if and (ne .mode "") (and (eq (.Values.global.enabled | toString) "true") (eq (.Values.global.psp.enable | toString) "true") ) }} | ||
apiVersion: policy/v1beta1 | ||
kind: PodSecurityPolicy | ||
metadata: | ||
name: {{ template "vault.fullname" . }} | ||
labels: | ||
app.kubernetes.io/name: {{ include "vault.name" . }} | ||
app.kubernetes.io/instance: {{ .Release.Name }} | ||
app.kubernetes.io/managed-by: {{ .Release.Service }} | ||
{{- template "vault.psp.annotations" . }} | ||
spec: | ||
privileged: false | ||
# Required to prevent escalations to root. | ||
allowPrivilegeEscalation: false | ||
volumes: | ||
- configMap | ||
- emptyDir | ||
- projected | ||
- secret | ||
- downwardAPI | ||
{{- if eq (.Values.server.dataStorage.enabled | toString) "true" }} | ||
- persistentVolumeClaim | ||
{{- end }} | ||
hostNetwork: false | ||
hostIPC: false | ||
hostPID: false | ||
runAsUser: | ||
# Require the container to run without root privileges. | ||
rule: MustRunAsNonRoot | ||
seLinux: | ||
# This policy assumes the nodes are using AppArmor rather than SELinux. | ||
rule: RunAsAny | ||
supplementalGroups: | ||
rule: MustRunAs | ||
ranges: | ||
# Forbid adding the root group. | ||
- min: 1 | ||
max: 65535 | ||
fsGroup: | ||
rule: MustRunAs | ||
ranges: | ||
# Forbid adding the root group. | ||
- min: 1 | ||
max: 65535 | ||
readOnlyRootFilesystem: false | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env bats | ||
|
||
load _helpers | ||
|
||
@test "injector/PodSecurityPolicy-Role: PodSecurityPolicy-Role not enabled by default" { | ||
cd `chart_dir` | ||
local actual=$( (helm template \ | ||
--show-only templates/injector-psp-role.yaml \ | ||
. || echo "---" ) | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "false" ] | ||
} | ||
|
||
@test "injector/PodSecurityPolicy-Role: enable with injector.enabled and global.psp.enable" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
--show-only templates/injector-psp-role.yaml \ | ||
--set 'injector.enabled=true' \ | ||
--set 'global.psp.enable=true' \ | ||
. | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "true" ] | ||
} | ||
|
||
@test "injector/PodSecurityPolicy-Role: disable with global.enabled" { | ||
cd `chart_dir` | ||
local actual=$( (helm template \ | ||
--show-only templates/injector-psp-role.yaml \ | ||
--set 'global.enabled=false' \ | ||
--set 'injector.enabled=true' \ | ||
--set 'global.psp.enable=true' \ | ||
. || echo "---") | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "false" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env bats | ||
|
||
load _helpers | ||
|
||
@test "injector/PodSecurityPolicy-RoleBinding: PodSecurityPolicy-RoleBinding not enabled by default" { | ||
cd `chart_dir` | ||
local actual=$( (helm template \ | ||
--show-only templates/injector-psp-rolebinding.yaml \ | ||
. || echo "---" ) | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "false" ] | ||
} | ||
|
||
@test "injector/PodSecurityPolicy-RoleBinding: enable with injector.enabled and global.psp.enable" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
--show-only templates/injector-psp-rolebinding.yaml \ | ||
--set 'injector.enabled=true' \ | ||
--set 'global.psp.enable=true' \ | ||
. | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "true" ] | ||
} | ||
|
||
@test "injector/PodSecurityPolicy-RoleBinding: disable with global.enabled" { | ||
cd `chart_dir` | ||
local actual=$( (helm template \ | ||
--show-only templates/injector-psp-rolebinding.yaml \ | ||
--set 'global.enabled=false' \ | ||
--set 'injector.enabled=true' \ | ||
--set 'global.psp.enable=true' \ | ||
. || echo "---") | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "false" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/usr/bin/env bats | ||
|
||
load _helpers | ||
|
||
@test "injector/PodSecurityPolicy: PodSecurityPolicy not enabled by default" { | ||
cd `chart_dir` | ||
local actual=$( (helm template \ | ||
--show-only templates/injector-psp.yaml \ | ||
. || echo "---") | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "false" ] | ||
} | ||
|
||
@test "injector/PodSecurityPolicy: enable with injector.enabled and global.psp.enable" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
--show-only templates/injector-psp.yaml \ | ||
--set 'injector.enabled=true' \ | ||
--set 'global.psp.enable=true' \ | ||
. | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "true" ] | ||
} | ||
|
||
@test "injector/PodSecurityPolicy: disable with global.enabled" { | ||
cd `chart_dir` | ||
local actual=$( (helm template \ | ||
--show-only templates/injector-psp.yaml \ | ||
--set 'global.enabled=false' \ | ||
--set 'injector.enabled=true' \ | ||
--set 'global.psp.enable=true' \ | ||
. || echo "---") | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "false" ] | ||
} | ||
|
||
@test "injector/PodSecurityPolicy: annotations are templated correctly by default" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
--show-only templates/injector-psp.yaml \ | ||
--set 'injector.enabled=true' \ | ||
--set 'global.psp.enable=true' \ | ||
. | tee /dev/stderr | | ||
yq '.metadata.annotations | length == 4' | tee /dev/stderr) | ||
[ "${actual}" = "true" ] | ||
} | ||
|
||
@test "injector/PodSecurityPolicy: annotations are added - string" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
--show-only templates/injector-psp.yaml \ | ||
--set 'injector.enabled=true' \ | ||
--set 'global.psp.enable=true' \ | ||
--set 'global.psp.annotations=vault-is: amazing' \ | ||
. | tee /dev/stderr | | ||
yq -r '.metadata.annotations["vault-is"]' | tee /dev/stderr) | ||
[ "${actual}" = "amazing" ] | ||
} | ||
|
||
@test "injector/PodSecurityPolicy: annotations are added - object" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
--show-only templates/injector-psp.yaml \ | ||
--set 'injector.enabled=true' \ | ||
--set 'global.psp.enable=true' \ | ||
--set 'global.psp.annotations.vault-is=amazing' \ | ||
. | tee /dev/stderr | | ||
yq -r '.metadata.annotations["vault-is"]' | tee /dev/stderr) | ||
[ "${actual}" = "amazing" ] | ||
} |
Oops, something went wrong.