@@ -91,11 +91,15 @@ func (b *Bridge) createContainer(req *request) (err error) {
9191 if err := b .hostState .SetupSecurityContextDir (ctx , & spec ); err != nil {
9292 return err
9393 }
94+ commandLine := len (spec .Process .Args ) > 0
9495 c := & Container {
95- id : containerID ,
96- spec : spec ,
97- processes : make (map [uint32 ]* containerProcess ),
96+ id : containerID ,
97+ spec : spec ,
98+ processes : make (map [uint32 ]* containerProcess ),
99+ commandLine : commandLine ,
100+ commandLineExec : false ,
98101 }
102+
99103 log .G (ctx ).Tracef ("Adding ContainerID: %v" , containerID )
100104 if err := b .hostState .AddContainer (req .ctx , containerID , c ); err != nil {
101105 log .G (ctx ).Tracef ("Container exists in the map." )
@@ -272,15 +276,19 @@ func (b *Bridge) executeProcess(req *request) (err error) {
272276 return fmt .Errorf ("failed to get created container: %w" , err )
273277 }
274278
275- // if this is an exec of Container command line, then it's already enforced
276- // during container creation, hence skip it here
277- containerCommandLine := escapeArgs (c .spec .Process .Args )
278- if processParams .CommandLine != containerCommandLine {
279+ c .processesMutex .Lock ()
280+ isInitExec := c .commandLine && ! c .commandLineExec
281+ if isInitExec {
282+ // if this is an exec of Container command line, then it's already enforced
283+ // during container creation, hence skip it here
284+ c .commandLineExec = true
279285
286+ }
287+ c .processesMutex .Unlock ()
288+ if ! isInitExec {
280289 user := securitypolicy.IDName {
281290 Name : processParams .User ,
282291 }
283-
284292 log .G (req .ctx ).Tracef ("Enforcing policy on exec in container" )
285293 _ , _ , _ , err = b .hostState .securityPolicyEnforcer .
286294 EnforceExecInContainerPolicyV2 (
@@ -298,7 +306,7 @@ func (b *Bridge) executeProcess(req *request) (err error) {
298306 }
299307 headerID := req .header .ID
300308
301- // initiate process ID
309+ // initiate exec process response channel
302310 procRespCh := make (chan * prot.ContainerExecuteProcessResponse , 1 )
303311 b .pendingMu .Lock ()
304312 b .pending [headerID ] = procRespCh
0 commit comments