Skip to content

fix(proxy): resolve os.environ/ refs universally in DB-sourced models - #32405

Merged
yuneng-berri merged 1 commit into
litellm_internal_stagingfrom
litellm_kraken-remove-envref-gates
Jul 8, 2026
Merged

yuneng-berri merged 1 commit into
litellm_internal_stagingfrom
litellm_kraken-remove-envref-gates

Conversation

@yucheng-berri

@yucheng-berri yucheng-berri commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Relevant issues

Linear ticket

Pre-Submission checklist

  • I have added meaningful tests
  • My PR passes all CI/CD checks (e.g., lint, format, unit tests)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review

Screenshots / Proof of Fix

Reproduced end-to-end against a live proxy on litellm_kraken-remove-envref-gates @ e7c4aeb0d6, backed by real Postgres 18. Config sets store_model_in_db: true, master key sk-1234, license via LITELLM_LICENSE

DB row shape follows the customer's setup: admin-authored (team_id=None) Bedrock model with aws_role_name set as an env-ref

$ export FOO_ARBITRARY="admin-arbitrary-resolved"
$ curl -sS -X POST http://localhost:4000/model/new \
    -H "Authorization: Bearer sk-1234" -H "Content-Type: application/json" \
    -d '{
      "model_name": "item1-admin-arbitrary",
      "litellm_params": {
        "model": "openai/gpt-4o-mini",
        "api_key": "sk-fake-not-used",
        "aws_role_name": "os.environ/FOO_ARBITRARY"
      }
    }'

Before this PR (base commit db24027): the DB-load path resolved env refs only for keys in _DB_LITELLM_PARAM_ENV_REF_KEYS. aws_role_name is not on the pre-PR 6-key list; even after #32256 extends the whitelist to 18 keys, any new off-list field silently fails the same way. On the unfixed code the router receives the literal os.environ/FOO_ARBITRARY and STS rejects the AssumeRole call with ValidationError: os.environ/FOO_ARBITRARY is invalid

After this PR (e7c4aeb0d6): the router deployment holds the resolved value

$ curl -sS "http://localhost:4000/v2/model/info?modelId=<id>" \
    -H "Authorization: Bearer sk-1234" | jq '.data[0].litellm_params.aws_role_name'
"admin-arbitrary-resolved"

Same result for a team-scoped row with api_key: os.environ/TEAM_OPENAI_KEY. A chat completion invocation through that model reaches OpenAI with the resolved key:

$ curl -sS -X POST http://localhost:4000/v1/chat/completions \
    -H "Authorization: Bearer <team_verify_admin_key>" -H "Content-Type: application/json" \
    -d '{"model": "item2-team-apikey", "messages": [{"role":"user","content":"hi"}]}'
{"error":{"message":"litellm.AuthenticationError: AuthenticationError:
  OpenAIException - Incorrect API key provided: sk-team-***********lved.
  ..."}}

That is sk-team-openai-resolved echoed back by OpenAI, masked by OpenAI's own error format. Same shape works for arbitrary custom field names (some_future_field: os.environ/TEAM_CUSTOM_ARBITRARY resolves to "team-custom-resolved" on /v2/model/info)

LIT-3831 is not reopened for the original request-body vector. A caller sending aws_role_name: os.environ/DATABASE_URL_SECRET in the request body is still refused by the existing _BANNED_REQUEST_BODY_PARAMS gate:

$ curl -sS -X POST http://localhost:4000/v1/chat/completions \
    -H "Authorization: Bearer sk-1234" -H "Content-Type: application/json" \
    -d '{"model":"item1-admin-arbitrary","messages":[{"role":"user","content":"hi"}],
         "aws_role_name":"os.environ/DATABASE_URL_SECRET"}'
{"error":{"message":"Authentication Error, Rejected Request: aws_role_name
  is not allowed in request body. ..."}}

Write-side trust boundary is unchanged. A team_verify admin cannot write another team's rows (403), a plain internal_user cannot write any model row (403). Sensitive fields explicitly popped by remove_sensitive_info_from_deployment (api_key, client_secret, aws_secret_access_key) are still absent from /model/info and /v2/model/info responses

Type

🐛 Bug Fix

Changes

Root cause: PR #30867 removed request-time os.environ/ expansion in BaseAWSLLM.get_credentials. That is only safe if the config-load path pre-resolves os.environ/ refs so the value reaching get_credentials is already the real secret. The YAML config path has always done this. The DB-load path (ProxyConfig._resolve_db_litellm_param in litellm/proxy/proxy_server.py) only re-expanded keys in _DB_LITELLM_PARAM_ENV_REF_KEYS plus short-circuited resolution entirely for team-scoped rows. PR #32256 extended that whitelist to 18 keys to unblock a customer whose Bedrock model with aws_role_name: os.environ/BEDROCK_ASSUME_ROLE_ARN broke on v1.90+. The whitelist is structurally fragile though: every future auth field breaks the same way until someone remembers to add it, which is the exact regression pattern that produced the ticket that led to #32256

Fix: remove the whitelist and the team-scope short-circuit. The DB-load resolver now expands os.environ/ on every string field, matching the YAML path. Trust boundary stays on the write side: only PROXY_ADMIN can create team_id=None rows (ModelManagementAuthChecks.can_user_make_model_call), only team admins of a given team can create rows scoped to that team, and the request-body vector is still blocked by _BANNED_REQUEST_BODY_PARAMS. Team-scoped rows now resolve env refs; this is a deliberate LIT-3831 threat-model expansion trusting team admins for env-var reads (an internal design conversation covering the tradeoff)

Regression tests in tests/test_litellm/proxy/proxy_server/test_proxy_config.py:

  • test_ProxyConfig__add_deployment_resolves_env_refs_after_db_decrypt pins admin-scoped rows resolve every field, including api_base which previously stayed literal
  • test_ProxyConfig__add_deployment_resolves_team_env_refs pins team rows resolve env refs (previously stayed literal). Fails on unfixed code with the exact "literal not resolved" symptom
  • test_ProxyConfig__add_deployment_resolves_env_refs_on_arbitrary_field pins the no-whitelist invariant against a made-up field name
  • test_ProxyConfig__add_deployment_resolves_env_refs_for_aws_bedrock_auth_params (from fix(proxy): resolve os.environ/ refs for all AWS auth params in DB-sourced models #32256) still passes
  • Path B counterparts (decrypt_model_list_from_db) mirror the above

@yucheng-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit e7c4aeb0d6ddebd948d01de3d22244c04dc331af. Configure here.

_litellm_params[k] = self._resolve_db_litellm_param(
key=k, value=v, resolve_env_refs=resolve_env_refs
)
_litellm_params[k] = self._resolve_db_litellm_param(key=k, value=v)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rotation persists resolved env values

Medium Severity

decrypt_model_list_from_db now resolves every os.environ/ string before master-key rotation re-encrypts model params via _add_model_to_db, so DB rows that stored indirection references can be rewritten with resolved plaintext secrets. Team-scoped models previously skipped resolution on this path.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit e7c4aeb0d6ddebd948d01de3d22244c04dc331af. Configure here.

Root cause: PR #30867 removed request-time os.environ/ expansion in
BaseAWSLLM.get_credentials. That is only safe if config-load pre-resolves
os.environ/ refs so the value reaching get_credentials is already the real
secret. The YAML config path has always done this. The DB-load path
(ProxyConfig._resolve_db_litellm_param) only re-expanded keys in a hardcoded
whitelist (_DB_LITELLM_PARAM_ENV_REF_KEYS) plus short-circuited env-ref
resolution entirely for team-scoped rows. PR #32256 extended that whitelist
to 18 keys to unblock a customer whose Bedrock model with aws_role_name:
os.environ/BEDROCK_ASSUME_ROLE_ARN broke on v1.90+, but the whitelist is
structurally fragile: every future auth field breaks the same way until
someone remembers to add it

Fix: remove the whitelist and the team-scope short-circuit. The DB-load
resolver now expands os.environ/ on every string field, matching the YAML
path. Trust boundary stays on the write side: only PROXY_ADMIN can create
team_id=None rows, only team admins of a team can create rows scoped to
that team, and the request-body vector is still blocked by
_BANNED_REQUEST_BODY_PARAMS. Team-scoped rows now resolve env refs — this
is a deliberate LIT-3831 threat-model expansion trusting team admins for
env-var reads

Regression tests in tests/test_litellm/proxy/proxy_server/test_proxy_config.py:
- test_ProxyConfig__add_deployment_resolves_env_refs_after_db_decrypt pins
  admin-scoped rows resolve every field (previously api_base stayed literal)
- test_ProxyConfig__add_deployment_resolves_team_env_refs pins team rows
  resolve env refs (previously stayed literal)
- test_ProxyConfig__add_deployment_resolves_env_refs_on_arbitrary_field pins
  the no-whitelist invariant against a made-up field name
- test_ProxyConfig__add_deployment_resolves_env_refs_for_aws_bedrock_auth_params
  (from #32256) still passes
- Path B counterparts (decrypt_model_list_from_db) mirror the above

Left as followups (not fixed here):
- /model/info and /v2/model/info still echo resolved values for fields not
  in the current pop-list (aws_role_name, aws_sts_endpoint, api_base, etc.).
  Fix is to extend remove_sensitive_info_from_deployment; separate PR
- Master-key rotation reads DB rows via decrypt_model_list_from_db which
  now resolves universally, so rotation collapses env-refs into hardcoded
  values. Pre-existing bug for the 6 previously-whitelisted fields; wider
  surface after this PR. Separate PR
@yucheng-berri
yucheng-berri force-pushed the litellm_kraken-remove-envref-gates branch from e7c4aeb to 5862be3 Compare July 8, 2026 01:31
@codecov

codecov Bot commented Jul 8, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 30 untouched benchmarks


Comparing litellm_kraken-remove-envref-gates (5862be3) with litellm_internal_staging (db24027)

Open in CodSpeed

@BerriAI BerriAI deleted a comment from veria-ai Bot Jul 8, 2026
@BerriAI BerriAI deleted a comment from greptile-apps Bot Jul 8, 2026
@BerriAI BerriAI deleted a comment from veria-ai Bot Jul 8, 2026
@yuneng-berri
yuneng-berri enabled auto-merge July 8, 2026 04:32
@yuneng-berri
yuneng-berri merged commit ec4f324 into litellm_internal_staging Jul 8, 2026
84 of 85 checks passed
@yuneng-berri
yuneng-berri deleted the litellm_kraken-remove-envref-gates branch July 8, 2026 04:53
yuneng-berri added a commit that referenced this pull request Jul 8, 2026
chore(release): backport #32256, #32405, #32524 to stable/1.91.x and cut 1.91.1
yuneng-berri added a commit that referenced this pull request Jul 8, 2026
eleboucher pushed a commit to eleboucher/homelab that referenced this pull request Jul 9, 2026
….1) (#1475)

This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [ghcr.io/berriai/litellm](https://images.chainguard.dev/directory/image/wolfi-base/overview) ([source](https://github.com/BerriAI/litellm)) | patch | `v1.91.0` → `v1.91.1` |

---

### Release Notes

<details>
<summary>BerriAI/litellm (ghcr.io/berriai/litellm)</summary>

### [`v1.91.1`](https://github.com/BerriAI/litellm/releases/tag/v1.91.1)

[Compare Source](BerriAI/litellm@v1.91.1...v1.91.1)

##### Verify Docker Image Signature

All LiteLLM Docker images are signed with [cosign](https://docs.sigstore.dev/cosign/overview/). Every release is signed with the same key introduced in [commit `0112e53`](BerriAI/litellm@0112e53).

**Verify using the pinned commit hash (recommended):**

A commit hash is cryptographically immutable, so this is the strongest way to ensure you are using the original signing key:

```bash
cosign verify \
  --key https://raw.githubusercontent.com/BerriAI/litellm/0112e53046018d726492c814b3644b7d376029d0/cosign.pub \
  ghcr.io/berriai/litellm:v1.91.1
```

**Verify using the release tag (convenience):**

Tags are protected in this repository and resolve to the same key. This option is easier to read but relies on tag protection rules:

```bash
cosign verify \
  --key https://raw.githubusercontent.com/BerriAI/litellm/v1.91.1/cosign.pub \
  ghcr.io/berriai/litellm:v1.91.1
```

Expected output:

```
The following checks were performed on each of these signatures:
  - The cosign claims were validated
  - The signatures were verified against the specified public key
```

***

##### What's Changed

- chore(release): backport [#&#8203;32256](BerriAI/litellm#32256), [#&#8203;32405](BerriAI/litellm#32405), [#&#8203;32524](BerriAI/litellm#32524) to stable/1.91.x and cut 1.91.1 by [@&#8203;yuneng-berri](https://github.com/yuneng-berri) in [#&#8203;32552](BerriAI/litellm#32552)

**Full Changelog**: <BerriAI/litellm@v1.91.0...v1.91.1>

### [`v1.91.1`](https://github.com/BerriAI/litellm/releases/tag/v1.91.1)

[Compare Source](BerriAI/litellm@v1.91.0...v1.91.1)

##### Verify Docker Image Signature

All LiteLLM Docker images are signed with [cosign](https://docs.sigstore.dev/cosign/overview/). Every release is signed with the same key introduced in [commit `0112e53`](BerriAI/litellm@0112e53).

**Verify using the pinned commit hash (recommended):**

A commit hash is cryptographically immutable, so this is the strongest way to ensure you are using the original signing key:

```bash
cosign verify \
  --key https://raw.githubusercontent.com/BerriAI/litellm/0112e53046018d726492c814b3644b7d376029d0/cosign.pub \
  ghcr.io/berriai/litellm:v1.91.1
```

**Verify using the release tag (convenience):**

Tags are protected in this repository and resolve to the same key. This option is easier to read but relies on tag protection rules:

```bash
cosign verify \
  --key https://raw.githubusercontent.com/BerriAI/litellm/v1.91.1/cosign.pub \
  ghcr.io/berriai/litellm:v1.91.1
```

Expected output:

```
The following checks were performed on each of these signatures:
  - The cosign claims were validated
  - The signatures were verified against the specified public key
```

***

##### What's Changed

- chore(release): backport [#&#8203;32256](BerriAI/litellm#32256), [#&#8203;32405](BerriAI/litellm#32405), [#&#8203;32524](BerriAI/litellm#32524) to stable/1.91.x and cut 1.91.1 by [@&#8203;yuneng-berri](https://github.com/yuneng-berri) in [#&#8203;32552](BerriAI/litellm#32552)

**Full Changelog**: <BerriAI/litellm@v1.91.0...v1.91.1>

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xMDEuMSIsInVwZGF0ZWRJblZlciI6IjQzLjEwMS4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJyZW5vdmF0ZS9jb250YWluZXIiLCJ0eXBlL3BhdGNoIl19-->

Reviewed-on: https://git.erwanleboucher.dev/eleboucher/homelab/pulls/1475
doonga pushed a commit to greyrock-labs/home-ops that referenced this pull request Jul 9, 2026
….1) (#488)

This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [ghcr.io/berriai/litellm](https://images.chainguard.dev/directory/image/wolfi-base/overview) ([source](https://github.com/BerriAI/litellm)) | patch | `v1.91.0` → `v1.91.1` |

---

### Release Notes

<details>
<summary>BerriAI/litellm (ghcr.io/berriai/litellm)</summary>

### [`v1.91.1`](https://github.com/BerriAI/litellm/releases/tag/v1.91.1)

[Compare Source](BerriAI/litellm@v1.91.1...v1.91.1)

##### Verify Docker Image Signature

All LiteLLM Docker images are signed with [cosign](https://docs.sigstore.dev/cosign/overview/). Every release is signed with the same key introduced in [commit `0112e53`](BerriAI/litellm@0112e53).

**Verify using the pinned commit hash (recommended):**

A commit hash is cryptographically immutable, so this is the strongest way to ensure you are using the original signing key:

```bash
cosign verify \
  --key https://raw.githubusercontent.com/BerriAI/litellm/0112e53046018d726492c814b3644b7d376029d0/cosign.pub \
  ghcr.io/berriai/litellm:v1.91.1
```

**Verify using the release tag (convenience):**

Tags are protected in this repository and resolve to the same key. This option is easier to read but relies on tag protection rules:

```bash
cosign verify \
  --key https://raw.githubusercontent.com/BerriAI/litellm/v1.91.1/cosign.pub \
  ghcr.io/berriai/litellm:v1.91.1
```

Expected output:

```
The following checks were performed on each of these signatures:
  - The cosign claims were validated
  - The signatures were verified against the specified public key
```

***

##### What's Changed

- chore(release): backport [#&#8203;32256](BerriAI/litellm#32256), [#&#8203;32405](BerriAI/litellm#32405), [#&#8203;32524](BerriAI/litellm#32524) to stable/1.91.x and cut 1.91.1 by [@&#8203;yuneng-berri](https://github.com/yuneng-berri) in [#&#8203;32552](BerriAI/litellm#32552)

**Full Changelog**: <BerriAI/litellm@v1.91.0...v1.91.1>

### [`v1.91.1`](https://github.com/BerriAI/litellm/releases/tag/v1.91.1)

[Compare Source](BerriAI/litellm@v1.91.0...v1.91.1)

##### Verify Docker Image Signature

All LiteLLM Docker images are signed with [cosign](https://docs.sigstore.dev/cosign/overview/). Every release is signed with the same key introduced in [commit `0112e53`](BerriAI/litellm@0112e53).

**Verify using the pinned commit hash (recommended):**

A commit hash is cryptographically immutable, so this is the strongest way to ensure you are using the original signing key:

```bash
cosign verify \
  --key https://raw.githubusercontent.com/BerriAI/litellm/0112e53046018d726492c814b3644b7d376029d0/cosign.pub \
  ghcr.io/berriai/litellm:v1.91.1
```

**Verify using the release tag (convenience):**

Tags are protected in this repository and resolve to the same key. This option is easier to read but relies on tag protection rules:

```bash
cosign verify \
  --key https://raw.githubusercontent.com/BerriAI/litellm/v1.91.1/cosign.pub \
  ghcr.io/berriai/litellm:v1.91.1
```

Expected output:

```
The following checks were performed on each of these signatures:
  - The cosign claims were validated
  - The signatures were verified against the specified public key
```

***

##### What's Changed

- chore(release): backport [#&#8203;32256](BerriAI/litellm#32256), [#&#8203;32405](BerriAI/litellm#32405), [#&#8203;32524](BerriAI/litellm#32524) to stable/1.91.x and cut 1.91.1 by [@&#8203;yuneng-berri](https://github.com/yuneng-berri) in [#&#8203;32552](BerriAI/litellm#32552)

**Full Changelog**: <BerriAI/litellm@v1.91.0...v1.91.1>

</details>

---

### Configuration

📅 **Schedule**: (in timezone America/New_York)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4yNTIuMSIsInVwZGF0ZWRJblZlciI6IjQzLjI1Mi4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJyZW5vdmF0ZS9jb250YWluZXIiLCJ0eXBlL3BhdGNoIl19-->

Reviewed-on: https://git.greyrock.io/greyrock-labs/home-ops/pulls/488
stvnksslr pushed a commit to stvnksslr/litellm that referenced this pull request Jul 14, 2026
…nvref-gates

fix(proxy): resolve os.environ/ refs universally in DB-sourced models

(cherry picked from commit ec4f324)
yuneng-berri added a commit that referenced this pull request Aug 8, 2026
…x-0808sec

chore(release): backport #30585, #30867, #31905, #32093, #32405, #34189, #36011 to stable/1.89.x and cut 1.89.7
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.

2 participants