Skip to content

Commit

Permalink
feat: custom security context for kafka addon (#1337)
Browse files Browse the repository at this point in the history
Co-authored-by: lancelot1989 <[email protected]>
  • Loading branch information
lancelot1989 and lancelot1989 authored Jan 22, 2025
1 parent 19d658a commit ec44453
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 27 deletions.
15 changes: 9 additions & 6 deletions addons/kafka/templates/cmpd-broker-27.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,18 @@ spec:
namespace: {{ .Release.Namespace }}
defaultMode: 0755
runtime:
{{- if .Values.securityContext }}
securityContext:
fsGroup: 1001
{{- toYaml .Values.securityContext | nindent 6 }}
{{- end }}
containers:
- name: kafka
image: {{ .Values.images.registry | default "docker.io" }}/{{ .Values.images.kafka.repository }}:{{ default .Values.images.kafka2.tag }}
imagePullPolicy: {{ default "IfNotPresent" .Values.images.pullPolicy }}
{{- if .Values.container.securityContext }}
securityContext:
allowPrivilegeEscalation: false
runAsNonRoot: true
runAsUser: 1001
{{- toYaml .Values.container.securityContext | nindent 10 }}
{{- end }}
command:
- /scripts/kafka-server-setup.sh
env:
Expand Down Expand Up @@ -228,9 +230,10 @@ spec:
- name: jmx-exporter
image: {{ .Values.images.registry | default "docker.io" }}/{{ .Values.images.jmxExporter.repository }}:{{ .Values.images.jmxExporter.tag }}
imagePullPolicy: {{ default "IfNotPresent" .Values.images.pullPolicy }}
{{- if .Values.exporter.securityContext }}
securityContext:
runAsNonRoot: true
runAsUser: 1001
{{- toYaml .Values.exporter.securityContext | nindent 10 }}
{{- end }}
command:
- java
args:
Expand Down
15 changes: 9 additions & 6 deletions addons/kafka/templates/cmpd-broker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,18 @@ spec:
namespace: {{ .Release.Namespace }}
defaultMode: 0755
runtime:
{{- if .Values.securityContext }}
securityContext:
fsGroup: 1001
{{- toYaml .Values.securityContext | nindent 6 }}
{{- end }}
containers:
- name: kafka
image: {{ .Values.images.registry | default "docker.io" }}/{{ .Values.images.kafka.repository }}:{{ default .Chart.AppVersion .Values.images.kafka.tag }}
imagePullPolicy: {{ default "IfNotPresent" .Values.images.pullPolicy }}
{{- if .Values.container.securityContext }}
securityContext:
allowPrivilegeEscalation: false
runAsNonRoot: true
runAsUser: 1001
{{- toYaml .Values.container.securityContext | nindent 10 }}
{{- end }}
command:
- /scripts/kafka-server-setup.sh
env:
Expand Down Expand Up @@ -228,9 +230,10 @@ spec:
- name: jmx-exporter
image: {{ .Values.images.registry | default "docker.io" }}/{{ .Values.images.jmxExporter.repository }}:{{ .Values.images.jmxExporter.tag }}
imagePullPolicy: {{ default "IfNotPresent" .Values.images.pullPolicy }}
{{- if .Values.exporter.securityContext }}
securityContext:
runAsNonRoot: true
runAsUser: 1001
{{- toYaml .Values.exporter.securityContext | nindent 10 }}
{{- end }}
command:
- java
args:
Expand Down
15 changes: 9 additions & 6 deletions addons/kafka/templates/cmpd-combine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,18 @@ spec:
namespace: {{ .Release.Namespace }}
defaultMode: 0755
runtime:
{{- if .Values.securityContext }}
securityContext:
fsGroup: 1001
{{- toYaml .Values.securityContext | nindent 6 }}
{{- end }}
containers:
- name: kafka
image: {{ .Values.images.registry | default "docker.io" }}/{{ .Values.images.kafka.repository }}:{{ default .Chart.AppVersion .Values.images.kafka.tag }}
imagePullPolicy: {{ default "IfNotPresent" .Values.images.pullPolicy }}
{{- if .Values.container.securityContext }}
securityContext:
allowPrivilegeEscalation: false
runAsNonRoot: true
runAsUser: 1001
{{- toYaml .Values.container.securityContext | nindent 10 }}
{{- end }}
command:
- /scripts/kafka-server-setup.sh
env:
Expand Down Expand Up @@ -219,9 +221,10 @@ spec:
- name: jmx-exporter
image: {{ .Values.images.registry | default "docker.io" }}/{{ .Values.images.jmxExporter.repository }}:{{ .Values.images.jmxExporter.tag }}
imagePullPolicy: {{ default "IfNotPresent" .Values.images.pullPolicy }}
{{- if .Values.exporter.securityContext }}
securityContext:
runAsNonRoot: true
runAsUser: 1001
{{- toYaml .Values.exporter.securityContext | nindent 10 }}
{{- end }}
command:
- java
args:
Expand Down
15 changes: 9 additions & 6 deletions addons/kafka/templates/cmpd-controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,18 @@ spec:
namespace: {{ .Release.Namespace }}
defaultMode: 0755
runtime:
{{- if .Values.securityContext }}
securityContext:
fsGroup: 1001
{{- toYaml .Values.securityContext | nindent 6 }}
{{- end }}
containers:
- name: kafka
image: {{ .Values.images.registry | default "docker.io" }}/{{ .Values.images.kafka.repository }}:{{ default .Chart.AppVersion .Values.images.kafka.tag }}
imagePullPolicy: {{ default "IfNotPresent" .Values.images.pullPolicy }}
{{- if .Values.container.securityContext }}
securityContext:
allowPrivilegeEscalation: false
runAsNonRoot: true
runAsUser: 1001
{{- toYaml .Values.container.securityContext | nindent 10 }}
{{- end }}
command:
- /scripts/kafka-server-setup.sh
env:
Expand Down Expand Up @@ -155,9 +157,10 @@ spec:
- name: jmx-exporter
image: {{ .Values.images.registry | default "docker.io" }}/{{ .Values.images.jmxExporter.repository }}:{{ .Values.images.jmxExporter.tag }}
imagePullPolicy: {{ default "IfNotPresent" .Values.images.pullPolicy }}
{{- if .Values.exporter.securityContext }}
securityContext:
runAsNonRoot: true
runAsUser: 1001
{{- toYaml .Values.exporter.securityContext | nindent 10 }}
{{- end }}
command:
- java
args:
Expand Down
9 changes: 6 additions & 3 deletions addons/kafka/templates/cmpd-exporter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,18 @@ spec:
namespace: {{ .Release.Namespace }}
defaultMode: 0755
runtime:
{{- if .Values.securityContext }}
securityContext:
fsGroup: 1001
{{- toYaml .Values.securityContext | nindent 6 }}
{{- end }}
containers:
- name: kafka-exporter
image: {{ .Values.images.registry | default "docker.io" }}/{{ .Values.images.kafkaExporter.repository }}:{{ .Values.images.kafkaExporter.tag }}
imagePullPolicy: {{ default "IfNotPresent" .Values.images.pullPolicy }}
{{- if .Values.exporter.securityContext }}
securityContext:
runAsNonRoot: true
runAsUser: 1001
{{- toYaml .Values.exporter.securityContext | nindent 8 }}
{{- end }}
env:
- name: SERVICE_PORT
value: "9308"
Expand Down
17 changes: 17 additions & 0 deletions addons/kafka/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,20 @@ storageClassParameters:
metadata:
awsEBSVolumeType: io2
awsEBSEnableBlockExpress: false

## pod security context settings
securityContext:
fsGroup: 1001

## container security context settings
container:
securityContext:
allowPrivilegeEscalation: false
runAsNonRoot: true
runAsUser: 1001

## exporter security context settings
exporter:
securityContext:
runAsNonRoot: true
runAsUser: 1001

0 comments on commit ec44453

Please sign in to comment.