@@ -84,7 +84,6 @@ func (b *Bridge) createContainer(req *request) (err error) {
8484 user := securitypolicy.IDName {
8585 Name : spec .Process .User .Username ,
8686 }
87- log .G (ctx ).Tracef ("user test: %v" , user )
8887 _ , _ , _ , err := b .hostState .securityPolicyEnforcer .EnforceCreateContainerPolicyV2 (req .ctx , containerID , spec .Process .Args , spec .Process .Env , spec .Process .Cwd , spec .Mounts , user , nil )
8988
9089 if err != nil {
@@ -97,11 +96,12 @@ func (b *Bridge) createContainer(req *request) (err error) {
9796 }
9897 log .G (ctx ).Tracef ("Adding ContainerID: %v" , containerID )
9998 if err := b .hostState .AddContainer (req .ctx , containerID , c ); err != nil {
100- log .G (ctx ).Tracef ("Container exists in the map!" )
99+ log .G (ctx ).Tracef ("Container exists in the map." )
100+ return err
101101 }
102102 defer func (err error ) {
103103 if err != nil {
104- b .hostState .RemoveContainer (containerID )
104+ b .hostState .RemoveContainer (ctx , containerID )
105105 }
106106 }(err )
107107 // Write security policy, signed UVM reference and host AMD certificate to
@@ -242,9 +242,6 @@ func (b *Bridge) shutdownGraceful(req *request) (err error) {
242242 return fmt .Errorf ("failed to unmarshal shutdownGraceful: %w" , err )
243243 }
244244
245- // TODO (kiashok/Mahati): Since gcs-sidecar can be used for all types of windows
246- // containers, it is important to check if we want to
247- // enforce policy or not.
248245 err = b .hostState .securityPolicyEnforcer .EnforceShutdownContainerPolicy (req .ctx , r .ContainerID )
249246 if err != nil {
250247 return fmt .Errorf ("rpcShudownGraceful operation not allowed: %w" , err )
@@ -313,7 +310,7 @@ func (b *Bridge) executeProcess(req *request) (err error) {
313310 c , err := b .hostState .GetCreatedContainer (req .ctx , containerID )
314311 if err != nil {
315312 log .G (req .ctx ).Tracef ("Container not found during exec: %v" , containerID )
316- return errors . Wrapf ( err , "containerID doesn't exist" )
313+ return fmt . Errorf ( "failed to get created container: %w" , err )
317314 }
318315
319316 // if this is an exec of Container command line, then it's already enforced
@@ -420,7 +417,7 @@ func (b *Bridge) signalProcess(req *request) (err error) {
420417 containerID := r .ContainerID
421418 c , err := b .hostState .GetCreatedContainer (req .ctx , containerID )
422419 if err != nil {
423- return err
420+ return fmt . Errorf ( "failed to get created container: %w" , err )
424421 }
425422
426423 p , err := c .GetProcess (r .ProcessID )
@@ -515,15 +512,13 @@ func (b *Bridge) deleteContainerState(req *request) (err error) {
515512 if err := commonutils .UnmarshalJSONWithHresult (req .message , & r ); err != nil {
516513 return fmt .Errorf ("failed to unmarshal deleteContainerState: %w" , err )
517514 }
518-
519- //TODO (Mahati): Remove container state locally before passing it to inbox-gcs
520- /*
521- c, err := b.hostState.GetCreatedContainer(request.ContainerID)
522- if err != nil {
523- return nil, err
524- }
525- // remove container state regardless of delete's success
526- defer b.hostState.RemoveContainer(request.ContainerID)*/
515+ _ , err = b .hostState .GetCreatedContainer (req .ctx , r .ContainerID )
516+ if err != nil {
517+ log .G (req .ctx ).Tracef ("Container not found during deleteContainerState: %v" , r .ContainerID )
518+ return fmt .Errorf ("container not found: %w" , err )
519+ }
520+ // remove container state regardless of delete's success
521+ defer b .hostState .RemoveContainer (req .ctx , r .ContainerID )
527522
528523 b .forwardRequestToGcs (req )
529524 return nil
0 commit comments