Skip to content
This repository was archived by the owner on Oct 14, 2020. It is now read-only.

Commit 4695e1e

Browse files
authored
Merge pull request #129 from secureCodeBox/security-contexts
Add securityContexts to secureCodeBox Components
2 parents 7123845 + 1823a60 commit 4695e1e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+454
-133
lines changed

hook-sdk/nodejs/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ RUN npm ci --production
55

66
FROM node:12-alpine
77
ARG NODE_ENV
8-
RUN addgroup -S app && adduser app -S -G app
8+
RUN addgroup --system --gid 1001 app && adduser app --system --uid 1001 --ingroup app
99
WORKDIR /home/app/hook-wrapper/
1010
COPY --from=build --chown=app:app /home/app/node_modules/ ./node_modules/
1111
COPY --chown=app:app ./hook-wrapper.js ./hook-wrapper.js
12-
USER app
12+
USER 1001
1313
ENV NODE_ENV ${NODE_ENV:-production}
14-
ENTRYPOINT ["node", "/home/app/hook-wrapper/hook-wrapper.js"]
14+
ENTRYPOINT ["node", "/home/app/hook-wrapper/hook-wrapper.js"]

lurcher/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,5 @@ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o lurcher
2020
FROM gcr.io/distroless/static:nonroot
2121
WORKDIR /
2222
COPY --from=builder /workspace/lurcher .
23-
USER nonroot:nonroot
2423

2524
ENTRYPOINT ["/lurcher"]

operator/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,5 @@ ENV TELEMETRY_ENABLED "true"
2828

2929
WORKDIR /
3030
COPY --from=builder /workspace/manager .
31-
USER nonroot:nonroot
3231

3332
ENTRYPOINT ["/manager"]

operator/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ helm install securecodebox-operator secureCodeBox/operator
2424
| image.pullPolicy | string | `"Always"` | Image pull policy |
2525
| image.repository | string | `"docker.io/securecodebox/operator"` | The operator image repository |
2626
| image.tag | string | defaults to the charts version | Parser image tag |
27-
| lurcher.image.pullPolicy | string | `"IfNotPresent"` | Image pull policy |
27+
| lurcher.image.pullPolicy | string | `"Always"` | Image pull policy |
2828
| lurcher.image.repository | string | `"docker.io/securecodebox/lurcher"` | The operator image repository |
2929
| lurcher.image.tag | string | defaults to the charts version | Parser image tag |
3030
| minio.defaultBucket.enabled | bool | `true` | |
@@ -38,5 +38,10 @@ helm install securecodebox-operator secureCodeBox/operator
3838
| s3.port | string | `nil` | |
3939
| s3.secretAttributeNames.accesskey | string | `"accesskey"` | |
4040
| s3.secretAttributeNames.secretkey | string | `"secretkey"` | |
41+
| securityContext.allowPrivilegeEscalation | bool | `false` | Ensure that users privileges cannot be escalated |
42+
| securityContext.capabilities.drop[0] | string | `"all"` | This drops all linux privileges from the operator container. They are not required |
43+
| securityContext.privileged | bool | `false` | Ensures that the operator container is not run in privileged mode |
44+
| securityContext.readOnlyRootFilesystem | bool | `true` | Prevents write access to the containers file system |
45+
| securityContext.runAsNonRoot | bool | `true` | Enforces that the Operator image is run as a non root user |
4146
| telemetryEnabled | bool | `true` | The Operator sends anonymous telemetry data, to give the team an overview how much the secureCodeBox is used. Find out more at https://www.securecodebox.io/telemetry |
4247

operator/controllers/execution/scans/hook_reconciler.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,8 @@ func (r *ScanReconciler) createJobForHook(hook *executionv1.ScanCompletionHook,
362362
labels["securecodebox.io/hook-name"] = hook.Name
363363

364364
var backOffLimit int32 = 3
365+
truePointer := true
366+
falsePointer := false
365367
job := &batch.Job{
366368
ObjectMeta: metav1.ObjectMeta{
367369
Annotations: make(map[string]string),
@@ -388,7 +390,7 @@ func (r *ScanReconciler) createJobForHook(hook *executionv1.ScanCompletionHook,
388390
Image: hook.Spec.Image,
389391
Args: cliArgs,
390392
Env: append(hook.Spec.Env, standardEnvVars...),
391-
ImagePullPolicy: "IfNotPresent",
393+
ImagePullPolicy: "Always",
392394
Resources: corev1.ResourceRequirements{
393395
Requests: corev1.ResourceList{
394396
corev1.ResourceCPU: resource.MustParse("200m"),
@@ -399,6 +401,15 @@ func (r *ScanReconciler) createJobForHook(hook *executionv1.ScanCompletionHook,
399401
corev1.ResourceMemory: resource.MustParse("200Mi"),
400402
},
401403
},
404+
SecurityContext: &corev1.SecurityContext{
405+
RunAsNonRoot: &truePointer,
406+
AllowPrivilegeEscalation: &falsePointer,
407+
ReadOnlyRootFilesystem: &truePointer,
408+
Privileged: &falsePointer,
409+
Capabilities: &corev1.Capabilities{
410+
Drop: []corev1.Capability{"all"},
411+
},
412+
},
402413
},
403414
},
404415
},

operator/controllers/execution/scans/parse_reconciler.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ func (r *ScanReconciler) startParser(scan *executionv1.Scan) error {
8080
labels["securecodebox.io/job-type"] = "parser"
8181
automountServiceAccountToken := true
8282
var backOffLimit int32 = 3
83+
truePointer := true
84+
falsePointer := false
8385
job := &batch.Job{
8486
ObjectMeta: metav1.ObjectMeta{
8587
Annotations: make(map[string]string),
@@ -133,6 +135,15 @@ func (r *ScanReconciler) startParser(scan *executionv1.Scan) error {
133135
corev1.ResourceMemory: resource.MustParse("200Mi"),
134136
},
135137
},
138+
SecurityContext: &corev1.SecurityContext{
139+
RunAsNonRoot: &truePointer,
140+
AllowPrivilegeEscalation: &falsePointer,
141+
ReadOnlyRootFilesystem: &truePointer,
142+
Privileged: &falsePointer,
143+
Capabilities: &corev1.Capabilities{
144+
Drop: []corev1.Capability{"all"},
145+
},
146+
},
136147
},
137148
},
138149
AutomountServiceAccountToken: &automountServiceAccountToken,

operator/controllers/execution/scans/scan_reconciler.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ func (r *ScanReconciler) constructJobForScan(scan *executionv1.Scan, scanType *e
221221
return nil, fmt.Errorf("Unknown imagePull Policy for lurcher: %s", lurcherPullPolicyRaw)
222222
}
223223

224+
falsePointer := false
225+
truePointer := true
226+
224227
lurcherSidecar := &corev1.Container{
225228
Name: "lurcher",
226229
Image: lurcherImage,
@@ -260,6 +263,15 @@ func (r *ScanReconciler) constructJobForScan(scan *executionv1.Scan, scanType *e
260263
ReadOnly: true,
261264
},
262265
},
266+
SecurityContext: &corev1.SecurityContext{
267+
RunAsNonRoot: &truePointer,
268+
AllowPrivilegeEscalation: &falsePointer,
269+
ReadOnlyRootFilesystem: &truePointer,
270+
Privileged: &falsePointer,
271+
Capabilities: &corev1.Capabilities{
272+
Drop: []corev1.Capability{"all"},
273+
},
274+
},
263275
}
264276

265277
job.Spec.Template.Spec.Containers = append(job.Spec.Template.Spec.Containers, *lurcherSidecar)

operator/templates/manager/manager.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,6 @@ spec:
7777
value: {{ .Values.lurcher.image.pullPolicy }}
7878
resources:
7979
{{- toYaml .Values.resources | nindent 12 }}
80+
securityContext:
81+
{{- toYaml .Values.securityContext | nindent 12 }}
8082
terminationGracePeriodSeconds: 10

operator/values.yaml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@ image:
1414
# image.pullPolicy -- Image pull policy
1515
pullPolicy: Always
1616

17+
securityContext:
18+
# securityContext.runAsNonRoot -- Enforces that the Operator image is run as a non root user
19+
runAsNonRoot: true
20+
# securityContext.readOnlyRootFilesystem -- Prevents write access to the containers file system
21+
readOnlyRootFilesystem: true
22+
# securityContext.allowPrivilegeEscalation -- Ensure that users privileges cannot be escalated
23+
allowPrivilegeEscalation: false
24+
# securityContext.privileged -- Ensures that the operator container is not run in privileged mode
25+
privileged: false
26+
capabilities:
27+
drop:
28+
# securityContext.capabilities.drop[0] -- This drops all linux privileges from the operator container. They are not required
29+
- all
30+
1731
lurcher:
1832
image:
1933
# lurcher.image.repository -- The operator image repository
@@ -22,7 +36,7 @@ lurcher:
2236
# @default -- defaults to the charts version
2337
tag: null
2438
# lurcher.image.pullPolicy -- Image pull policy
25-
pullPolicy: IfNotPresent
39+
pullPolicy: Always
2640

2741
minio:
2842
# minio.enabled Enable this to use minio as storage backend instead of a cloud bucket provider like AWS S3, Google Cloud Storage, DigitalOcean Spaces etc.

parser-sdk/nodejs/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ RUN npm ci --production
55

66
FROM node:12-alpine
77
ARG NODE_ENV
8-
RUN addgroup -S app && adduser app -S -G app
8+
RUN addgroup --system --gid 1001 app && adduser app --system --uid 1001 --ingroup app
99
WORKDIR /home/app/parser-wrapper/
1010
COPY --from=build --chown=app:app /home/app/node_modules/ ./node_modules/
1111
COPY --chown=app:app ./parser-wrapper.js ./parser-wrapper.js
12-
USER app
12+
USER 1001
1313
ENV NODE_ENV ${NODE_ENV:-production}
14-
ENTRYPOINT ["node", "/home/app/parser-wrapper/parser-wrapper.js"]
14+
ENTRYPOINT ["node", "/home/app/parser-wrapper/parser-wrapper.js"]

0 commit comments

Comments
 (0)