Skip to content

Commit 1b40c19

Browse files
authored
fix: add securityContext to kratos init containers (#622)
1 parent 8692a00 commit 1b40c19

File tree

5 files changed

+80
-17
lines changed

5 files changed

+80
-17
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ You can test and develop charts locally using
2222
To test a chart locally without applying it to kubernetes, do:
2323

2424
```sh
25-
$ helm install --debug --dry-run .
25+
$ helm install --debug --dry-run <name> .
2626
```
2727

2828
```sh
2929
$ name=<name>
30-
$ helm install --name $name .
30+
$ helm install $name .
3131
$ helm upgrade $name .
3232
```
3333

@@ -67,8 +67,8 @@ To run helm test, do:
6767

6868
```sh
6969
$ helm lint .
70-
$ helm install .
71-
$ helm test --cleanup <name>
70+
$ helm install <name> .
71+
$ helm test <name>
7272
```
7373

7474
### Remove all releases

hacks/values/kratos.yaml

+19
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ kratos:
2323
- "--yes"
2424
- "--config"
2525
- "/etc/config/kratos.yaml"
26+
resources:
27+
limits:
28+
cpu: 100m
29+
memory: 128Mi
30+
requests:
31+
cpu: 100m
32+
memory: 128Mi
2633
identitySchemas:
2734
"identity.default.schema.json": |
2835
{
@@ -206,6 +213,12 @@ deployment:
206213
ory.sh/pod_label: kratos
207214
annotations:
208215
ory.sh/pod_annotation: kratos
216+
initContainerSecurityContext:
217+
capabilities:
218+
drop:
219+
- ALL
220+
podSecurityContext:
221+
runAsNonRoot: false
209222
extraEnv:
210223
- name: FOO
211224
value: BAR
@@ -275,6 +288,12 @@ watcher:
275288
ory.sh/pod_label: kratos_watcher
276289
annotations:
277290
ory.sh/pod_annotation: kratos_watcher
291+
securityContext:
292+
capabilities:
293+
drop:
294+
- ALL
295+
podSecurityContext:
296+
runAsNonRoot: false
278297

279298
cleanup:
280299
enabled: true

helm/charts/kratos/templates/deployment-kratos.yaml

+15-3
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ spec:
8585
{{- if $migrationExtraEnv }}
8686
{{- toYaml $migrationExtraEnv | nindent 12 }}
8787
{{- end }}
88+
{{- with .Values.kratos.automigration.resources }}
89+
resources:
90+
{{- toYaml . | nindent 12 }}
91+
{{- end }}
92+
{{- with .Values.deployment.initContainerSecurityContext }}
93+
securityContext:
94+
{{- toYaml . | nindent 12 }}
95+
{{- end }}
8896
{{- end }}
8997
volumes:
9098
{{- if .Values.deployment.extraVolumes }}
@@ -212,7 +220,7 @@ spec:
212220
{{- toYaml .Values.deployment.readinessProbe | nindent 12 }}
213221
{{- end }}
214222
startupProbe:
215-
{{- if .Values.deployment.customStartupProbe }}
223+
{{- if .Values.deployment.customStartupProbe }}
216224
{{- toYaml .Values.deployment.customStartupProbe | nindent 12 }}
217225
{{- else }}
218226
httpGet:
@@ -225,9 +233,9 @@ spec:
225233
{{- end }}
226234
resources:
227235
{{- toYaml .Values.deployment.resources | nindent 12 }}
228-
{{- if .Values.securityContext }}
236+
{{- with .Values.securityContext }}
229237
securityContext:
230-
{{- toYaml .Values.securityContext | nindent 12 }}
238+
{{- toYaml . | nindent 12 }}
231239
{{- end }}
232240
{{- if .Values.deployment.extraContainers }}
233241
{{- tpl .Values.deployment.extraContainers . | nindent 8 }}
@@ -248,6 +256,10 @@ spec:
248256
topologySpreadConstraints:
249257
{{- toYaml . | nindent 8 }}
250258
{{- end }}
259+
{{- with .Values.deployment.podSecurityContext }}
260+
securityContext:
261+
{{- toYaml . | nindent 8 }}
262+
{{- end }}
251263
{{- with .Values.deployment.dnsConfig }}
252264
dnsConfig:
253265
{{- toYaml . | nindent 8 }}

helm/charts/kratos/templates/job-migration.yaml

+10-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ metadata:
2121
{{- end }}
2222
spec:
2323
template:
24-
metadata:
24+
metadata:
2525
annotations:
2626
{{- with .Values.job.annotations }}
2727
{{- toYaml . | nindent 8 }}
@@ -68,6 +68,10 @@ spec:
6868
{{- if $migrationExtraEnv }}
6969
{{- toYaml $migrationExtraEnv | nindent 10 }}
7070
{{- end }}
71+
{{- with .Values.kratos.automigration.resources }}
72+
resources:
73+
{{- toYaml . | nindent 10 }}
74+
{{- end }}
7175
{{- if .Values.job.lifecycle }}
7276
lifecycle:
7377
{{- tpl .Values.job.lifecycle . | nindent 10 }}
@@ -91,6 +95,10 @@ spec:
9195
{{- tpl .Values.job.extraInitContainers . | nindent 8 }}
9296
{{- end }}
9397
restartPolicy: Never
98+
{{- with .Values.deployment.podSecurityContext }}
99+
securityContext:
100+
{{- toYaml . | nindent 8 }}
101+
{{- end }}
94102
volumes:
95103
- name: {{ include "kratos.name" . }}-config-volume
96104
configMap:
@@ -108,4 +116,4 @@ spec:
108116
{{- end }}
109117
shareProcessNamespace: {{ .Values.job.shareProcessNamespace }}
110118
backoffLimit: {{ .Values.job.spec.backoffLimit }}
111-
{{- end }}
119+
{{- end }}

helm/charts/kratos/values.yaml

+32-8
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ kratos:
115115
enabled: false
116116
# -- Configure the way to execute database migration. Possible values: job, initContainer
117117
# When set to job, the migration will be executed as a job on release or upgrade.
118-
# When set to initContainer, the migration will be executed when kratos pod is created
118+
# When set to initContainer, the migration will be executed when Kratos pod is created
119119
# Defaults to job
120120
type: job
121121
# -- Ability to override the entrypoint of the automigration container
@@ -126,6 +126,8 @@ kratos:
126126
# - sleep 5;
127127
# - kratos
128128
customArgs: []
129+
# -- resource requests and limits for the automigration initcontainer
130+
resources: {}
129131

130132
# -- You can add multiple identity schemas here. You can pass JSON schema using `--set-file` Helm CLI argument.
131133
identitySchemas: {}
@@ -141,7 +143,7 @@ kratos:
141143
# "identity.phone.schema.json": |
142144
# {{ .Values.phone_schema }}
143145

144-
# -- You can customize the emails kratos is sending (also uncomment config.courier.template_override_path below)
146+
# -- You can customize the emails Kratos is sending (also uncomment config.courier.template_override_path below)
145147
emailTemplates: {}
146148
# emailTemplates:
147149
# recovery:
@@ -187,6 +189,25 @@ kratos:
187189

188190
# -- Configuration options for the k8s deployment
189191
deployment:
192+
## -- initContainer securityContext for Kratos & migration init
193+
initContainerSecurityContext: {}
194+
195+
## -- pod securityContext for Kratos & migration init
196+
podSecurityContext: {}
197+
198+
## -- container securityContext for Kratos & migration init
199+
securityContext:
200+
allowPrivilegeEscalation: false
201+
capabilities:
202+
drop:
203+
- ALL
204+
privileged: false
205+
readOnlyRootFilesystem: true
206+
runAsNonRoot: true
207+
runAsUser: 100
208+
seccompProfile:
209+
type: RuntimeDefault
210+
190211
lifecycle: {}
191212
# -- Configure the livenessProbe parameters
192213
livenessProbe:
@@ -499,6 +520,9 @@ job:
499520
# lines, adjust them as necessary, and remove the curly braces after 'nodeSelector:'.
500521
# foo: bar
501522

523+
# -- resource requests and limits for the job
524+
resources: {}
525+
502526
# -- Configure node tolerations.
503527
tolerations: []
504528

@@ -516,9 +540,9 @@ job:
516540
shareProcessNamespace: false
517541

518542
# -- Specify the serviceAccountName value.
519-
# In some situations it is needed to provides specific permissions to Hydra deployments
520-
# Like for example installing Hydra on a cluster with a PosSecurityPolicy and Istio.
521-
# Uncoment if it is needed to provide a ServiceAccount for the Hydra deployment.
543+
# In some situations it is needed to provide specific permissions to Kratos deployments
544+
# Like for example installing Kratos on a cluster with a PosSecurityPolicy and Istio.
545+
# Uncomment if it is needed to provide a ServiceAccount for the Kratos deployment.
522546
serviceAccount:
523547
# -- Specifies whether a service account should be created
524548
create: true
@@ -608,14 +632,14 @@ cronjob:
608632

609633
# -- Configure the containers' SecurityContext for the cleanup cronjob
610634
securityContext:
635+
allowPrivilegeEscalation: false
611636
capabilities:
612637
drop:
613638
- ALL
639+
privileged: false
614640
readOnlyRootFilesystem: true
615641
runAsNonRoot: true
616642
runAsUser: 100
617-
allowPrivilegeEscalation: false
618-
privileged: false
619643
seccompProfile:
620644
type: RuntimeDefault
621645

@@ -653,7 +677,7 @@ serviceMonitor:
653677
scrapeInterval: 60s
654678
# -- Timeout after which the scrape is ended
655679
scrapeTimeout: 30s
656-
# -- Provide additionnal labels to the ServiceMonitor ressource metadata
680+
# -- Provide additional labels to the ServiceMonitor ressource metadata
657681
labels: {}
658682
# -- TLS configuration to use when scraping the endpoint
659683
tlsConfig: {}

0 commit comments

Comments
 (0)