@@ -15,6 +15,7 @@ import (
1515 "path"
1616 "path/filepath"
1717 "regexp"
18+ "slices"
1819 "strings"
1920 "sync"
2021 "sync/atomic"
@@ -448,6 +449,18 @@ func (h *Host) CreateContainer(ctx context.Context, id string, settings *prot.VM
448449 }
449450 }
450451
452+ // Take a backup of the devices array before we populate it with any devices
453+ // found by GCS, in order to pass to the policy enforcer later.
454+ //
455+ // In specGuest.ApplyAnnotationsToSpec, if this is a privileged container,
456+ // we will add devices found in the GCS namespace's /dev. Regardless of
457+ // privileged or not, we also always include /dev/sev-guest. Since the
458+ // policy already lets the user enforce whether the container should be
459+ // privileged or not, and the sev-guest device is always added for a
460+ // confidential container, we do not need the policy enforcer to check these
461+ // devices we dynamically add again.
462+ extraLinuxDevices := slices .Clone (settings .OCISpecification .Linux .Devices )
463+
451464 // Normally we would be doing policy checking here at the start of our
452465 // "policy gated function". However, we can't for create container as we
453466 // need a properly correct sandboxID which might be changed by the code
@@ -583,21 +596,27 @@ func (h *Host) CreateContainer(ctx context.Context, id string, settings *prot.VM
583596 return nil , err
584597 }
585598
586- envToKeep , capsToKeep , allowStdio , err := h .securityOptions .PolicyEnforcer .EnforceCreateContainerPolicy (
599+ privileged := isPrivilegedContainerCreationRequest (ctx , settings .OCISpecification )
600+ noNewPrivileges := settings .OCISpecification .Process .NoNewPrivileges
601+ opts := & securitypolicy.CreateContainerOptions {
602+ SandboxID : sandboxID ,
603+ Privileged : & privileged ,
604+ NoNewPrivileges : & noNewPrivileges ,
605+ Groups : groups ,
606+ Umask : umask ,
607+ Capabilities : settings .OCISpecification .Process .Capabilities ,
608+ SeccompProfileSHA256 : seccomp ,
609+ LinuxDevices : extraLinuxDevices ,
610+ }
611+ envToKeep , capsToKeep , allowStdio , err := h .securityOptions .PolicyEnforcer .EnforceCreateContainerPolicyV2 (
587612 ctx ,
588- sandboxID ,
589613 id ,
590614 settings .OCISpecification .Process .Args ,
591615 settings .OCISpecification .Process .Env ,
592616 settings .OCISpecification .Process .Cwd ,
593617 settings .OCISpecification .Mounts ,
594- isPrivilegedContainerCreationRequest (ctx , settings .OCISpecification ),
595- settings .OCISpecification .Process .NoNewPrivileges ,
596618 user ,
597- groups ,
598- umask ,
599- settings .OCISpecification .Process .Capabilities ,
600- seccomp ,
619+ opts ,
601620 )
602621 if err != nil {
603622 return nil , errors .Wrapf (err , "container creation denied due to policy" )
0 commit comments