Skip to content

Commit 1775f16

Browse files
committed
feat: restricted security context
1 parent 4dc695c commit 1775f16

File tree

4 files changed

+52
-24
lines changed

4 files changed

+52
-24
lines changed

bento-downloader/Dockerfile

+10
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,13 @@ RUN curl https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud
1111
&& tar -xf google-cloud-cli-410.tar.gz \
1212
&& ./google-cloud-sdk/install.sh \
1313
&& rm google-cloud-cli-410.tar.gz
14+
15+
ARG USERNAME=yetone
16+
ARG USER_UID=1000
17+
ARG USER_GID=$USER_UID
18+
19+
# Create the user
20+
RUN groupadd --gid $USER_GID $USERNAME \
21+
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME
22+
23+
USER $USER_UID

bento-downloader/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
IMAGE := quay.io/bentoml/bento-downloader:0.0.1
1+
IMAGE := quay.io/bentoml/bento-downloader:0.0.3
22

33
build:
44
docker build -t ${IMAGE} .

controllers/resources/bentorequest_controller.go

+31-13
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,17 @@ echo "Done"
12001200
})
12011201
}
12021202

1203+
restrictedSecurityContext := &corev1.SecurityContext{
1204+
AllowPrivilegeEscalation: pointer.BoolPtr(false),
1205+
RunAsNonRoot: pointer.BoolPtr(true),
1206+
SeccompProfile: &corev1.SeccompProfile{
1207+
Type: corev1.SeccompProfileTypeRuntimeDefault,
1208+
},
1209+
Capabilities: &corev1.Capabilities{
1210+
Drop: []corev1.Capability{"ALL"},
1211+
},
1212+
}
1213+
12031214
initContainers := []corev1.Container{
12041215
{
12051216
Name: "bento-downloader",
@@ -1209,9 +1220,10 @@ echo "Done"
12091220
"-c",
12101221
bentoDownloadCommand,
12111222
},
1212-
VolumeMounts: volumeMounts,
1213-
Resources: downloaderContainerResources,
1214-
EnvFrom: downloaderContainerEnvFrom,
1223+
VolumeMounts: volumeMounts,
1224+
Resources: downloaderContainerResources,
1225+
EnvFrom: downloaderContainerEnvFrom,
1226+
SecurityContext: restrictedSecurityContext,
12151227
},
12161228
}
12171229

@@ -1329,9 +1341,10 @@ echo "Done"
13291341
"-c",
13301342
modelDownloadCommand,
13311343
},
1332-
VolumeMounts: volumeMounts,
1333-
Resources: downloaderContainerResources,
1334-
EnvFrom: downloaderContainerEnvFrom,
1344+
VolumeMounts: volumeMounts,
1345+
Resources: downloaderContainerResources,
1346+
EnvFrom: downloaderContainerEnvFrom,
1347+
SecurityContext: restrictedSecurityContext,
13351348
})
13361349
}
13371350

@@ -1488,14 +1501,13 @@ echo "Done"
14881501
Privileged: pointer.BoolPtr(true),
14891502
}
14901503
} else if buildEngine == BentoImageBuildEngineBuildkitRootless {
1491-
kubeAnnotations["container.apparmor.security.beta.kubernetes.io/builder"] = "unconfined"
1492-
builderContainerSecurityContext = &corev1.SecurityContext{
1493-
SeccompProfile: &corev1.SeccompProfile{
1494-
Type: corev1.SeccompProfileTypeUnconfined,
1495-
},
1496-
RunAsUser: pointer.Int64Ptr(1000),
1497-
RunAsGroup: pointer.Int64Ptr(1000),
1504+
kubeAnnotations["container.apparmor.security.beta.kubernetes.io/builder"] = "runtime/default"
1505+
for _, container := range initContainers {
1506+
kubeAnnotations[fmt.Sprintf("container.apparmor.security.beta.kubernetes.io/%s", container.Name)] = "runtime/default"
14981507
}
1508+
builderContainerSecurityContext = restrictedSecurityContext.DeepCopy()
1509+
builderContainerSecurityContext.RunAsUser = pointer.Int64Ptr(1000)
1510+
builderContainerSecurityContext.RunAsGroup = pointer.Int64Ptr(1000)
14991511
}
15001512

15011513
// add build args to pass via --build-arg
@@ -1614,6 +1626,12 @@ echo "Done"
16141626
Containers: []corev1.Container{
16151627
container,
16161628
},
1629+
SecurityContext: &corev1.PodSecurityContext{
1630+
RunAsNonRoot: pointer.BoolPtr(true),
1631+
SeccompProfile: &corev1.SeccompProfile{
1632+
Type: corev1.SeccompProfileTypeRuntimeDefault,
1633+
},
1634+
},
16171635
},
16181636
}
16191637

helm/yatai-image-builder/values.yaml

+10-10
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ serviceAccount:
2727

2828
podAnnotations: {}
2929

30-
podSecurityContext: {}
31-
# fsGroup: 2000
30+
podSecurityContext:
31+
runAsNonRoot: true
32+
seccompProfile:
33+
type: RuntimeDefault
3234

33-
securityContext: {}
34-
# capabilities:
35-
# drop:
36-
# - ALL
37-
# readOnlyRootFilesystem: true
38-
# runAsNonRoot: true
39-
# runAsUser: 1000
35+
securityContext:
36+
allowPrivilegeEscalation: false
37+
capabilities:
38+
drop:
39+
- ALL
4040

4141
service:
4242
type: ClusterIP
@@ -96,7 +96,7 @@ aws:
9696
secretAccessKeyExistingSecretKey: ''
9797

9898
internalImages:
99-
bentoDownloader: quay.io/bentoml/bento-downloader:0.0.1
99+
bentoDownloader: quay.io/bentoml/bento-downloader:0.0.3
100100
kaniko: quay.io/bentoml/kaniko:1.9.1
101101
buildkit: quay.io/bentoml/buildkit:master
102102
buildkitRootless: quay.io/bentoml/buildkit:master-rootless

0 commit comments

Comments
 (0)