Skip to content

fix(k8s): make LiteLLM emit https URLs behind the ingress - #97

Merged
jcschaff merged 1 commit into
mainfrom
fix/litellm-forwarded-proto
Aug 12, 2026
Merged

fix(k8s): make LiteLLM emit https URLs behind the ingress#97
jcschaff merged 1 commit into
mainfrom
fix/litellm-forwarded-proto

Conversation

@jcschaff

Copy link
Copy Markdown
Member

Follow-up to #96. With the dashboard working, one wart remained: /kartik/ui redirected to http://<host>/kartik/ui/ rather than https://. Browsers recovered on a second hop, but the first one was plaintext.

Cause. LiteLLM takes uvicorn's defaults, so ProxyHeadersMiddleware is installed (proxy_headers=True) — but forwarded_allow_ips falls back to FORWARDED_ALLOW_IPS or "127.0.0.1" (uvicorn/config.py:357). nginx connects from a pod IP, so X-Forwarded-Proto: https was discarded, the request scheme stayed http, and that's what Starlette used to build the redirect.

Why * is acceptable here. The litellm Service is ClusterIP, so nothing outside the cluster can reach the pod directly to forge the header, and nginx overwrites X-Forwarded-* on every request. The residual exposure is that an in-cluster caller could spoof the client IP in logs — no auth impact. Scoping to the ingress controller's pod CIDR would be tighter but brittle across cluster changes.

Dev only, matching SERVER_ROOT_PATH — prod and local don't expose the proxy through an ingress.

Config-only, no image bump.

🤖 Generated with Claude Code

https://claude.ai/code/session_0174W6CHp7FMt7c9sKdBhbp1

/kartik/ui redirected to http://<host>/kartik/ui/ instead of https. Browsers
recovered on a second hop, but the first one was plaintext.

LiteLLM takes uvicorn's defaults, so ProxyHeadersMiddleware is installed
(proxy_headers=True) but only trusts 127.0.0.1 -- uvicorn falls back to
FORWARDED_ALLOW_IPS or "127.0.0.1" (uvicorn/config.py:357). nginx connects from
a pod IP, so X-Forwarded-Proto was discarded and the request scheme stayed http,
which is what Starlette used to build the redirect.

"*" is safe here: the Service is ClusterIP, so nothing outside the cluster can
reach the pod directly to forge the header, and nginx overwrites it per request.
Dev only, since prod and local don't expose the proxy through an ingress.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0174W6CHp7FMt7c9sKdBhbp1
@jcschaff
jcschaff merged commit adafe92 into main Aug 12, 2026
1 check passed
@jcschaff
jcschaff deleted the fix/litellm-forwarded-proto branch August 12, 2026 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant