Skip to content

Commit 9226069

Browse files
Mossakaclaude
andcommitted
fix: address review feedback on host.docker.internal propagation
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 6b3ba11 commit 9226069

3 files changed

Lines changed: 48 additions & 4 deletions

File tree

containers/agent/docker-stub.sh

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,50 @@ fi
3737

3838
AGENT_CONTAINER="${AWF_AGENT_CONTAINER:-awf-agent}"
3939

40-
# Get the subcommand (first non-flag argument)
40+
# Known Docker subcommands that we need to intercept or handle.
41+
# Used by get_subcommand() to avoid misidentifying Docker global option
42+
# values as subcommands (e.g., `docker --context foo run` where `foo` is
43+
# a value for --context, not a subcommand).
44+
KNOWN_SUBCOMMANDS="run create exec build pull push images ps logs stop start rm rmi network compose volume inspect cp tag login logout info version"
45+
46+
# Get the Docker subcommand, skipping global options and their values.
47+
# Docker global options that take a value (e.g., --context <name>, --host <url>)
48+
# would cause a naive "first non-flag token" parser to misidentify the value
49+
# as the subcommand. Instead, we check each non-flag token against known
50+
# Docker subcommands.
4151
get_subcommand() {
52+
local skip_next=false
4253
for arg in "$@"; do
54+
if [ "$skip_next" = true ]; then
55+
skip_next=false
56+
continue
57+
fi
4358
case "$arg" in
44-
-*) continue ;;
45-
*) echo "$arg"; return ;;
59+
# Docker global options that take a separate value argument
60+
--config|--context|-c|--host|-H|--log-level|-l)
61+
skip_next=true
62+
continue
63+
;;
64+
# Docker global options with value in same token (--context=foo)
65+
--config=*|--context=*|--host=*|--log-level=*)
66+
continue
67+
;;
68+
# Other flags (boolean flags like --debug, --tls, etc.)
69+
-*)
70+
continue
71+
;;
72+
*)
73+
# Check if this token is a known Docker subcommand
74+
for cmd in $KNOWN_SUBCOMMANDS; do
75+
if [ "$arg" = "$cmd" ]; then
76+
echo "$arg"
77+
return
78+
fi
79+
done
80+
# Unknown token before a known subcommand — skip it
81+
# (could be an unrecognized global option value)
82+
continue
83+
;;
4684
esac
4785
done
4886
}
@@ -103,6 +141,7 @@ case "$SUBCOMMAND" in
103141
# Propagate host.docker.internal DNS to child containers when host access is enabled.
104142
# The agent container gets this via Docker's extra_hosts in docker-compose.yml,
105143
# but child containers spawned via 'docker run' don't inherit it automatically.
144+
# Note: docker-manager.ts sets AWF_ENABLE_HOST_ACCESS='1' (not 'true').
106145
if [ "${AWF_ENABLE_HOST_ACCESS:-}" = "1" ]; then
107146
INJECT_FLAGS+=("--add-host" "host.docker.internal:host-gateway")
108147
fi

containers/agent/entrypoint.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ set -e
33

44
# SECURITY: Lock down AWF control variables to prevent tampering by user code.
55
# These are set by the Docker Compose environment and must not be modified.
6+
# Note: `readonly` is a best-effort defense — it only prevents modification within
7+
# this shell's execution path. Subshells and child processes get their own copies
8+
# of exported variables and can modify them freely. The real enforcement is the
9+
# docker-stub.sh wrapper, which intercepts `docker run/create` and injects the
10+
# correct flags based on the original value set here.
611
readonly AWF_ENABLE_HOST_ACCESS="${AWF_ENABLE_HOST_ACCESS:-}"
712
export AWF_ENABLE_HOST_ACCESS
813

src/docker-manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ export function generateDockerCompose(
755755
// Ensure host access is enabled (setup-iptables.sh requires AWF_ENABLE_HOST_ACCESS)
756756
// The CLI auto-enables this, but this is a safety net for programmatic usage
757757
if (!environment.AWF_ENABLE_HOST_ACCESS) {
758-
environment.AWF_ENABLE_HOST_ACCESS = 'true';
758+
environment.AWF_ENABLE_HOST_ACCESS = '1';
759759
}
760760
}
761761

0 commit comments

Comments
 (0)