@@ -330,20 +330,37 @@ func (r *KbsConfigReconciler) newKbsDeployment(ctx context.Context) *appsv1.Depl
330330 kbsDeploymentType = confidentialcontainersorgv1alpha1 .DeploymentTypeMicroservices
331331 }
332332
333- // RunAsUser (root) 0
334- runAsUser := int64 (0 )
335-
336333 var volumes []corev1.Volume
337334 var kbsVM []corev1.VolumeMount
338335 var asVM []corev1.VolumeMount
339336 var rvpsVM []corev1.VolumeMount
340337
338+ // The paths /opt/confidential-container and /opt/confidential-container/kbs/repository/default
339+ // are mounted as a RW volume in memory to allow trustee components
340+ // to have full access to the filesystem
341+ // confidential-containers
342+ volume , err := r .createConfidentialContainersVolume (confidentialContainers )
343+ if err != nil {
344+ return nil
345+ }
346+ volumes = append (volumes , * volume )
347+ volumeMount := createVolumeMount (volume .Name , filepath .Join (rootPath , volume .Name ))
348+ kbsVM = append (kbsVM , volumeMount )
349+ // default repo
350+ volume , err = r .createDefaultRepositoryVolume (defaultRepository )
351+ if err != nil {
352+ return nil
353+ }
354+ volumes = append (volumes , * volume )
355+ volumeMount = createVolumeMount (volume .Name , filepath .Join (repositoryPath , volume .Name ))
356+ kbsVM = append (kbsVM , volumeMount )
357+
341358 // kbs-config
342- volume , err : = r .createKbsConfigMapVolume (ctx , "kbs-config" )
359+ volume , err = r .createKbsConfigMapVolume (ctx , "kbs-config" )
343360 if err != nil {
344361 return nil
345362 }
346- volumeMount : = createVolumeMount (volume .Name , filepath .Join (kbsDefaultConfigPath , volume .Name ))
363+ volumeMount = createVolumeMount (volume .Name , filepath .Join (kbsDefaultConfigPath , volume .Name ))
347364 volumes = append (volumes , * volume )
348365 kbsVM = append (kbsVM , volumeMount )
349366
@@ -424,13 +441,14 @@ func (r *KbsConfigReconciler) newKbsDeployment(ctx context.Context) *appsv1.Depl
424441 rvpsVM = append (rvpsVM , volumeMount )
425442 }
426443
427- containers := []corev1.Container {r .buildKbsContainer (kbsVM , runAsUser )}
444+ securityContext := createSecurityContext ()
445+ containers := []corev1.Container {r .buildKbsContainer (kbsVM , securityContext )}
428446
429447 if kbsDeploymentType == confidentialcontainersorgv1alpha1 .DeploymentTypeMicroservices {
430448 // build AS container
431- containers = append (containers , r .buildAsContainer (asVM , runAsUser ))
449+ containers = append (containers , r .buildAsContainer (asVM , securityContext ))
432450 // build RVPS container
433- containers = append (containers , r .buildRvpsContainer (rvpsVM , runAsUser ))
451+ containers = append (containers , r .buildRvpsContainer (rvpsVM , securityContext ))
434452 }
435453
436454 // Create the deployment
@@ -464,7 +482,24 @@ func (r *KbsConfigReconciler) newKbsDeployment(ctx context.Context) *appsv1.Depl
464482 return deployment
465483}
466484
467- func (r * KbsConfigReconciler ) buildAsContainer (volumeMounts []corev1.VolumeMount , runAsUser int64 ) corev1.Container {
485+ func pointer [T any ](d T ) * T {
486+ return & d
487+ }
488+
489+ func createSecurityContext () * corev1.SecurityContext {
490+ return & corev1.SecurityContext {
491+ AllowPrivilegeEscalation : pointer (false ),
492+ Capabilities : & corev1.Capabilities {
493+ Drop : []corev1.Capability {
494+ "ALL" },
495+ },
496+ SeccompProfile : & corev1.SeccompProfile {
497+ Type : corev1 .SeccompProfileTypeRuntimeDefault ,
498+ },
499+ }
500+ }
501+
502+ func (r * KbsConfigReconciler ) buildAsContainer (volumeMounts []corev1.VolumeMount , securityContext * corev1.SecurityContext ) corev1.Container {
468503 asImageName := os .Getenv ("AS_IMAGE_NAME" )
469504 if asImageName == "" {
470505 asImageName = DefaultAsImageName
@@ -489,17 +524,14 @@ func (r *KbsConfigReconciler) buildAsContainer(volumeMounts []corev1.VolumeMount
489524 },
490525 },
491526 // Add command to start AS
492- Command : asCommand ,
493- // Add SecurityContext
494- SecurityContext : & corev1.SecurityContext {
495- RunAsUser : & runAsUser ,
496- },
527+ Command : asCommand ,
528+ SecurityContext : securityContext ,
497529 // Add volume mount for config
498530 VolumeMounts : volumeMounts ,
499531 }
500532}
501533
502- func (r * KbsConfigReconciler ) buildRvpsContainer (volumeMounts []corev1.VolumeMount , runAsUser int64 ) corev1.Container {
534+ func (r * KbsConfigReconciler ) buildRvpsContainer (volumeMounts []corev1.VolumeMount , securityContext * corev1. SecurityContext ) corev1.Container {
503535 rvpsImageName := os .Getenv ("RVPS_IMAGE_NAME" )
504536 if rvpsImageName == "" {
505537 rvpsImageName = DefaultRvpsImageName
@@ -522,17 +554,14 @@ func (r *KbsConfigReconciler) buildRvpsContainer(volumeMounts []corev1.VolumeMou
522554 },
523555 },
524556 // Add command to start RVPS
525- Command : rvpsCommand ,
526- // Add SecurityContext
527- SecurityContext : & corev1.SecurityContext {
528- RunAsUser : & runAsUser ,
529- },
557+ Command : rvpsCommand ,
558+ SecurityContext : securityContext ,
530559 // Add volume mount for config
531560 VolumeMounts : volumeMounts ,
532561 }
533562}
534563
535- func (r * KbsConfigReconciler ) buildKbsContainer (volumeMounts []corev1.VolumeMount , runAsUser int64 ) corev1.Container {
564+ func (r * KbsConfigReconciler ) buildKbsContainer (volumeMounts []corev1.VolumeMount , securityContext * corev1. SecurityContext ) corev1.Container {
536565 // Get Image Name from env variable if set
537566 imageName := os .Getenv ("KBS_IMAGE_NAME" )
538567 if imageName == "" {
@@ -556,11 +585,8 @@ func (r *KbsConfigReconciler) buildKbsContainer(volumeMounts []corev1.VolumeMoun
556585 },
557586 },
558587 // Add command to start KBS
559- Command : command ,
560- // Add SecurityContext
561- SecurityContext : & corev1.SecurityContext {
562- RunAsUser : & runAsUser ,
563- },
588+ Command : command ,
589+ SecurityContext : securityContext ,
564590 // Add volume mount for KBS config
565591 VolumeMounts : volumeMounts ,
566592 /* TODO commented out because not configurable yet
0 commit comments