Skip to content

Commit

Permalink
Run container as non-root user
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkingit committed Aug 3, 2020
1 parent c1c5030 commit 6e5218d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
5 changes: 5 additions & 0 deletions build/process-template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ export TRAVIS_COMMIT
GIT_REMOTE="$(git remote get-url origin)"
export GIT_REMOTE

NODE_USER_ID="$(docker run -it node:lts-alpine /usr/bin/id -u node | tr -d '\r' | tr -d '\n')"
export NODE_USER_ID
NODE_GROUP_ID="$(docker run -it node:lts-alpine /usr/bin/id -g node | tr -d '\r' | tr -d '\n')"
export NODE_GROUP_ID

envsubst <"${THIS_DIR}/viewTemplate.json" >/tmp/view.json

npx mustache /tmp/view.json "${FILE}"
8 changes: 5 additions & 3 deletions build/viewTemplate.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"TRAVIS_COMMIT": "${TRAVIS_COMMIT}",
"GIT_REMOTE": "${GIT_REMOTE}",
"TRAVIS_TAG": "${TRAVIS_TAG}"
"TRAVIS_COMMIT": "${TRAVIS_COMMIT}",
"TRAVIS_TAG": "${TRAVIS_TAG}",
"GIT_REMOTE": "${GIT_REMOTE}",
"NODE_USER_ID": "${NODE_USER_ID}",
"NODE_GROUP_ID": "${NODE_GROUP_ID}"
}
30 changes: 14 additions & 16 deletions kubernetes/razeedash-api/resource.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@ kind: List
metadata:
name: razeedash-api
annotations:
version: "{{TRAVIS_COMMIT}}"
version: "{{{TRAVIS_COMMIT}}}"
type: array
items:

# api

- apiVersion: apps/v1
- apiVersion: apps/v1 #api
kind: Deployment
metadata:
annotations:
version: "{{TRAVIS_COMMIT}}"
version: "{{{TRAVIS_COMMIT}}}"
razee.io/git-repo: "{{{GIT_REMOTE}}}"
razee.io/commit-sha: "{{TRAVIS_COMMIT}}"
razee.io/commit-sha: "{{{TRAVIS_COMMIT}}}"
labels:
razee/watch-resource: "lite"
name: razeedash-api
Expand All @@ -35,16 +32,17 @@ items:
name: razeedash-api
spec:
securityContext:
fsGroup: 999
runAsUser: 999
runAsUser: {{{NODE_USER_ID}}}
runAsGroup: {{{NODE_GROUP_ID}}}
fsGroup: {{{NODE_GROUP_ID}}}
initContainers:
- env:
- name: MONGO_URL
valueFrom:
secretKeyRef:
name: razeedash-secret
key: mongo_url
image: "quay.io/razee/razeedash-api:{{TRAVIS_TAG}}"
image: "quay.io/razee/razeedash-api:{{{TRAVIS_TAG}}}"
command: ["npm", "run", "wait-mongo"]
imagePullPolicy: Always
name: razeedash-api-init
Expand Down Expand Up @@ -110,7 +108,7 @@ items:
optional: true
- name: REDIS_PUBSUB_URL
value: 'redis://redis-service:6379/0'
image: "quay.io/razee/razeedash-api:{{TRAVIS_TAG}}"
image: "quay.io/razee/razeedash-api:{{{TRAVIS_TAG}}}"
imagePullPolicy: Always
name: razeedash-api
ports:
Expand Down Expand Up @@ -144,9 +142,7 @@ items:
secret:
secretName: razeedash-secret

# redis

- apiVersion: apps/v1
- apiVersion: apps/v1 # redis
kind: Deployment
metadata:
name: redis
Expand All @@ -161,6 +157,10 @@ items:
app: redis
name: redis
spec:
securityContext:
runAsUser: 999
runAsGroup: 1000
fsGroup: 1000
containers:
- name: redis
image: redis:latest
Expand All @@ -183,8 +183,6 @@ items:
cpu: 1m
memory: 64Mi



- apiVersion: v1
kind: Service
metadata:
Expand Down

0 comments on commit 6e5218d

Please sign in to comment.