@@ -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
0 commit comments