-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PodSecurityPolicy for Consul API Gateway controller (#1656)
* Add PodSecurityPolicy for Consul API Gateway controller * Grant Consul API Gateway controller access to new PodSecurityPolicy * Add unit test coverage for clusterrole + podsecuritypolicy * Add changelog entry * Use YQ@3 friendly select
- Loading branch information
1 parent
767340c
commit 2f7c891
Showing
5 changed files
with
83 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
40 changes: 40 additions & 0 deletions
40
charts/consul/templates/api-gateway-controller-podsecuritypolicy.yaml
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,40 @@ | ||
{{- if and .Values.apiGateway.enabled .Values.global.enablePodSecurityPolicies }} | ||
apiVersion: policy/v1beta1 | ||
kind: PodSecurityPolicy | ||
metadata: | ||
name: {{ template "consul.fullname" . }}-api-gateway-controller | ||
namespace: {{ .Release.Namespace }} | ||
labels: | ||
app: {{ template "consul.name" . }} | ||
chart: {{ template "consul.chart" . }} | ||
heritage: {{ .Release.Service }} | ||
release: {{ .Release.Name }} | ||
component: api-gateway-controller | ||
spec: | ||
privileged: false | ||
# Required to prevent escalations to root. | ||
allowPrivilegeEscalation: false | ||
# This is redundant with non-root + disallow privilege escalation, | ||
# but we can provide it for defense in depth. | ||
requiredDropCapabilities: | ||
- ALL | ||
# Allow core volume types. | ||
volumes: | ||
- 'configMap' | ||
- 'emptyDir' | ||
- 'projected' | ||
- 'secret' | ||
- 'downwardAPI' | ||
hostNetwork: false | ||
hostIPC: false | ||
hostPID: false | ||
runAsUser: | ||
rule: 'RunAsAny' | ||
seLinux: | ||
rule: 'RunAsAny' | ||
supplementalGroups: | ||
rule: 'RunAsAny' | ||
fsGroup: | ||
rule: 'RunAsAny' | ||
readOnlyRootFilesystem: true | ||
{{- 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
22 changes: 22 additions & 0 deletions
22
charts/consul/test/unit/api-gateway-controller-podsecuritypolicy.bats
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,22 @@ | ||
#!/usr/bin/env bats | ||
|
||
load _helpers | ||
|
||
@test "apiGateway/PodSecurityPolicy: disabled by default" { | ||
cd `chart_dir` | ||
assert_empty helm template \ | ||
-s templates/api-gateway-controller-podsecuritypolicy.yaml \ | ||
. | ||
} | ||
|
||
@test "apiGateway/PodSecurityPolicy: enabled with apiGateway.enabled=true and global.enablePodSecurityPolicies=true" { | ||
cd `chart_dir` | ||
local actual=$(helm template \ | ||
-s templates/api-gateway-controller-podsecuritypolicy.yaml \ | ||
--set 'global.enablePodSecurityPolicies=true' \ | ||
--set 'apiGateway.enabled=true' \ | ||
--set 'apiGateway.image=foo' \ | ||
. | tee /dev/stderr | | ||
yq 'length > 0' | tee /dev/stderr) | ||
[ "${actual}" = "true" ] | ||
} |