Repository navigation
Description
Friction
Every client of the LLM gateway holds its master key. The master key is LiteLLM's proxy admin key: whoever holds it can mint and delete keys and call every model without limit. The cluster Jobs get it as DEVOPS_CLI_AI_API_KEY. An agent session can only get a gateway credential by a person pasting the master key, which breaks the owner's rule that agents never handle credential values.
LiteLLM's virtual keys solve this. A virtual key has an expiry, request and token limits, a parallel-request cap, a model list, an alias and metadata, and it can be revoked on its own. But LiteLLM keeps virtual keys only in a Postgres database, reached through DATABASE_URL, and the gateway has none. Without it, #1154's agent grant (devops agent env) cannot be built, and no cluster workload can move off the master key.
Evidence
Checked against main at 3dd7fa6:
- The gateway's
general_settingshold onlymaster_key,cancel_on_disconnect,store_model_in_db: falseandproxy_batch_write_at(k8s/llm/gateway/configmap.yaml:187-191). There is no database setting. - The Deployment's environment is
LITELLM_MASTER_KEY,LITELLM_LOCAL_MODEL_COST_MAP,LITELLM_TELEMETRY,LITELLM_REDIS_HOSTandLITELLM_REDIS_PORT, with noDATABASE_URL(k8s/llm/gateway/deployment.yaml:47-63). - The container runs with
readOnlyRootFilesystem: true(deployment.yaml:36), and only/tmpis writable, as anemptyDir(:72-73,:98-99). The image is pinned to LiteLLMv1.103.0(:32), and the Deployment runs one replica (:12). - The gateway's NetworkPolicy allows egress only to the Ollama pods on 11434, Valkey on 6379 and DNS (
k8s/llm/gateway/networkpolicy.yaml:27-52). Its peers are pod selectors, neveripBlock(:25-26). - No manifest under
k8s/runs Postgres. - The cluster Secret table,
CLUSTER_SECRETS(src/devops_cli/k8s/cluster_secrets.py:161), generates the master key forllm/llm-gateway-secrets(:162-180). It also copies the key intodevops/devops-cliasDEVOPS_CLI_AI_API_KEYfor every cluster Job (:223-248, the key at:230). - Every Secret in that table must be an ignored orphan in the
homelabArgo CD project (tests/test_k8s_argocd_apps.py:177-211). The llm stack's manifests are listed in_MANIFESTS_BY_STACK["llm"](src/devops_cli/commands/k8s/stack_lifecycle.py:181-190) andk8s/llm/kustomization.yaml. - LiteLLM's documentation, as recorded in feat(agent):
devops agent envgives an agent session its own expiring gateway key, run-index access and a read-only kube identity, written to its settings file or a child process and never printed, with--revokeand an audit of every grant #1154 on 2026-10-04:- Virtual keys (
/key/generate) needDATABASE_URLpointing at Postgres. - The proxy runs
prisma migrate deployat start-up. Under a read-only root filesystem, its production guide setsLITELLM_MIGRATION_DIRto a writable directory. LITELLM_SALT_KEYis set before the first key is stored, and it is never changed afterwards./health/readinessreports the database's state.general_settings.allow_requests_on_db_unavailablechooses what happens when the database is down.
- Virtual keys (
Remedy
The gateway gets its own single-instance Postgres in llm, under GitOps and deploy-stack:
- Database. Run the official
postgresimage at a pinned tag, as a StatefulSetllm-gateway-dbwith one replica and a Service on 5432.- Use the restricted security context the gateway uses: non-root,
RuntimeDefaultseccomp, no capabilities, and a read-only root filesystem withemptyDirs for the socket and temporary directories. - Data lives on a
local-pathclaim markedPrune=false,Delete=false. - The manifests join
k8s/llm/kustomization.yaml(Argo CD'sllmApplication) and_MANIFESTS_BY_STACK["llm"], ahead of the gateway's Deployment.
- Use the restricted security context the gateway uses: non-root,
- Secrets. Add a new
CLUSTER_SECRETSentry,llm/llm-gateway-db, with a generatedpasswordand a generatedsalt-key, both kept in the keyring and adopted like the master key.- Postgres reads
POSTGRES_PASSWORDfrompassword. - The gateway builds
DATABASE_URLfrom the same key with Kubernetes$(VAR)interpolation, so no full URL is stored anywhere. It readsLITELLM_SALT_KEYfromsalt-key. push-secrets --rotatenever rotatessalt-key, and the table's change note says why.- The orphan-ignore test then requires
llm-gateway-dbin thehomelabproject's list.
- Postgres reads
- Network. The gateway's policy gains one egress rule to the database pods on 5432. The database gets its own perimeter, admitting only the gateway's pods on 5432 and allowing no egress except DNS. Both use pod-selector peers.
- Gateway. Add
LITELLM_MIGRATION_DIRon anemptyDir, and keepreadOnlyRootFilesystem: true. The PR checks whether the pinned image writes anywhere else at start-up and mounts only what it must.allow_requests_on_db_unavailablestays at LiteLLM's default (false). The gateway is reachable from outside the cluster, so a key it cannot check is refused.store_model_in_dbstaysfalse, so the models stay in git.
- Backups. Per the owner's rule that PVC data has backups, add a daily
pg_dumpCronJob from the same image into its own claim, keeping 7 dumps.k8s/README.mdgets a restore section. - Tests (in the gate, no cluster):
- the database manifests' security context, claim protection and perimeter, in both directions;
- the new Secret table rows, their generators, and that
salt-keyis never rotated; - the manifest order in
_MANIFESTS_BY_STACK["llm"]; - that the gateway Deployment sets
DATABASE_URL,LITELLM_SALT_KEYandLITELLM_MIGRATION_DIRwithout any literal value.
- Pending a person, after the sync:
- the gateway's
/health/readinessreports a connected database; - a person mints a one-hour test key with the master key from their keyring, calls one model with it, deletes it, and sees the next call answer 401;
- the database claim is
Bound; - one backup file exists after the first CronJob run.
- the gateway's
Out of scope: the agent grant command (#1154's follow-up item), switching the cluster Jobs' DEVOPS_CLI_AI_API_KEY to a virtual key, and Open WebUI's connection, which keeps its own stored key.
Unblocks: the agent grant item drafted with #1154, and a later item that gives the cluster Jobs a virtual key instead of the master key.
Related: #1154, #741 (the Secret table), #755 (GitOps), #1562 (roadmap-service suspended, so a person files this item).
Delivery
One pull request delivers this issue (see the answer in the comments). It differs from the Remedy above in these points:
- Database. A CloudNativePG
Clusterllm-gateway-dbinllm, in the form of the Mattermost database, not a hand-written StatefulSet. It has one instance onlocal-path(Prune=false,Delete=false) and its own perimeter. - Secrets. The operator creates Secret
llm-gateway-db-appat run time. There is noCLUSTER_SECRETSrow, no generated password and no push. The gateway readsDATABASE_URLfrom itsurikey. - Salt key. No
LITELLM_SALT_KEY: withstore_model_in_db: falsethe database holds nothing that LiteLLM encrypts, and a virtual key is a SHA-256 hash. The README states when to set one. - Network. As in the Remedy, with one addition: the database also reaches the Kubernetes API, which the instance manager needs.
- Gateway. As in the Remedy, plus a
startupProbeso that the liveness probe does not kill a pod that migrates. - Order. The
cloudnative-pgrelease moves to stackinfra. Stackllmapplies the database after the Helm releases. - Moved: backups (the daily
pg_dumpCronJob and the restore section) to dan-petty/homelab#332. The backup must go off the node, and feat(k8s): Add scheduled off-node backup and restore for Gitea #2144 chooses the target for Gitea.
Proposed design
Problem statement
The LiteLLM gateway uses a master key for all clients. This breaks the security rule that agents should never handle credential values. Virtual keys in LiteLLM require a Postgres database, but the gateway has no database connection.
Acceptance criteria
- Criterion 1: A new Postgres StatefulSet is created for the gateway with proper security context and data persistence
Verification: The k8s/llm/gateway-db/statefulset.yaml manifest exists with restricted security context, local-path PVC with Prune=false,Delete=false, and one replica - Criterion 2: The gateway Deployment is updated to include DATABASE_URL, LITELLM_SALT_KEY, and LITELLM_MIGRATION_DIR environment variables
Verification: The k8s/llm/gateway/deployment.yaml includes env vars LITELLM_MIGRATION_DIR, DATABASE_URL (from secret interpolation), and LITELLM_SALT_KEY (from secret) - Criterion 3: A new cluster Secret is added for the gateway database with generated password and salt-key
Verification: src/devops_cli/k8s/cluster_secrets.py includes a new CLUSTER_SECRETS entry for llm/llm-gateway-db with password and salt-key generators - Criterion 4: The gateway's NetworkPolicy allows egress to the database pods on port 5432
Verification: k8s/llm/gateway/networkpolicy.yaml includes an egress rule to podSelector matching 'app.kubernetes.io/name: llm-gateway-db' on port 5432 - Criterion 5: The database's NetworkPolicy only allows ingress from the gateway pods and egress to DNS
Verification: k8s/llm/gateway-db/networkpolicy.yaml includes ingress rule from gateway podSelector and egress rule only to kube-system namespace on DNS ports - Criterion 6: The manifest order in _MANIFESTS_BY_STACK["llm"] places the database before the gateway deployment
Verification: src/devops_cli/commands/k8s/stack_lifecycle.py shows llm-gateway-db resources listed before llm-gateway deployment in the "llm" stack manifest list
Key questions
- What is the required Postgres image tag and version?: The issue description does not specify a particular Postgres version, but it references that the gateway uses LiteLLM v1.103.0 and suggests using a pinned tag for consistency with other components. [sources: k8s/llm/gateway/deployment.yaml:32]
- How should the LITELLM_SALT_KEY be handled to ensure it's never rotated?: The salt-key should be generated once and kept in the keyring, with a note explaining why it's never rotated to prevent breaking existing virtual keys. (proposed) [sources: k8s/llm/gateway/deployment.yaml:32]
- What is the expected database URL format for LiteLLM?: The DATABASE_URL should be constructed using Kubernetes $(VAR) interpolation to avoid storing full URLs in manifests, with the format postgresql://:@host`:port/database. [sources: k8s/llm/gateway/deployment.yaml:32]
- How should the gateway's readiness probe respond when the database is unavailable?: The gateway should refuse requests when the database is down, since it's reachable from outside the cluster, and allow_requests_on_db_unavailable should stay at LiteLLM's default (false). (proposed) [sources: k8s/llm/gateway/deployment.yaml:32]
Fit
Needs splitting into 5 items:
- Create the Postgres StatefulSet for the gateway
- Update cluster secrets table with database credentials
- Modify gateway Deployment to include database connection variables
- Update network policies for database connectivity
- Add database manifests to stack lifecycle order
Suspected block
None.
Dependencies
None.
Alternatives check of 2026-11-01: not-applicable.
Tool: none found.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNew
- StatusShow more project fieldsNew
Activity
dan-petty commentedon Oct 18, 2026
Intake placed this item to the backlog: at intake only a critical fix goes into a release; a release start pulls Ready items in, P0 features first.
The candidate proposes adding a new feature to support scoped, expiring gateway keys using an in-cluster Postgres database.This feature is required to enable the agent grant functionality described in issue dan-petty/devops-cli#1154 and to move off the master key for cluster workloads.This change enables secure credential management for LLM gateway access, supporting agent automation and improving security posture.The implementation requires setting up a new Postgres database, integrating it with the gateway, managing secrets, and updating deployment configurations.dan-petty commentedon Oct 18, 2026
Proposal needs splitting into 5 items at 25e2cda (see proposed design in issue body).
dan-petty commentedon Oct 26, 2026
The proposal at 085ca36 needs splitting into 5 items. A person splits the item into the items below, or replies in a comment or edits the body to keep one item, and the next refine round looks at the item again.
devops-cli-service commentedon Nov 1, 2026
Alternatives check: not-applicable
Tool: none found
Checked on 2026-11-01. A person decides what this means for the item. The check changes no label and closes no issue.
dan-petty commentedon Nov 6, 2026
Answer from project standards, under the owner's instruction of 2026-11-05.
Question 1: the refine round says to split this item in 5. Is that right?
Answer: No. It is one pull request. The 5 parts (database, secrets, gateway variables, network policies, stack order) are one change: none works alone, and they edit the same files. A split would give 5 pull requests that each leave the gateway in a state that does not work.
Rule: AGENTS.md rule 1 (one issue, one pull request).
Question 2: StatefulSet and a generated password in
CLUSTER_SECRETS, or something else?Answer: A CloudNativePG
Cluster. The cluster already runs the operator for Mattermost (k8s/mattermost/database.yaml,k8s/argocd/apps/cloudnative-pg.yaml). AClusterthat names nobootstrap.initdb.secretmakes the operator create the user, the database and Secretllm-gateway-db-appat run time, with a generated password and a readyurikey (CloudNativePG documents,applications.md, "Secrets"). The gateway readsDATABASE_URLfrom that key. So no secret is in git,CLUSTER_SECRETSgets no row, and no person pushes a value.Rule: AGENTS.md rule 3 (use an open tool before you build),
k8s/README.md(the form of the existing database), SECURITY.md (no secret in git).Question 3: is
LITELLM_SALT_KEYneeded?Answer: Not now. LiteLLM uses it only to encrypt values that it stores in the database, such as provider keys of models added at run time, and falls back to the master key. A virtual key is stored as a SHA-256 hash and does not use it (LiteLLM source at
v1.103.0,encrypt_decrypt_utils.pyandhash_token). The gateway keepsstore_model_in_db: false, so the database holds nothing to encrypt. A generated salt key would add a keyring row and a person's push before the gateway can start.k8s/README.mdstates the rule: set a salt key before the first change that stores a credential in the database.Rule: AGENTS.md rule 3 (use an open tool before you build): LiteLLM already has a fallback for this case.
Question 4: no egress except DNS for the database?
Answer: The database also needs the Kubernetes API. The instance manager calls the API server (CloudNativePG documents,
security.md). The policy uses the form ofmattermost-db-api. It admits only the gateway and the operator on 5432.Question 5: the backup CronJob.
Answer: Moved to dan-petty/homelab#332. A dump into a claim of the same node is not a backup off the node, and #2144 is choosing the target for Gitea, so the cluster gets one backup design.
Rule: the rule in this issue that PVC data has backups, and the partial-delivery rule (move a separate criterion to its own issue).
Rollout (the merge applies at once through Argo CD). The gateway has no downtime, and no person plans a window. Argo CD creates the policy and the database, and starts a new gateway pod beside the old one (one replica:
maxSurge1,maxUnavailable0). The new pod waits for the Secret, restarts a few times until the database accepts connections, runs the migrations on the empty database, and passes its readiness probe. AstartupProbegives it ten minutes so that the liveness probe does not kill it during the migration. Then Kubernetes stops the old pod. The old pod answers every request until then. The change adds nopush-secretsstep, and no person runs a command.What only a person can do: merge, and after the sync check
/health/readinessof the gateway and mint, use and delete one test key (these steps are in the change'stasks.md).chore(main): release 0.67.0 (#3750)
devops-cli-service commentedon Nov 6, 2026
Released in v0.67.0: https://github.com/dan-petty/devops-cli/releases/tag/v0.67.0
devops-cli-service commentedon Nov 6, 2026
Live since 2026-11-06 07:13 UTC
feat(service): give the Service its own gateway key (#5703)
fix(k8s): State the NVMe rule and cover CNPG claims (#6062)