Skip to content

Commit 0e7cadb

Browse files
committed
C-WCOW: Differentiate container cmdline
Signed-off-by: Mahati Chamarthy <[email protected]>
1 parent f4d6807 commit 0e7cadb

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

internal/gcs-sidecar/handlers.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

internal/gcs-sidecar/host.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ type Host struct {
4242
}
4343

4444
type Container struct {
45-
id string
46-
spec specs.Spec
47-
processesMutex sync.Mutex
48-
processes map[uint32]*containerProcess
45+
id string
46+
spec specs.Spec
47+
processesMutex sync.Mutex
48+
processes map[uint32]*containerProcess
49+
commandLine bool
50+
commandLineExec bool
4951
}
5052

5153
// Process is a struct that defines the lifetime and operations associated with

0 commit comments

Comments
 (0)