Skip to content

Commit fd2e125

Browse files
authored
Update default container security context (#2265)
* Update default container security context Signed-off-by: Yi Chen <[email protected]> * Push user and group directives into Dockerfile Signed-off-by: Yi Chen <[email protected]> * Add allowPrivilegeEscalation to container security context Signed-off-by: Yi Chen <[email protected]> * fix: fsGroup should be moved to pod security context Signed-off-by: Yi Chen <[email protected]> --------- Signed-off-by: Yi Chen <[email protected]>
1 parent 735c7fc commit fd2e125

File tree

3 files changed

+29
-21
lines changed

3 files changed

+29
-21
lines changed

Dockerfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ RUN --mount=type=cache,target=/go/pkg/mod/ \
2626
go mod download
2727

2828
COPY . .
29+
2930
ENV GOCACHE=/root/.cache/go-build
31+
3032
ARG TARGETARCH
3133

3234
RUN --mount=type=cache,target=/go/pkg/mod/ \
@@ -35,6 +37,10 @@ RUN --mount=type=cache,target=/go/pkg/mod/ \
3537

3638
FROM ${SPARK_IMAGE}
3739

40+
ARG SPARK_UID=185
41+
42+
ARG SPARK_GID=185
43+
3844
USER root
3945

4046
RUN apt-get update \
@@ -45,7 +51,7 @@ RUN mkdir -p /etc/k8s-webhook-server/serving-certs /home/spark && \
4551
chmod -R g+rw /etc/k8s-webhook-server/serving-certs && \
4652
chown -R spark /etc/k8s-webhook-server/serving-certs /home/spark
4753

48-
USER spark
54+
USER ${SPARK_UID}:${SPARK_GID}
4955

5056
COPY --from=builder /workspace/bin/spark-operator /usr/bin/spark-operator
5157

charts/spark-operator-chart/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,13 @@ See [helm uninstall](https://helm.sh/docs/helm/helm_uninstall) for command docum
106106
| controller.affinity | object | `{}` | Affinity for controller pods. |
107107
| controller.tolerations | list | `[]` | List of node taints to tolerate for controller pods. |
108108
| controller.priorityClassName | string | `""` | Priority class for controller pods. |
109-
| controller.podSecurityContext | object | `{}` | Security context for controller pods. |
109+
| controller.podSecurityContext | object | `{"fsGroup":185}` | Security context for controller pods. |
110110
| controller.topologySpreadConstraints | list | `[]` | Topology spread constraints rely on node labels to identify the topology domain(s) that each Node is in. Ref: [Pod Topology Spread Constraints](https://kubernetes.io/docs/concepts/workloads/pods/pod-topology-spread-constraints/). The labelSelector field in topology spread constraint will be set to the selector labels for controller pods if not specified. |
111111
| controller.env | list | `[]` | Environment variables for controller containers. |
112112
| controller.envFrom | list | `[]` | Environment variable sources for controller containers. |
113113
| controller.volumeMounts | list | `[]` | Volume mounts for controller containers. |
114114
| controller.resources | object | `{}` | Pod resource requests and limits for controller containers. Note, that each job submission will spawn a JVM within the controller pods using "/usr/local/openjdk-11/bin/java -Xmx128m". Kubernetes may kill these Java processes at will to enforce resource limits. When that happens, you will see the following error: 'failed to run spark-submit for SparkApplication [...]: signal: killed' - when this happens, you may want to increase memory limits. |
115-
| controller.securityContext | object | `{}` | Security context for controller containers. |
115+
| controller.securityContext | object | `{"allowPrivilegeEscalation":false,"capabilities":{"drop":["ALL"]},"privileged":false,"runAsNonRoot":true}` | Security context for controller containers. |
116116
| controller.sidecars | list | `[]` | Sidecar containers for controller pods. |
117117
| controller.podDisruptionBudget.enable | bool | `false` | Specifies whether to create pod disruption budget for controller. Ref: [Specifying a Disruption Budget for your Application](https://kubernetes.io/docs/tasks/run-application/configure-pdb/) |
118118
| controller.podDisruptionBudget.minAvailable | int | `1` | The number of pods that must be available. Require `controller.replicas` to be greater than 1 |
@@ -144,13 +144,13 @@ See [helm uninstall](https://helm.sh/docs/helm/helm_uninstall) for command docum
144144
| webhook.affinity | object | `{}` | Affinity for webhook pods. |
145145
| webhook.tolerations | list | `[]` | List of node taints to tolerate for webhook pods. |
146146
| webhook.priorityClassName | string | `""` | Priority class for webhook pods. |
147-
| webhook.podSecurityContext | object | `{}` | Security context for webhook pods. |
147+
| webhook.podSecurityContext | object | `{"fsGroup":185}` | Security context for webhook pods. |
148148
| webhook.topologySpreadConstraints | list | `[]` | Topology spread constraints rely on node labels to identify the topology domain(s) that each Node is in. Ref: [Pod Topology Spread Constraints](https://kubernetes.io/docs/concepts/workloads/pods/pod-topology-spread-constraints/). The labelSelector field in topology spread constraint will be set to the selector labels for webhook pods if not specified. |
149149
| webhook.env | list | `[]` | Environment variables for webhook containers. |
150150
| webhook.envFrom | list | `[]` | Environment variable sources for webhook containers. |
151151
| webhook.volumeMounts | list | `[]` | Volume mounts for webhook containers. |
152152
| webhook.resources | object | `{}` | Pod resource requests and limits for webhook pods. |
153-
| webhook.securityContext | object | `{}` | Security context for webhook containers. |
153+
| webhook.securityContext | object | `{"allowPrivilegeEscalation":false,"capabilities":{"drop":["ALL"]},"privileged":false,"runAsNonRoot":true}` | Security context for webhook containers. |
154154
| webhook.podDisruptionBudget.enable | bool | `false` | Specifies whether to create pod disruption budget for webhook. Ref: [Specifying a Disruption Budget for your Application](https://kubernetes.io/docs/tasks/run-application/configure-pdb/) |
155155
| webhook.podDisruptionBudget.minAvailable | int | `1` | The number of pods that must be available. Require `webhook.replicas` to be greater than 1 |
156156
| spark.jobNamespaces | list | `["default"]` | List of namespaces where to run spark jobs. If empty string is included, all namespaces will be allowed. Make sure the namespaces have already existed. |

charts/spark-operator-chart/values.yaml

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,8 @@ controller:
120120
priorityClassName: ""
121121

122122
# -- Security context for controller pods.
123-
podSecurityContext: {}
124-
# runAsUser: 1000
125-
# runAsGroup: 2000
126-
# fsGroup: 3000
123+
podSecurityContext:
124+
fsGroup: 185
127125

128126
# -- Topology spread constraints rely on node labels to identify the topology domain(s) that each Node is in.
129127
# Ref: [Pod Topology Spread Constraints](https://kubernetes.io/docs/concepts/workloads/pods/pod-topology-spread-constraints/).
@@ -158,10 +156,13 @@ controller:
158156
# memory: 300Mi
159157

160158
# -- Security context for controller containers.
161-
securityContext: {}
162-
# runAsUser: 1000
163-
# runAsGroup: 2000
164-
# fsGroup: 3000
159+
securityContext:
160+
privileged: false
161+
allowPrivilegeEscalation: false
162+
runAsNonRoot: true
163+
capabilities:
164+
drop:
165+
- ALL
165166

166167
# -- Sidecar containers for controller pods.
167168
sidecars: []
@@ -266,10 +267,8 @@ webhook:
266267
priorityClassName: ""
267268

268269
# -- Security context for webhook pods.
269-
podSecurityContext: {}
270-
# runAsUser: 1000
271-
# runAsGroup: 2000
272-
# fsGroup: 3000
270+
podSecurityContext:
271+
fsGroup: 185
273272

274273
# -- Topology spread constraints rely on node labels to identify the topology domain(s) that each Node is in.
275274
# Ref: [Pod Topology Spread Constraints](https://kubernetes.io/docs/concepts/workloads/pods/pod-topology-spread-constraints/).
@@ -301,10 +300,13 @@ webhook:
301300
# memory: 300Mi
302301

303302
# -- Security context for webhook containers.
304-
securityContext: {}
305-
# runAsUser: 1000
306-
# runAsGroup: 2000
307-
# fsGroup: 3000
303+
securityContext:
304+
privileged: false
305+
allowPrivilegeEscalation: false
306+
runAsNonRoot: true
307+
capabilities:
308+
drop:
309+
- ALL
308310

309311
# Pod disruption budget for webhook to avoid service degradation.
310312
podDisruptionBudget:

0 commit comments

Comments
 (0)