Skip to content

WCOW: support RUN --mount=type=secret - #6944

Open
rzlink wants to merge 1 commit into
moby:masterfrom
rzlink:wcow-secret-mount
Open

WCOW: support RUN --mount=type=secret#6944
rzlink wants to merge 1 commit into
moby:masterfrom
rzlink:wcow-secret-mount

Conversation

@rzlink

@rzlink rzlink commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

This enables RUN --mount=type=secret for Windows containers (WCOW). Previously the build failed with invalid windows mount type: 'tmpfs', because the secret mount was always set up as a Linux tmpfs, which the Windows containerd mount layer rejects.

Since Windows has no tmpfs, the secret is written to a temporary file on the host and exposed to the build step as a read-only, single-file bind mount (via the HCS bind filter). Access is restricted with an explicit protected DACL that grants only SYSTEM, Administrators, and the build's own user account, which is the Windows analog of the 0600 permissions used on Linux.

Some Linux-only behaviors do not apply on Windows: a target must be given explicitly (there is no /run/secrets default), and the uid/gid/mode options are ignored. After the mount is released, an empty placeholder directory may remain at the target; the secret value itself is not persisted into the image layer.

fixes #5273
relates to #5678

@rzlink
rzlink force-pushed the wcow-secret-mount branch from f424e8c to 1ac8a2b Compare July 9, 2026 17:34
@rzlink rzlink changed the title windows: support RUN --mount=type=secret WCOW: support RUN --mount=type=secret Jul 9, 2026

@tonistiigi tonistiigi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

CI errors look related

@rzlink
rzlink force-pushed the wcow-secret-mount branch from 1ac8a2b to d6c0abb Compare July 13, 2026 21:17
@rzlink
rzlink requested a review from tonistiigi July 13, 2026 22:22
@rzlink

rzlink commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator Author

CI errors look related

Thanks for the review! The failing checks were caused by two existing Windows dockerfile tests ( TestOutlineSecrets ,  TestSecretRequiredWithoutValue ) that used targetless secrets — which the new Windows code path now rejects, since a  target  is required on Windows (there's no  /run/secrets  default). I've updated those tests to pass explicit targets.

All checks are green now. PTAL when you get a chance.

@tonistiigi
tonistiigi requested a review from crazy-max July 22, 2026 15:35
@rzlink

rzlink commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator Author

@crazy-max Could you please take a look at this PR when you have some time? Thanks!

@crazy-max crazy-max left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you also rebase with master to make sure Go 1.26 bump in go.mod doesn't introduce lint issue? Thanks

Comment on lines +16 to +19
if isWindows {
// Normalize backslashes so C:\path\to\secret resolves to an absolute path.
m.Target = system.ToSlash(m.Target, "windows")
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would prefer to avoid mutating m.Target:

Suggested change
if isWindows {
// Normalize backslashes so C:\path\to\secret resolves to an absolute path.
m.Target = system.ToSlash(m.Target, "windows")
}
targetPath := m.Target
if isWindows {
targetPath = system.ToSlash(targetPath, "windows")
}

@crazy-max crazy-max added this to the v0.33.0 milestone Jul 27, 2026
@rzlink
rzlink force-pushed the wcow-secret-mount branch from d6c0abb to 31d5496 Compare July 27, 2026 23:35
Secret mounts previously failed on Windows with invalid windows mount type: 'tmpfs' because the secret mount setup hardcoded a tmpfs scratch dir, which the Windows containerd mount layer rejects (only 'windows-layer' is allowed).

Split secretMountInstance.Mount() into platform files. The Unix path is unchanged. The Windows path writes the secret to a temp file and returns a single-file, read-only bind mount (no tmpfs), and applies a protected DACL granting access only to SYSTEM, Administrators and the daemon account - the Windows analog of the Unix chmod(0600).

The dockerfile frontend now requires an explicit target on Windows, as there is no POSIX-style /run/secrets default. UID/GID/mode are unsupported on Windows and ignored.

Adds unit and integration tests and documents the Windows behavior in the Dockerfile reference.

Signed-off-by: Dawei Wei <wei.dawei.cn@gmail.com>
@rzlink
rzlink force-pushed the wcow-secret-mount branch from 31d5496 to 752906f Compare July 28, 2026 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows docker container buildctl does not allow mounting secrets. It fails mounting to linux tmpfs location

3 participants