Skip to content

Commit

Permalink
chore: run containers as non-root on GKE (#431)
Browse files Browse the repository at this point in the history
  • Loading branch information
henrybell authored Jan 13, 2025
1 parent fd06f18 commit 558b74a
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Dockerfile-poller
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ COPY package*.json ./
COPY autoscaler-config.schema.json ./
RUN npm config set update-notifier false
RUN npm install --omit=dev
RUN find /usr/src/app/ -type d -exec chmod a+x '{}' ';'
RUN find /usr/src/app/ -type f -name '*.js*' -exec chmod a+r '{}' ';'

FROM gcr.io/distroless/nodejs${NODE_VERSION}:latest
FROM gcr.io/distroless/nodejs${NODE_VERSION}:nonroot
COPY --from=build-env /usr/src/app /usr/src/app
WORKDIR /usr/src/app/

Expand Down
4 changes: 3 additions & 1 deletion Dockerfile-scaler
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ COPY src/scaler/ src/scaler/
COPY package*.json ./
RUN npm config set update-notifier false
RUN npm install --omit=dev
RUN find /usr/src/app/ -type d -exec chmod a+x '{}' ';'
RUN find /usr/src/app/ -type f -name '*.js*' -exec chmod a+r '{}' ';'

FROM gcr.io/distroless/nodejs${NODE_VERSION}:latest
FROM gcr.io/distroless/nodejs${NODE_VERSION}:nonroot
COPY --from=build-env /usr/src/app /usr/src/app
WORKDIR /usr/src/app/

Expand Down
4 changes: 3 additions & 1 deletion Dockerfile-unified
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ COPY package*.json ./
COPY autoscaler-config.schema.json ./
RUN npm config set update-notifier false
RUN npm install --omit=dev
RUN find /usr/src/app/ -type d -exec chmod a+x '{}' ';'
RUN find /usr/src/app/ -type f -name '*.js*' -exec chmod a+r '{}' ';'

FROM gcr.io/distroless/nodejs${NODE_VERSION}:latest
FROM gcr.io/distroless/nodejs${NODE_VERSION}:nonroot
COPY --from=build-env /usr/src/app /usr/src/app
WORKDIR /usr/src/app/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ spec:
args:
- --config
- /etc/otel/config.yaml
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
runAsNonRoot: true
capabilities:
drop:
- all
volumeMounts:
- mountPath: /etc/otel/
name: otel-config
Expand Down
7 changes: 7 additions & 0 deletions kubernetes/decoupled/autoscaler-pkg/poller/poller-hourly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ spec:
value: "http://otel-collector:4317/"
- name: OTEL_IS_LONG_RUNNING_PROCESS
value: "false"
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
runAsNonRoot: true
capabilities:
drop:
- all
volumeMounts:
- name: config-volume
mountPath: /etc/autoscaler-config
Expand Down
7 changes: 7 additions & 0 deletions kubernetes/decoupled/autoscaler-pkg/poller/poller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ spec:
value: "http://otel-collector:4317/"
- name: OTEL_IS_LONG_RUNNING_PROCESS
value: "false"
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
runAsNonRoot: true
capabilities:
drop:
- all
volumeMounts:
- name: config-volume
mountPath: /etc/autoscaler-config
Expand Down
7 changes: 7 additions & 0 deletions kubernetes/decoupled/autoscaler-pkg/scaler/scaler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ spec:
value: "http://otel-collector:4317/"
- name: OTEL_IS_LONG_RUNNING_PROCESS
value: "true"
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
runAsNonRoot: true
capabilities:
drop:
- all
nodeSelector:
iam.gke.io/gke-metadata-server-enabled: "true"
serviceAccountName: scaler-sa
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ spec:
args:
- --config
- /etc/otel/config.yaml
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
runAsNonRoot: true
capabilities:
drop:
- all
volumeMounts:
- mountPath: /etc/otel/
name: otel-config
Expand Down
7 changes: 7 additions & 0 deletions kubernetes/unified/autoscaler-pkg/scaler/scaler-hourly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ spec:
value: "http://otel-collector:4317/"
- name: OTEL_IS_LONG_RUNNING_PROCESS
value: "false"
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
runAsNonRoot: true
capabilities:
drop:
- all
volumeMounts:
- name: config-volume
mountPath: /etc/autoscaler-config
Expand Down
7 changes: 7 additions & 0 deletions kubernetes/unified/autoscaler-pkg/scaler/scaler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ spec:
value: "http://otel-collector:4317/"
- name: OTEL_IS_LONG_RUNNING_PROCESS
value: "false"
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
runAsNonRoot: true
capabilities:
drop:
- all
volumeMounts:
- name: config-volume
mountPath: /etc/autoscaler-config
Expand Down

0 comments on commit 558b74a

Please sign in to comment.