Skip to content

fix(runtime): bind-mount file secrets to target paths in Apple container runtime#172

Open
ryancee wants to merge 2 commits into
GoogleCloudPlatform:mainfrom
ryancee:fix/apple-runtime-file-secret-mounts
Open

fix(runtime): bind-mount file secrets to target paths in Apple container runtime#172
ryancee wants to merge 2 commits into
GoogleCloudPlatform:mainfrom
ryancee:fix/apple-runtime-file-secret-mounts

Conversation

@ryancee
Copy link
Copy Markdown

@ryancee ryancee commented Apr 19, 2026

Problem

The Apple container runtime was staging file secrets on the host via writeFileSecrets() but discarding the returned mount specs. Instead of bind-mounting each secret to its intended container target path, it was mounting the entire secrets staging directory at /run/scion-secrets:ro.

This meant a secret like OPENCODE_AUTH (target: ~/.local/share/opencode/auth.json) would land at /run/scion-secrets/OPENCODE_AUTH inside the container but not at its actual target path, so any harness relying on the file would silently fail to find it.

Fix

Capture the []string mount specs returned by writeFileSecrets() and pass them to insertVolumeFlags(), so each file secret is bind-mounted directly to its container target path. This mirrors how DockerRuntime.Run() already handles file secrets.

Also disables MetadataInterception for the Apple runtime since it does not support --cap-add NET_ADMIN (required by the iptables-based GCE metadata blocking approach).

Testing

Manually verified on macOS with the Apple Virtualization Framework (container CLI) runtime: OPENCODE_AUTH file secret is now correctly projected to ~/.local/share/opencode/auth.json inside the container.

…ner runtime

The Apple runtime was staging file secrets on the host but only mounting
the entire secrets directory at /run/scion-secrets:ro, instead of
bind-mounting each secret to its intended container target path.

This mirrors how the Docker runtime handles file secrets: capture the
mount specs returned by writeFileSecrets() and pass them to
insertVolumeFlags(), so each secret (e.g. OPENCODE_AUTH) lands at its
correct path inside the container (e.g. ~/.local/share/opencode/auth.json).

Also disables MetadataInterception for Apple runtime since it does not
support --cap-add NET_ADMIN required by the iptables-based GCE metadata
blocking approach.
@google-cla
Copy link
Copy Markdown

google-cla Bot commented Apr 19, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors secret mounting in the Apple container runtime by utilizing mount specifications returned from writeFileSecrets and removes unused imports. It also disables metadata interception to avoid unsupported Linux capabilities. Feedback suggests that while the code comments mention a reliance on the GCE_METADATA_HOST environment variable for metadata interception, the implementation fails to actually set this variable in the configuration.

Comment thread pkg/runtime/apple_container.go Outdated
Comment on lines +70 to +72
// Apple container runtime does not support Linux capabilities (--cap-add).
// Metadata interception relies on GCE_METADATA_HOST env var instead of iptables.
config.MetadataInterception = false
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.

medium

The comment mentions that metadata interception relies on the GCE_METADATA_HOST environment variable instead of iptables. However, the code only disables MetadataInterception (to avoid the unsupported --cap-add NET_ADMIN flag) but does not appear to set the GCE_METADATA_HOST variable. If the runtime is expected to provide this alternative interception mechanism, consider injecting the environment variable into config.Env here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch. GCE_METADATA_HOST and GCE_METADATA_ROOT are already injected into the agent env by the broker (runtimebroker/start_context.go) when in assign/block metadata modes — no need to set them here. The original comment was just misleading. Updated it in 68a1bfc to accurately describe the trade-off: iptables interception is unavailable on Apple, so only apps honouring the standard env vars will reach the scion metadata server; apps that hardcode metadata.google.internal won't be intercepted.

The original comment incorrectly implied that GCE_METADATA_HOST was being
set here as an alternative to iptables interception. In fact GCE_METADATA_HOST
and GCE_METADATA_ROOT are already injected into the agent env by the broker
(start_context.go) for assign/block metadata modes. The comment now accurately
describes the trade-off: iptables interception is unavailable on Apple, so only
apps that honour the standard env vars will reach the scion metadata server.
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.

1 participant