Skip to content

Commit f7361c5

Browse files
lpcoxCopilotCopilot
authored
fix: copy AWF CA cert to chroot-accessible path for ssl-bump (#1555)
* fix: copy AWF CA cert to chroot-accessible path for ssl-bump When ssl-bump and chroot are both active, NODE_EXTRA_CA_CERTS points to /usr/local/share/ca-certificates/awf-ca.crt which is a Docker volume mount on the container's overlay filesystem. After chroot /host, this path is inaccessible, causing TLS failures (transaction-end-before-headers in Squid, EHOSTUNREACH in Claude Code after 10 retries). Fix: copy the CA cert to /host/tmp/awf-lib/awf-ca.crt before chroot activates (same pattern as one-shot-token.so and get-claude-key.sh), then update NODE_EXTRA_CA_CERTS to the chroot-relative path. Also set SSL_CERT_FILE and REQUESTS_CA_BUNDLE so non-Node.js tools (curl, git, Python requests, Ruby) trust the AWF CA in both chroot and non-chroot ssl-bump modes. Cleanup is handled by the existing /tmp/awf-lib removal in the EXIT trap. Fixes #1546 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Update containers/agent/entrypoint.sh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix: address PR review feedback on ssl-bump chroot CA - Verify destination file exists after copy ([ -f ] check) - Log warning when mkdir /host/tmp/awf-lib fails - Include CHROOT_KEY_HELPER in cleanup condition to prevent /tmp/awf-lib leak when only key helper was copied Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 43870f7 commit f7361c5

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

containers/agent/entrypoint.sh

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,14 @@ if [ "${AWF_SSL_BUMP_ENABLED}" = "true" ]; then
107107
echo "[entrypoint] SSL Bump mode detected - updating CA certificates..."
108108
if [ -f /usr/local/share/ca-certificates/awf-ca.crt ]; then
109109
update-ca-certificates 2>/dev/null
110+
AWF_CA_PATH="/usr/local/share/ca-certificates/awf-ca.crt"
110111
# Set NODE_EXTRA_CA_CERTS so Node.js tools (Yarn 4, Corepack, npm) trust the AWF CA.
111112
# Node.js uses its own CA bundle, not the system CA store updated by update-ca-certificates.
112-
export NODE_EXTRA_CA_CERTS="/usr/local/share/ca-certificates/awf-ca.crt"
113+
export NODE_EXTRA_CA_CERTS="$AWF_CA_PATH"
114+
# SSL_CERT_FILE is respected by curl, git, Python requests, Ruby, and most
115+
# OpenSSL-based tools that don't use the system CA store updated above.
116+
export SSL_CERT_FILE="$AWF_CA_PATH"
117+
export REQUESTS_CA_BUNDLE="$AWF_CA_PATH"
113118
echo "[entrypoint] CA certificates updated for SSL Bump"
114119
echo "[entrypoint] NODE_EXTRA_CA_CERTS set to $NODE_EXTRA_CA_CERTS"
115120
echo "[entrypoint] ⚠️ WARNING: HTTPS traffic will be intercepted for URL inspection"
@@ -473,6 +478,33 @@ if [ "${AWF_CHROOT_ENABLED}" = "true" ]; then
473478
fi
474479
fi
475480

481+
# Copy AWF CA certificate to chroot-accessible path for ssl-bump TLS trust.
482+
# NODE_EXTRA_CA_CERTS points to /usr/local/share/ca-certificates/awf-ca.crt which
483+
# is a Docker volume mount on the container's overlay filesystem. After chroot /host,
484+
# this path is inaccessible. Copy to /tmp/awf-lib/ (always writable) and update the
485+
# env var so Node.js (Claude Code), curl, git, Python, etc. trust the Squid CA.
486+
AWF_CA_CHROOT=""
487+
if [ "${AWF_SSL_BUMP_ENABLED}" = "true" ] && [ -f /usr/local/share/ca-certificates/awf-ca.crt ]; then
488+
if mkdir -p /host/tmp/awf-lib 2>/dev/null; then
489+
if cp /usr/local/share/ca-certificates/awf-ca.crt /host/tmp/awf-lib/awf-ca.crt 2>/dev/null && \
490+
[ -f /host/tmp/awf-lib/awf-ca.crt ]; then
491+
AWF_CA_CHROOT="/tmp/awf-lib/awf-ca.crt"
492+
export NODE_EXTRA_CA_CERTS="$AWF_CA_CHROOT"
493+
# SSL_CERT_FILE is respected by curl, git, Python requests, Ruby, and most
494+
# OpenSSL-based tools. This ensures non-Node.js tools also trust the AWF CA.
495+
export SSL_CERT_FILE="$AWF_CA_CHROOT"
496+
export REQUESTS_CA_BUNDLE="$AWF_CA_CHROOT"
497+
echo "[entrypoint] AWF CA certificate copied to chroot at $AWF_CA_CHROOT"
498+
echo "[entrypoint] NODE_EXTRA_CA_CERTS updated to $AWF_CA_CHROOT"
499+
echo "[entrypoint] SSL_CERT_FILE updated to $AWF_CA_CHROOT"
500+
else
501+
echo "[entrypoint][WARN] Could not copy AWF CA certificate to chroot — ssl-bump TLS may fail"
502+
fi
503+
else
504+
echo "[entrypoint][WARN] Could not create /host/tmp/awf-lib for CA cert — ssl-bump TLS may fail in chroot"
505+
fi
506+
fi
507+
476508
# Verify capsh is available on the host (required for privilege drop)
477509
if ! chroot /host which capsh >/dev/null 2>&1; then
478510
echo "[entrypoint][ERROR] capsh not found on host system"
@@ -697,8 +729,8 @@ AWFEOF
697729
CLEANUP_CMD="${CLEANUP_CMD}; sed -i '/^[0-9.]\\+[[:space:]]\\+host\\.docker\\.internal\$/d' /etc/hosts 2>/dev/null || true"
698730
echo "[entrypoint] host.docker.internal will be removed from /etc/hosts on exit"
699731
fi
700-
# Clean up the one-shot-token library if it was copied
701-
if [ -n "${ONE_SHOT_TOKEN_LIB}" ]; then
732+
# Clean up /tmp/awf-lib if anything was copied (one-shot-token, CA cert, key helper)
733+
if [ -n "${ONE_SHOT_TOKEN_LIB}" ] || [ -n "${AWF_CA_CHROOT}" ] || [ -n "${CHROOT_KEY_HELPER}" ]; then
702734
CLEANUP_CMD="${CLEANUP_CMD}; rm -rf /tmp/awf-lib 2>/dev/null || true"
703735
fi
704736

0 commit comments

Comments
 (0)