@@ -1200,6 +1200,17 @@ echo "Done"
1200
1200
})
1201
1201
}
1202
1202
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
+
1203
1214
initContainers := []corev1.Container {
1204
1215
{
1205
1216
Name : "bento-downloader" ,
@@ -1209,9 +1220,10 @@ echo "Done"
1209
1220
"-c" ,
1210
1221
bentoDownloadCommand ,
1211
1222
},
1212
- VolumeMounts : volumeMounts ,
1213
- Resources : downloaderContainerResources ,
1214
- EnvFrom : downloaderContainerEnvFrom ,
1223
+ VolumeMounts : volumeMounts ,
1224
+ Resources : downloaderContainerResources ,
1225
+ EnvFrom : downloaderContainerEnvFrom ,
1226
+ SecurityContext : restrictedSecurityContext ,
1215
1227
},
1216
1228
}
1217
1229
@@ -1329,9 +1341,10 @@ echo "Done"
1329
1341
"-c" ,
1330
1342
modelDownloadCommand ,
1331
1343
},
1332
- VolumeMounts : volumeMounts ,
1333
- Resources : downloaderContainerResources ,
1334
- EnvFrom : downloaderContainerEnvFrom ,
1344
+ VolumeMounts : volumeMounts ,
1345
+ Resources : downloaderContainerResources ,
1346
+ EnvFrom : downloaderContainerEnvFrom ,
1347
+ SecurityContext : restrictedSecurityContext ,
1335
1348
})
1336
1349
}
1337
1350
@@ -1488,14 +1501,13 @@ echo "Done"
1488
1501
Privileged : pointer .BoolPtr (true ),
1489
1502
}
1490
1503
} 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"
1498
1507
}
1508
+ builderContainerSecurityContext = restrictedSecurityContext .DeepCopy ()
1509
+ builderContainerSecurityContext .RunAsUser = pointer .Int64Ptr (1000 )
1510
+ builderContainerSecurityContext .RunAsGroup = pointer .Int64Ptr (1000 )
1499
1511
}
1500
1512
1501
1513
// add build args to pass via --build-arg
@@ -1614,6 +1626,12 @@ echo "Done"
1614
1626
Containers : []corev1.Container {
1615
1627
container ,
1616
1628
},
1629
+ SecurityContext : & corev1.PodSecurityContext {
1630
+ RunAsNonRoot : pointer .BoolPtr (true ),
1631
+ SeccompProfile : & corev1.SeccompProfile {
1632
+ Type : corev1 .SeccompProfileTypeRuntimeDefault ,
1633
+ },
1634
+ },
1617
1635
},
1618
1636
}
1619
1637
0 commit comments