security: drop guessable LITELLM_MASTER_KEY fallback on gateway clients#116
Merged
Merged
Conversation
PR #111 hardened the model-gateway to refuse a guessable master key. Downstream clients still fell back to the literal `local` when calling the gateway, so an unset key now silently locks the client out (401) instead of failing loud. Remove every guessable `local` default on the client side; an unset key now yields an empty bearer the gateway rejects loudly. Each client is provided the real key: LITELLM_MASTER_KEY is a CORE_SECRET_KEY rendered into secrets.env, and the stack (and per-service recreate) is brought up with `--env-file .env --env-file secrets.env`, so `${LITELLM_MASTER_KEY}` interpolates the real value at compose-up (comfyui/open-webui/dashboard/n8n) and reaches the hermes/agent container in-process via its secrets.env env_file. Sites fixed: - services/comfyui/plugin.yaml LITELLM_MASTER_KEY ${..:-local} -> ${..} - services/open-webui/plugin.yaml (x2) OPENAI_API_KEY / RAG_OPENAI_API_KEY - services/v1-parity/dashboard.yaml MODEL_GATEWAY_API_KEY - hermes/entrypoint.sh model.api_key: add `:?` fail-loud guard, drop :-local - services/automation/plugin.yaml n8n OPENAI_API_KEY: hardcoded `local` -> ${LITELLM_MASTER_KEY} (bare-literal sibling of the same hole, found by grep beyond the reported set) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to PR #111 (model-gateway edge-auth hardening). The gateway now refuses a guessable master key, but downstream clients still fell back to the literal
localwhen authenticating to it. Post-hardening that means an unset key is sent as a guessablelocal(or the client is silently locked out with a 401) instead of failing loud. This removes every guessablelocaldefault on the client side — an unset key now yields an empty bearer the gateway rejects loudly (security + correctness).Verification — each client IS provided the real key (checked before removing)
LITELLM_MASTER_KEYis aCORE_SECRET_KEY(ordo/render.py:35), always rendered intosecrets.env. The stack up and the per-service recreate both pass--env-file .env --env-file secrets.env(services/ops-api/compose_recreate.py— its docstring states: "Withoutsecrets.env,${LITELLM_MASTER_KEY}… go UNSET"), so:wants_secrets: true), open-webui (wants_secrets: true), v1-parity dashboard, n8n — receive the real value via compose${LITELLM_MASTER_KEY}interpolation at up-time.secrets=True→env_file: [.env, secrets.env], so the entrypoint's runtime${LITELLM_MASTER_KEY}expansion reads the real key in-process.None genuinely depended on the
:-localfallback; all removals are safe.Sites fixed
services/comfyui/plugin.yamlLITELLM_MASTER_KEY: ${LITELLM_MASTER_KEY:-local}${LITELLM_MASTER_KEY}services/open-webui/plugin.yamlOPENAI_API_KEY: ${LITELLM_MASTER_KEY:-local}${LITELLM_MASTER_KEY}services/open-webui/plugin.yamlRAG_OPENAI_API_KEY: ${LITELLM_MASTER_KEY:-local}${LITELLM_MASTER_KEY}services/v1-parity/dashboard.yamlMODEL_GATEWAY_API_KEY: ${LITELLM_MASTER_KEY:-local}${LITELLM_MASTER_KEY}hermes/entrypoint.shmodel.api_key "${LITELLM_MASTER_KEY:-local}": "${LITELLM_MASTER_KEY:?…}"fail-loud guard +${LITELLM_MASTER_KEY}services/automation/plugin.yaml(n8n)OPENAI_API_KEY: local(bare literal)${LITELLM_MASTER_KEY}Beyond the reported set: the n8n site (
automation/plugin.yaml) hardcoded a barelocal(not the:-localpattern), so it wasn't in the batch-2 list — but it's the same class of guessable gateway-client key and is fixed here. Verified it interpolates the real key fromsecrets.envat up-time (interpolation is CLI---env-filebased, so it works despite n8n lackingwants_secrets).Validation
grepforLITELLM_MASTER_KEY:-local/:- localacross the repo → zero remain (client and gateway code).python -m ordo --source out/ordo.yaml render→ succeeds. Newdocker-compose.ymlsha6450f3f0(baseline727e332d— already drifted from the audit-quoted3f63588dbecauseout/carries the operator fable pin).grep -i "master.*local\|LITELLM.*local\|API_KEY: local"on the new compose → none; all client key lines render as bare${LITELLM_MASTER_KEY}.ruff check .→ clean.pytest tests/ -q→ 564 passed, 4 skipped (no test asserted the old client env strings).Out of scope (surfaced, not changed here)
services/v1-parity/dashboard/app.py:202—os.environ.get("MODEL_GATEWAY_API_KEY", os.environ.get("LITELLM_MASTER_KEY", "local")). Baked intoordo/dashboard-v1:latest(needs an image rebuild, not a next-deploy manifest change); the"local"default is dead in practice becauseMODEL_GATEWAY_API_KEYis always injected. Recommend a follow-up dashboard-image PR to drop it.scripts/smoke_test.sh/scripts/smoke_test.ps1— manual diagnostic probes default to'local'; operator tooling, not a running client credential.🤖 Generated with Claude Code