Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions pkg/runtime/apple_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ import (
"context"
"encoding/json"
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"time"

Expand Down Expand Up @@ -48,11 +46,14 @@ func (r *AppleContainerRuntime) ExecUser() string {

func (r *AppleContainerRuntime) Run(ctx context.Context, config RunConfig) (string, error) {
// Stage file, variable, and secret-map secrets before building args
var secretMountSpecs []string
if config.HomeDir != "" && len(config.ResolvedSecrets) > 0 {
containerHome := util.GetHomeDir(config.UnixUsername)
if _, err := writeFileSecrets(config.HomeDir, containerHome, config.ResolvedSecrets); err != nil {
mounts, err := writeFileSecrets(config.HomeDir, containerHome, config.ResolvedSecrets)
if err != nil {
return "", fmt.Errorf("failed to stage file secrets: %w", err)
}
secretMountSpecs = mounts
if err := writeVariableSecrets(config.HomeDir, config.ResolvedSecrets); err != nil {
return "", fmt.Errorf("failed to write variable secrets: %w", err)
}
Expand All @@ -66,6 +67,10 @@ func (r *AppleContainerRuntime) Run(ctx context.Context, config RunConfig) (stri
config.Env = append(config.Env, telemetryGCPCredentialsEnvVar+"="+credPath)
}

// 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.


args, err := buildCommonRunArgs(config)
if err != nil {
return "", err
Expand Down Expand Up @@ -109,13 +114,10 @@ func (r *AppleContainerRuntime) Run(ctx context.Context, config RunConfig) (stri
// Skip the original 'run', '-d', and '-i' from buildCommonRunArgs (indices 0, 1, 2)
newArgs = append(newArgs, args[3:]...)

// Insert secrets staging directory volume before the image so it is treated
// as a container flag rather than an argument to the container command.
if config.HomeDir != "" && len(config.ResolvedSecrets) > 0 {
secretsDir := filepath.Join(filepath.Dir(config.HomeDir), "secrets")
if _, err := os.Stat(secretsDir); err == nil {
newArgs = insertVolumeFlags(newArgs, config.Image, []string{secretsDir + ":/run/scion-secrets:ro"})
}
// Insert file secret bind-mounts before the image so they are treated as
// container flags rather than arguments to the container command.
if len(secretMountSpecs) > 0 {
newArgs = insertVolumeFlags(newArgs, config.Image, secretMountSpecs)
}

WriteRuntimeDebugFile(config, r.Command, newArgs)
Expand Down