Skip to content

Commit 7a720da

Browse files
authored
Kubernetes simcore: add pod security standard (#1139)
* Kubernetes simcore: add pod security standard Ensure baseline policy and warn on restricted policy violations. The k8s way to add pod security standard, is to add labels to the namespace. The adding labels to namespace is achieved via helmfile hooks. Add helpful defaults for pod & container security context to ensure minimal privileges. WARNING: if deployed pod does not conform with baseline policy, it SILENTLY won't be scheduled. To see warnings / errors execute `kubectl -n simcore events' * #1137 * Improve security readme
1 parent 3e9c5e8 commit 7a720da

File tree

7 files changed

+83
-13
lines changed

7 files changed

+83
-13
lines changed

charts/SECURITY.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Security
2+
3+
This file documents security measures and their configuration in current code base
4+
5+
## Application developer
6+
7+
Full list: https://kubernetes.io/docs/concepts/security/application-security-checklist/
8+
9+
#### Pod-level securityContext recommendations
10+
11+
Enable pod security standard on namespace level:
12+
* create namespace with labels (examples and explanations https://aro-labs.com/pod-security-standards/)
13+
* configure pod and container security context to satisfy security standards (read more https://medium.com/dynatrace-engineering/kubernetes-security-part-3-security-context-7d44862c4cfa)
14+
15+
## Cluster / OPS developers
16+
17+
Full list: https://kubernetes.io/docs/concepts/security/security-checklist/

charts/simcore-charts/common-helpers/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type: application
1515
# This is the chart version. This version number should be incremented each time you make changes
1616
# to the chart and its templates, including the app version.
1717
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18-
version: 0.0.1
18+
version: 0.0.2
1919

2020
# This is the version number of the application being deployed. This version number should be
2121
# incremented each time you make changes to the application. Versions are not expected to

charts/simcore-charts/common-helpers/templates/_helpers.tpl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,36 @@ data:
7272
{{- end }}
7373
{{- end }}
7474
{{- end -}}
75+
76+
{{/*
77+
78+
Usage:
79+
{{- include "common-helpers.defaultPodSecurityContext" . | nindent 0 }}
80+
81+
Defines a common pod security context to ensure minimal privileges for containers.
82+
83+
Values inspired from https://medium.com/dynatrace-engineering/kubernetes-security-part-3-security-context-7d44862c4cfa
84+
*/}}
85+
{{- define "common-helpers.defaultPodSecurityContext" -}}
86+
runAsNonRoot: true
87+
seccompProfile:
88+
type: RuntimeDefault
89+
{{- end -}}
90+
91+
{{/*
92+
93+
Usage:
94+
{{- include "common-helpers.defaultContainerSecurityContext" . | nindent 0 }}
95+
96+
Defines a common container security context to ensure minimal privileges for containers.
97+
98+
Values inspired from https://medium.com/dynatrace-engineering/kubernetes-security-part-3-security-context-7d44862c4cfa
99+
*/}}
100+
{{- define "common-helpers.defaultContainerSecurityContext" -}}
101+
privileged: false
102+
readOnlyRootFilesystem: true
103+
allowPrivilegeEscalation: false
104+
capabilities:
105+
drop:
106+
- ALL
107+
{{- end -}}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# namespace with defined pod security standard
2+
# inspired from https://aro-labs.com/pod-security-standards/
3+
# official doc: https://kubernetes.io/docs/concepts/security/pod-security-standards/
4+
#
5+
# Warning: if pod / container does not meet enforced standards, it will not be deployed (silently)
6+
# execute `kubectl -n <namespace> events` to see errors (e.g.)
7+
# Error creating: pods "xyz" is forbidden: violates PodSecurity "baseline:latest": privileged
8+
# container "xyz" must not set securityContext.privileged to true
9+
#
10+
apiVersion: v1
11+
kind: Namespace
12+
metadata:
13+
name: simcore
14+
labels:
15+
pod-security.kubernetes.io/enforce: baseline
16+
pod-security.kubernetes.io/warn: restricted

charts/simcore-charts/resource-usage-tracker/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: A Helm chart for Kubernetes
44

55
dependencies:
66
- name: common-helpers
7-
version: 0.0.1
7+
version: 0.0.2
88
repository: "file://../common-helpers"
99

1010
# A chart can be either an 'application' or a 'library' chart.
@@ -20,7 +20,7 @@ type: application
2020
# This is the chart version. This version number should be incremented each time you make changes
2121
# to the chart and its templates, including the app version.
2222
# Versions are expected to follow Semantic Versioning (https://semver.org/)
23-
version: 0.0.1
23+
version: 0.0.2
2424

2525
# This is the version number of the application being deployed. This version number should be
2626
# incremented each time you make changes to the application. Versions are not expected to

charts/simcore-charts/resource-usage-tracker/templates/deployment.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,19 @@ spec:
2929
{{- end }}
3030
serviceAccountName: {{ include "resource-usage-tracker.serviceAccountName" . }}
3131
securityContext:
32+
{{- if .Values.podSecurityContext }}
3233
{{- toYaml .Values.podSecurityContext | nindent 8 }}
34+
{{- else }}
35+
{{- include "common-helpers.defaultPodSecurityContext" . | nindent 8 }}
36+
{{- end }}
3337
containers:
3438
- name: {{ .Chart.Name }}
3539
securityContext:
40+
{{- if .Values.securityContext }}
3641
{{- toYaml .Values.securityContext | nindent 12 }}
42+
{{- else }}
43+
{{- include "common-helpers.defaultContainerSecurityContext" . | nindent 12 }}
44+
{{- end }}
3745
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
3846
imagePullPolicy: {{ .Values.image.pullPolicy }}
3947
env:

charts/simcore-charts/resource-usage-tracker/values.yaml.gotmpl

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,12 @@ serviceAccount:
2828
podAnnotations: {}
2929
podLabels: {}
3030

31-
podSecurityContext: {}
32-
# fsGroup: 2000
33-
34-
securityContext: {}
35-
# capabilities:
36-
# drop:
37-
# - ALL
38-
# readOnlyRootFilesystem: true
39-
# runAsNonRoot: true
40-
# runAsUser: 1000
31+
podSecurityContext:
32+
seccompProfile:
33+
type: RuntimeDefault
34+
35+
securityContext:
36+
privileged: false
4137

4238
service:
4339
type: ClusterIP

0 commit comments

Comments
 (0)