Skip to content

C-WCOW: SecurityPolicy implementation and tests - #2508

Merged
ambarve merged 9 commits into
microsoft:mainfrom
MahatiC:rebased-securitypolicy-tests
Sep 19, 2025
Merged

C-WCOW: SecurityPolicy implementation and tests#2508
ambarve merged 9 commits into
microsoft:mainfrom
MahatiC:rebased-securitypolicy-tests

Conversation

@MahatiC

@MahatiC MahatiC commented Aug 28, 2025

Copy link
Copy Markdown
Member

Comment thread internal/uvm/security_policy.go Outdated
@MahatiC
MahatiC force-pushed the rebased-securitypolicy-tests branch 10 times, most recently from e9c8277 to 3995b88 Compare September 4, 2025 16:05
@MahatiC
MahatiC marked this pull request as ready for review September 9, 2025 14:59
@MahatiC
MahatiC requested a review from a team as a code owner September 9, 2025 14:59
Comment thread internal/hcsoci/create.go Outdated
Comment thread internal/uvm/types.go Outdated
Comment thread pkg/securitypolicy/securitypolicyenforcer.go Outdated
Comment thread cmd/gcs-sidecar/main.go Outdated
Comment thread pkg/securitypolicy/securitypolicyenforcer.go Outdated
Comment thread internal/protocol/guestresource/resources.go
Comment thread internal/gcs-sidecar/host.go

// GetProcess returns the Process with the matching 'pid'. If the 'pid' does
// not exit returns error.
func (c *Container) GetProcess(pid uint32) (*containerProcess, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be moved to a new file named container.go?

Please move this method along with the declaration of container struct to that file. There should be a clear boundary between host methods vs container methods.


if containerID == UVMContainerID {
log.G(req.ctx).Tracef("Enforcing policy on external exec process")
_, _, err := b.hostState.securityPolicyEnforcer.EnforceExecExternalProcessPolicy(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need User validation in this enforcement point?

// if this is an exec of Container command line, then it's already enforced
// during container creation, hence skip it here
containerCommandLine := escapeArgs(c.spec.Process.Args)
if processParams.CommandLine != containerCommandLine {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If another exec is made by the user with same command args as the original container, then this will not be enforced. Maybe we enforce all the exec including the container init exec.

b.forwardRequestToGcs(req)

// fetch the process ID from response
deadline := time.Now().Add(5 * time.Second)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Please declare the timeout at the beginning of the file so that we have a unified way for all the important constants.

_ = sendWithContextCancel(ctx, sidecarErrChan, recverr)
return
}
// If this is a ContainerExecuteProcessResponse, notify

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of this approach, we can use channels for capturing the process response.
Approach would be-

  • Create a channel on which you write the response to when the same is received in ListenAndServeShimRequests method.
  • Same channel is used in executeProcess method. We listens on the channel with a deadline of 5 seconds. If you don't hear back then return an error message. If we hear back about another exec then we skip and keep waiting for next response.

With this approach, you won't need- b.pending, b.pendingMu and other polling logic.

}
headerID := req.header.ID

// initiate process ID

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use channels instead of this logic. Please refer to earlier comment.

Comment thread internal/gcs-sidecar/handlers.go
Comment thread internal/gcs-sidecar/handlers.go
Comment thread internal/regopolicyinterpreter/regopolicyinterpreter.go
Comment thread pkg/annotations/annotations.go
@MahatiC
MahatiC force-pushed the rebased-securitypolicy-tests branch from 887b690 to d0815d2 Compare September 15, 2025 14:13
Signed-off-by: Mahati Chamarthy <mahati.chamarthy@gmail.com>
Signed-off-by: Mahati Chamarthy <mahati.chamarthy@gmail.com>
Signed-off-by: Mahati Chamarthy <mahati.chamarthy@gmail.com>
Signed-off-by: Mahati Chamarthy <mahati.chamarthy@gmail.com>
Signed-off-by: Mahati Chamarthy <mahati.chamarthy@gmail.com>
Signed-off-by: Mahati Chamarthy <mahati.chamarthy@gmail.com>
Signed-off-by: Mahati Chamarthy <mahati.chamarthy@gmail.com>
@MahatiC
MahatiC force-pushed the rebased-securitypolicy-tests branch from d0815d2 to d744385 Compare September 18, 2025 12:32
Signed-off-by: Mahati Chamarthy <mahati.chamarthy@gmail.com>
@MahatiC
MahatiC force-pushed the rebased-securitypolicy-tests branch 2 times, most recently from 3098d26 to 9d6b64d Compare September 18, 2025 14:43
@MahatiC
MahatiC force-pushed the rebased-securitypolicy-tests branch from 9d6b64d to 9ef1de2 Compare September 18, 2025 15:07
Signed-off-by: Mahati Chamarthy <mahati.chamarthy@gmail.com>
@MahatiC
MahatiC force-pushed the rebased-securitypolicy-tests branch from 9ef1de2 to 24fcf74 Compare September 18, 2025 15:21

@KenGordon KenGordon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed. Merge now (but do not delete the PR) and add some issues for the coding/style/refactoring that will be needed afterwards but which is not critical path for the demo and enabling others to get on with their work.

SeccompProfileSHA256 string `json:"-"`
}

type WindowsContainer struct {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these various windows versions of pre-existing types be made common, either by using the go interface scheme (or whatever is appropriate - I can't claim to be a golang guru) or by just using the same objects but not filling out the parts that don't apply to the given platform?

@ambarve
ambarve merged commit 0fc5d6e into microsoft:main Sep 19, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants