Skip to content

MappedDirectory enforcement and misc fixes#2727

Draft
MahatiC wants to merge 2 commits into
microsoft:mainfrom
MahatiC:enforce-readonly-mount
Draft

MappedDirectory enforcement and misc fixes#2727
MahatiC wants to merge 2 commits into
microsoft:mainfrom
MahatiC:enforce-readonly-mount

Conversation

@MahatiC
Copy link
Copy Markdown
Member

@MahatiC MahatiC commented May 7, 2026

Commit 1: CWCOW: Filter environment variable

The GCS sidecar was evaluating security policy for environment variables but discarding the filtered result. This meant policy could block containers with disallowed env vars, but couldn't selectively strip individual variables. This commit captures the filtered env list and rewrites the request with it before forwarding to GCS.

Commit 2: CWCOW: Enforce MappedDirectory inside gcs-sidecar

The GCS sidecar had no enforcement for ResourceTypeMappedDirectory (VSMB shares) or path validation for ResourceTypeMappedVirtualDisk/ResourceTypeMappedVirtualDiskForContainerScratch (SCSI mounts). This would allow an untrusted host to share arbitrary directories into the UVM without policy checks. This commit adds:

  • EnforceMappedDirectoryMountPolicy -- validates the
    read-only invariant inside the UVM and prevents duplicate mounts at the same container path. Path pattern validation ensures SCSI mounts only target c:\mounts\scsi\m
  • Path pattern validation for SCSI mounts -- ensures ContainerPath matches c:\mounts\scsi\m
  • New mapped_directory_mount / mapped_directory_unmount Rego enforcement points with error reporting

MahatiC added 2 commits May 7, 2026 22:06
Capture and apply envToKeep from policy enforcement in createContainer,
external exec, and in-container exec. Previously the filtered env list
was discarded.

Add ociEnvToProcessParamEnv and rewriteExecRequest helpers with tests.

Signed-off-by: Mahati Chamarthy <mahati.chamarthy@gmail.com>
Add EnforceMappedDirectoryMountPolicy/UnmountPolicy to enforce VSMB
directory shares for confidential Windows containers. Writable mapped
directories are denied; duplicates at the same container path are
prevented. Also add path pattern validation for MappedVirtualDisk
and MappedVirtualDiskForContainerScratch to ensure SCSI mounts only
target c:\mounts\scsi\m<N>.

Signed-off-by: Mahati Chamarthy <mahati.chamarthy@gmail.com>
if envToKeep != nil {
spec.Process.Env = []string(envToKeep)
}
_ = allowStdio // TODO: enforce stdio access for Windows containers
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.

Is there no enforcement on stdout in WCOW yet?

// Tests for environment variable filtering helpers (envlist persistence)

func TestOciEnvToProcessParamEnv_Basic(t *testing.T) {
input := []string{"FOO=bar", "PATH=/usr/bin", "EMPTY="}
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.

/usr/bin might not be the most obvious choice for a Windows test.

load_fragment := data.framework.load_fragment
scratch_mount := data.framework.scratch_mount
scratch_unmount := data.framework.scratch_unmount
mapped_directory_mount := data.framework.mapped_directory_mount
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.

Does the tooling need to be updated to match?

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.

2 participants