-
Notifications
You must be signed in to change notification settings - Fork 17
feat: unify API proxy sidecar into Squid proxy container #1026
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,36 @@ | ||
| FROM ubuntu/squid:latest | ||
|
|
||
| # Install additional tools for debugging, healthcheck, and SSL Bump | ||
| # Install additional tools for debugging, healthcheck, SSL Bump, and Node.js (for auth proxy) | ||
| # Retry logic handles transient 404s when Ubuntu archive supersedes package versions mid-build | ||
| RUN set -eux; \ | ||
| PKGS="curl dnsutils net-tools netcat-openbsd openssl squid-openssl"; \ | ||
| PKGS="curl dnsutils net-tools netcat-openbsd openssl squid-openssl nodejs npm"; \ | ||
| apt-get update && \ | ||
| apt-get install -y --only-upgrade gpgv && \ | ||
| ( apt-get install -y --no-install-recommends $PKGS || \ | ||
| (rm -rf /var/lib/apt/lists/* && apt-get update && \ | ||
| apt-get install -y --no-install-recommends $PKGS) ) && \ | ||
| rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # Create log directory and SSL database directory | ||
| RUN mkdir -p /var/log/squid && \ | ||
| chown -R proxy:proxy /var/log/squid | ||
| # Create log directories | ||
| RUN mkdir -p /var/log/squid /var/log/api-proxy && \ | ||
| chown -R proxy:proxy /var/log/squid /var/log/api-proxy | ||
|
|
||
| # Copy API proxy files and install dependencies | ||
| WORKDIR /app/api-proxy | ||
| COPY package*.json ./ | ||
| RUN npm ci --omit=dev | ||
| COPY server.js ./ | ||
|
|
||
| # Reset workdir | ||
| WORKDIR / | ||
|
|
||
| # Copy entrypoint script | ||
| COPY entrypoint.sh /usr/local/bin/entrypoint.sh | ||
| RUN chmod +x /usr/local/bin/entrypoint.sh | ||
|
|
||
| # Expose Squid port (3128 for HTTP, 3129 for HTTPS with SSL Bump) | ||
| EXPOSE 3128 | ||
| EXPOSE 3129 | ||
| # and API proxy ports (10000-10002 for LLM provider proxies) | ||
| EXPOSE 3128 3129 10000 10001 10002 | ||
|
|
||
| # Use entrypoint to fix permissions before starting Squid | ||
| ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] |
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -19,5 +19,51 @@ if [ -d "/var/spool/squid_ssl_db" ]; then | |||||||||||||||
| echo "[squid-entrypoint] SSL certificate database ready" | ||||||||||||||||
| fi | ||||||||||||||||
|
|
||||||||||||||||
| # Start Squid | ||||||||||||||||
| exec squid -N -d 1 | ||||||||||||||||
| # Start Node.js auth proxy if API keys are configured | ||||||||||||||||
| # Security mitigation 3a: Run Node.js as non-root 'proxy' user | ||||||||||||||||
| if [ -n "$OPENAI_API_KEY" ] || [ -n "$ANTHROPIC_API_KEY" ] || [ -n "$COPILOT_GITHUB_TOKEN" ]; then | ||||||||||||||||
| echo "[squid-entrypoint] Starting API auth proxy..." | ||||||||||||||||
|
|
||||||||||||||||
| # Fix permissions on api-proxy log directory | ||||||||||||||||
| chown -R proxy:proxy /var/log/api-proxy | ||||||||||||||||
| chmod -R 755 /var/log/api-proxy | ||||||||||||||||
|
|
||||||||||||||||
| # Route through localhost Squid (not external IP) | ||||||||||||||||
| export HTTP_PROXY="http://localhost:3128" | ||||||||||||||||
| export HTTPS_PROXY="http://localhost:3128" | ||||||||||||||||
|
|
||||||||||||||||
| # Security mitigation 3a: Drop to non-root 'proxy' user before starting Node.js | ||||||||||||||||
| su -s /bin/sh proxy -c "HTTP_PROXY='$HTTP_PROXY' HTTPS_PROXY='$HTTPS_PROXY' \ | ||||||||||||||||
| OPENAI_API_KEY='${OPENAI_API_KEY:-}' \ | ||||||||||||||||
| ANTHROPIC_API_KEY='${ANTHROPIC_API_KEY:-}' \ | ||||||||||||||||
| COPILOT_GITHUB_TOKEN='${COPILOT_GITHUB_TOKEN:-}' \ | ||||||||||||||||
| node /app/api-proxy/server.js" & | ||||||||||||||||
|
Comment on lines
+36
to
+40
|
||||||||||||||||
| su -s /bin/sh proxy -c "HTTP_PROXY='$HTTP_PROXY' HTTPS_PROXY='$HTTPS_PROXY' \ | |
| OPENAI_API_KEY='${OPENAI_API_KEY:-}' \ | |
| ANTHROPIC_API_KEY='${ANTHROPIC_API_KEY:-}' \ | |
| COPILOT_GITHUB_TOKEN='${COPILOT_GITHUB_TOKEN:-}' \ | |
| node /app/api-proxy/server.js" & | |
| # Preserve environment so proxy and API key variables are available to Node.js | |
| su -m -s /bin/sh proxy -c "node /app/api-proxy/server.js" & |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chmod -R 755 /var/log/api-proxymakes the mounted log directory world-readable. Since these logs may contain sensitive request metadata, it would be safer to restrict permissions (e.g., 750/700) and rely onproxy:proxyownership for access.