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

Return support for readOnlyRootFilesystem #120

Open
wants to merge 6 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
6 changes: 3 additions & 3 deletions templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ for users looking to use this chart with Consul Helm.
{{- define "vault.args" -}}
{{ if or (eq .mode "standalone") (eq .mode "ha") }}
- |
sed -E "s/HOST_IP/${HOST_IP?}/g" /vault/config/extraconfig-from-values.hcl > /tmp/storageconfig.hcl;
sed -Ei "s/POD_IP/${POD_IP?}/g" /tmp/storageconfig.hcl;
/usr/local/bin/docker-entrypoint.sh vault server -config=/tmp/storageconfig.hcl
sed -E "s/HOST_IP/${HOST_IP?}/g" /vault/config/extraconfig-from-values.hcl > /home/vault/storageconfig.hcl;
sed -Ei "s/POD_IP/${POD_IP?}/g" /home/vault/storageconfig.hcl;
/usr/local/bin/docker-entrypoint.sh vault server -config=/home/vault/storageconfig.hcl
{{ end }}
{{- end -}}

Expand Down
10 changes: 9 additions & 1 deletion templates/server-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,16 @@ spec:
fsGroup: {{ .Values.server.gid | default 1000 }}
volumes:
{{ template "vault.volumes" . }}
- name: home-volume
emptyDir:
medium: Memory
containers:
- name: vault
{{ template "vault.resources" . }}
securityContext:
{{- if .Values.server.securityContext.readOnlyRootFilesystem }}
readOnlyRootFilesystem: true
{{- end }}
capabilities:
add: ["IPC_LOCK"]
image: {{ .Values.server.image.repository }}:{{ .Values.server.image.tag | default "latest" }}
Expand Down Expand Up @@ -77,6 +83,8 @@ spec:
{{- include "vault.extraSecretEnvironmentVars" .Values.server | nindent 12 }}
volumeMounts:
{{ template "vault.mounts" . }}
- name: home-volume
mountPath: /home/vault
ports:
- containerPort: 8200
name: http
Expand Down Expand Up @@ -122,7 +130,7 @@ spec:
{{- end }}
lifecycle:
# Vault container doesn't receive SIGTERM from Kubernetes
# and after the grace period ends, Kube sends SIGKILL. This
# and after the grace period ends, Kube sends SIGKILL. This
# causes issues with graceful shutdowns such as deregistering itself
# from Consul (zombie services).
preStop:
Expand Down
2 changes: 1 addition & 1 deletion test/acceptance/server-dev.bats
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ load _helpers
# Volume Mounts
local volumeCount=$(kubectl get statefulset "$(name_prefix)" --output json |
jq -r '.spec.template.spec.containers[0].volumeMounts | length')
[ "${volumeCount}" == "0" ]
[ "${volumeCount}" == "1" ]

# Service
local service=$(kubectl get service "$(name_prefix)" --output json |
Expand Down
4 changes: 2 additions & 2 deletions test/acceptance/server-ha.bats
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ load _helpers
# Volume Mounts
local volumeCount=$(kubectl get statefulset "$(name_prefix)" --output json |
jq -r '.spec.template.spec.containers[0].volumeMounts | length')
[ "${volumeCount}" == "1" ]
[ "${volumeCount}" == "2" ]

# Volumes
local volumeCount=$(kubectl get statefulset "$(name_prefix)" --output json |
jq -r '.spec.template.spec.volumes | length')
[ "${volumeCount}" == "1" ]
[ "${volumeCount}" == "2" ]

local volume=$(kubectl get statefulset "$(name_prefix)" --output json |
jq -r '.spec.template.spec.volumes[0].configMap.name')
Expand Down
4 changes: 2 additions & 2 deletions test/acceptance/server.bats
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ load _helpers
# Volume Mounts
local volumeCount=$(kubectl get statefulset "$(name_prefix)" --output json |
jq -r '.spec.template.spec.containers[0].volumeMounts | length')
[ "${volumeCount}" == "2" ]
[ "${volumeCount}" == "3" ]

local mountName=$(kubectl get statefulset "$(name_prefix)" --output json |
jq -r '.spec.template.spec.containers[0].volumeMounts[0].name')
Expand All @@ -47,7 +47,7 @@ load _helpers
# Volumes
local volumeCount=$(kubectl get statefulset "$(name_prefix)" --output json |
jq -r '.spec.template.spec.volumes | length')
[ "${volumeCount}" == "1" ]
[ "${volumeCount}" == "2" ]

local volume=$(kubectl get statefulset "$(name_prefix)" --output json |
jq -r '.spec.template.spec.volumes[0].configMap.name')
Expand Down
21 changes: 21 additions & 0 deletions test/unit/server-dev-statefulset.bats
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,24 @@ load _helpers
yq -r '.spec.template.spec.securityContext.fsGroup' | tee /dev/stderr)
[ "${actual}" = "2000" ]
}

@test "server/dev-StatefulSet: readOnlyRootFilesystem default" {
cd `chart_dir`
local actual=$(helm template \
-x templates/server-statefulset.yaml \
--set 'server.dev.enabled=true' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.containers[0].securityContext.readOnlyRootFilesystem' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "server/dev-StatefulSet: readOnlyRootFilesystem configurable" {
cd `chart_dir`
local actual=$(helm template \
-x templates/server-statefulset.yaml \
--set 'server.dev.enabled=true' \
--set 'server.securityContext.readOnlyRootFilesystem=false' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.containers[0].securityContext.readOnlyRootFilesystem' | tee /dev/stderr)
[ "${actual}" = "null" ]
}
21 changes: 21 additions & 0 deletions test/unit/server-ha-statefulset.bats
Original file line number Diff line number Diff line change
Expand Up @@ -578,3 +578,24 @@ load _helpers
yq -r '.spec.template.spec.securityContext.fsGroup' | tee /dev/stderr)
[ "${actual}" = "2000" ]
}

@test "server/ha-StatefulSet: readOnlyRootFilesystem default" {
cd `chart_dir`
local actual=$(helm template \
-x templates/server-statefulset.yaml \
--set 'server.ha.enabled=true' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.containers[0].securityContext.readOnlyRootFilesystem' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "server/ha-StatefulSet: readOnlyRootFilesystem configurable" {
cd `chart_dir`
local actual=$(helm template \
-x templates/server-statefulset.yaml \
--set 'server.ha.enabled=true' \
--set 'server.securityContext.readOnlyRootFilesystem=false' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.containers[0].securityContext.readOnlyRootFilesystem' | tee /dev/stderr)
[ "${actual}" = "null" ]
}
21 changes: 20 additions & 1 deletion test/unit/server-statefulset.bats
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ load _helpers

local containers_count=$(echo $object |
yq -r 'length' | tee /dev/stderr)
[ "${containers_count}" = 1 ]
[ "${containers_count}" = 1 ]
}

# extra labels
Expand Down Expand Up @@ -742,6 +742,25 @@ load _helpers
[ "${actual}" = "2000" ]
}

@test "server/standalone-StatefulSet: readOnlyRootFilesystem default" {
cd `chart_dir`
local actual=$(helm template \
-x templates/server-statefulset.yaml \
. | tee /dev/stderr |
yq -r '.spec.template.spec.containers[0].securityContext.readOnlyRootFilesystem' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

@test "server/standalone-StatefulSet: readOnlyRootFilesystem configurable" {
cd `chart_dir`
local actual=$(helm template \
-x templates/server-statefulset.yaml \
--set 'server.securityContext.readOnlyRootFilesystem=false' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.containers[0].securityContext.readOnlyRootFilesystem' | tee /dev/stderr)
[ "${actual}" = "null" ]
}

#--------------------------------------------------------------------
# health checks

Expand Down
7 changes: 5 additions & 2 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ server:
# should map directly to the value of the resources field for a PodSpec.
# By default no direct resource request is made.

securityContext:
readOnlyRootFilesystem: true

image:
repository: "vault"
tag: 1.3.0
Expand All @@ -31,7 +34,7 @@ server:
# memory: 256Mi
# cpu: 250m

# Ingress allows ingress services to be created to allow external access
# Ingress allows ingress services to be created to allow external access
# from Kubernetes to access Vault pods.
ingress:
enabled: false
Expand All @@ -55,7 +58,7 @@ server:
# method. https://www.vaultproject.io/docs/auth/kubernetes.html
authDelegator:
enabled: false

# extraContainers is a list of sidecar containers. Specified as a raw YAML string.
extraContainers: null

Expand Down