Skip to content

Commit 79b23be

Browse files
Claudelpcox
andcommitted
fix: add claude code api key helper validation and ttl config
- Add validation in entrypoint.sh to verify apiKeyHelper is in config file - Check config file exists at ~/.claude/config.json - Verify apiKeyHelper field matches CLAUDE_CODE_API_KEY_HELPER env var - Exit with error if validation fails to prevent using wrong credentials - Add CLAUDE_CODE_API_KEY_HELPER_TTL_MS=3600000 to smoke-claude workflow - Ensures Claude Code properly detects and uses the API key helper script Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
1 parent f62c148 commit 79b23be

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

.github/workflows/smoke-claude.lock.yml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

containers/agent/entrypoint.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,41 @@ fi
119119
# If health check fails, the script exits with non-zero code and prevents agent from running
120120
/usr/local/bin/api-proxy-health-check.sh || exit 1
121121

122+
# Validate Claude Code API key helper configuration
123+
# This ensures the apiKeyHelper is properly configured in the config file
124+
# If validation fails, exit before running the agent to prevent using wrong credentials
125+
if [ -n "$CLAUDE_CODE_API_KEY_HELPER" ]; then
126+
echo "[entrypoint] Validating Claude Code API key helper configuration..."
127+
128+
# Check if config file exists
129+
CONFIG_FILE="$HOME/.claude/config.json"
130+
if [ ! -f "$CONFIG_FILE" ]; then
131+
echo "[entrypoint][ERROR] Claude Code config file not found at $CONFIG_FILE"
132+
echo "[entrypoint][ERROR] Cannot verify apiKeyHelper configuration"
133+
exit 1
134+
fi
135+
136+
# Check if apiKeyHelper is present in config file
137+
if ! grep -q '"apiKeyHelper"' "$CONFIG_FILE"; then
138+
echo "[entrypoint][ERROR] apiKeyHelper not found in Claude Code config file"
139+
echo "[entrypoint][ERROR] Expected: {\"apiKeyHelper\":\"$CLAUDE_CODE_API_KEY_HELPER\"}"
140+
echo "[entrypoint][ERROR] Actual config:"
141+
cat "$CONFIG_FILE" >&2
142+
exit 1
143+
fi
144+
145+
# Verify the value matches the environment variable
146+
CONFIGURED_HELPER=$(grep -o '"apiKeyHelper":"[^"]*"' "$CONFIG_FILE" | cut -d'"' -f4)
147+
if [ "$CONFIGURED_HELPER" != "$CLAUDE_CODE_API_KEY_HELPER" ]; then
148+
echo "[entrypoint][ERROR] apiKeyHelper mismatch:"
149+
echo "[entrypoint][ERROR] Environment variable: $CLAUDE_CODE_API_KEY_HELPER"
150+
echo "[entrypoint][ERROR] Config file value: $CONFIGURED_HELPER"
151+
exit 1
152+
fi
153+
154+
echo "[entrypoint] ✓ Claude Code API key helper validated: $CLAUDE_CODE_API_KEY_HELPER"
155+
fi
156+
122157
# Print proxy environment
123158
echo "[entrypoint] Proxy configuration:"
124159
echo "[entrypoint] HTTP_PROXY=$HTTP_PROXY"

0 commit comments

Comments
 (0)