Repository navigation
fix(auth): do not admit ambient environment credentials behind declared profiles - #118458
Patrick-Erichsen merged 1 commit into
Conversation
…ed profiles
A provider credential present only in the process environment — named in
neither the provider entry, `auth.profiles`, nor `auth.order` — was appended to
the auth attempt list behind the operator's declared profiles. A run that left
a declared profile could therefore continue on an undeclared credential, which
may bill a different account, with no configuration authorizing the transition
and nothing reporting that it happened.
Add an explicit `authorization: "declared" | "ambient"` fact on direct auth
sources and enforce it during source selection. The field is required rather
than defaulted so every construction site is audited; `evidence` is left as
provenance, since a declared credential can legitimately be environment-sourced
via a `${VAR}` marker or a SecretRef.
An ambient credential may still serve a provider with no declared profiles (the
documented zero-config `PROVIDER_API_KEY` path), but it is no longer admitted
behind declared profiles, nor substituted for declared profiles that turned out
to be unusable. `auth.order` failover is unaffected: profiles are never filtered
by this change. The read-only availability evaluator applies the same rule so
status cannot advertise a credential the runtime refuses.
This restores the invariant that held before 1b1cebf (openclaw#104685), where an
environment candidate was reachable only when a provider had no declared
profiles. The regression shipped in 2026.7.2-beta.1 onwards; no GA release is
affected.
Reported in openclaw#117956.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Nwk2KaB6zL71xa1i3Xwgwi
|
Reported by @Peetiegonzalez in #117956, who confirmed the metered usage against the provider console and reviewed this fix before filing. Tagging for follow-ups. |
|
Codex review: needs maintainer review before merge. Reviewed August 3, 2026, 1:17 AM ET / 05:17 UTC. ClawSweeper reviewWhat this changesThe branch distinguishes declared from ambient provider credentials so an environment-only credential cannot become a fallback behind configured auth profiles, while preserving zero-config API-key use and explicitly ordered profile failover. Merge readinessThe PR addresses a current-main auth-planning regression: an environment-only direct credential is appended after declared profiles and can therefore receive traffic the operator did not configure. The authorization fact is carried through the runtime planner, route selector, and availability resolver; the remaining blocker is maintainer acceptance of the deliberate beta-only fallback withdrawal before merge. Priority: P1 Review scores
Verification
How this fits togetherOpenClaw turns provider configuration, stored auth profiles, and discovered credentials into ordered model-auth attempts. Those attempts feed model-route selection, runtime failover, and status availability, so admission must agree across all three surfaces. flowchart LR
A[Provider configuration] --> D[Auth source plan]
B[Stored auth profiles] --> D
C[Environment credentials] --> D
D --> E[Authorization admission]
E --> F[Route-specific attempts]
F --> G[Runtime failover]
E --> H[Status availability]
Decision needed
Why: The implementation is internally consistent and preserves zero-config credentials and declared failover, but it deliberately changes a beta operator fallback path that can affect billing and runtime recovery. Before merge
Agent review detailsSecurityNone. PR surfaceSource +90, Tests +266. Total +356 across 10 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Merge before the 2026.7.2 GA release once the auth owner confirms that explicit profiles, rather than ambient process credentials, are the supported cross-account failover contract. Do we have a high-confidence way to reproduce the issue? Yes, from source: current main appends a direct fallback after usable declared profiles and selects it when those profiles are unavailable. The new focused regression constructs that exact declared-profile plus ambient-key shape, although this read-only review did not execute it. Is this the best way to solve the issue? Yes. The required authorization fact separates policy from credential provenance, keeps declared environment references valid, preserves zero-config use when no profile exists, and prevents route filtering from reintroducing the ambient fallback. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 0fadfc6dae52. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
* origin/main: (54 commits) test(qa): cover agent session streaming (#119028) test(qa): cover sandbox workspace isolation (#119038) test(qa): cover progress followthrough evidence (#119039) fix(auth): cooldown inline api key billing failures (#88709) chore(gateway): cover update and setup RPCs test(qa): prove ClawHub catalog discovery (#118934) chore(qa): cover plugin testing harness contracts (#118933) test(qa): prove failure recovery visibility (#119034) test(qa): cover direct tool invocation (#119025) test(qa): close external app SDK proof gaps (#118978) test(qa): prove container health endpoints (#119012) test(qa): claim sessionless heartbeat coverage (#119027) fix(gateway): keep plugin model allowlists static (#118854) fix(plugins): refresh bundled channel skills (#119020) test(qa): cover ClawHub package compatibility (#118985) test(qa): cover agent session reconnect dedupe (#119013) test(qa): prove gateway chat RPCs (#118988) test(ui): cover Control UI auth transports (#118866) fix(auth): do not admit ambient environment credentials behind declared profiles (#118458) test(ui): cover operator administration flows (#118836) ...
…ed profiles (openclaw#118458) A provider credential present only in the process environment — named in neither the provider entry, `auth.profiles`, nor `auth.order` — was appended to the auth attempt list behind the operator's declared profiles. A run that left a declared profile could therefore continue on an undeclared credential, which may bill a different account, with no configuration authorizing the transition and nothing reporting that it happened. Add an explicit `authorization: "declared" | "ambient"` fact on direct auth sources and enforce it during source selection. The field is required rather than defaulted so every construction site is audited; `evidence` is left as provenance, since a declared credential can legitimately be environment-sourced via a `${VAR}` marker or a SecretRef. An ambient credential may still serve a provider with no declared profiles (the documented zero-config `PROVIDER_API_KEY` path), but it is no longer admitted behind declared profiles, nor substituted for declared profiles that turned out to be unusable. `auth.order` failover is unaffected: profiles are never filtered by this change. The read-only availability evaluator applies the same rule so status cannot advertise a credential the runtime refuses. This restores the invariant that held before e00b05b (openclaw#104685), where an environment candidate was reachable only when a provider had no declared profiles. The regression shipped in 2026.7.2-beta.1 onwards; no GA release is affected. Reported in openclaw#117956. Claude-Session: https://claude.ai/code/session_01Nwk2KaB6zL71xa1i3Xwgwi Co-authored-by: Marvinthebored <[email protected]> Co-authored-by: Claude Opus 5 <[email protected]>
Related: #117956
What Problem This Solves
Fixes an issue where operators who authenticate a provider with a subscription auth profile, and who
also happen to have that provider's API key in their environment for some unrelated named consumer,
could silently have inference billed to the API key instead of their subscription.
The environment variable is never mentioned in their config — not in the provider entry, not in
auth.profiles, not inauth.order. It is picked up purely because it exists in the processenvironment, and it is then queued as a backup credential behind the profiles they did declare. If a
run leaves the declared profile for any reason, it continues on the undeclared credential. Status
keeps reporting the subscription throughout, and nothing warns that the switch happened.
In #117956 this produced metered API usage on an account the operator had not routed anything to. It
was discovered from a billing console, not from any signal in the product.
This is a regression in the 2026.7.2 prereleases. Before
1b1cebfe4218(#104685, 2026-07-11) anenvironment credential was only reachable when a provider had no declared profiles — the documented
zero-config path. It was never queued behind declared profiles:
No GA release is affected.
Why This Change Was Made
Credentials that config never names must not be able to inherit a declared credential's traffic,
because the two can bill different accounts. Moving between them should be something an operator
states, not something the runtime infers from an environment variable being present.
The change adds an explicit
authorization: "declared" | "ambient"fact to direct auth sources andenforces it during source selection. An ambient credential may still serve a provider that has no
declared profiles — the documented zero-config
PROVIDER_API_KEYpath is unchanged — but it is nolonger admitted behind declared profiles, nor substituted for declared profiles that turn out to be
unusable.
Two deliberate design decisions:
authorizationis required, not defaulted. A permissive default is what let an entire module(
model-auth-availability.ts) escape the rule during development. Making the compiler demand itforced every construction site to be audited.
evidencefield.evidenceis provenance — where acredential was found — and is reported as such by status and probe surfaces. It cannot carry
authorization, because a declared credential is legitimately environment-sourced: a
${VAR}markeris reported as
evidence: "environment"while being fully declared.The same classification is applied in the read-only availability evaluator so status cannot advertise
a credential the runtime would refuse.
Non-goals. Failover currently treats a transport-level failure the same as a credential failure
when the harness does not own transport, so a network fault can advance a run to the next prepared
attempt. That is a separate concern from whether a credential should have been eligible at all, and
is left for a follow-up.
User Impact
Operators keep exactly the auth behavior they configured, and stop getting the behavior they did not:
auth.orderfailover is unchanged — every ordered profile is still attempted, in order.PROVIDER_API_KEYis unchanged for providers with no auth profiles.${VAR}marker, SecretRef), setup-provider identities(Vertex/gcloud ADC),
aws-sdkauth, user locks and provider bindings are all unaffected.Behavior that changes, all 2026.7.2-beta only:
PROVIDER_API_KEYused as an unstated backup — the declaredcredential's failure now surfaces instead of switching accounts silently.
models.providers.<id>.authset toapi-key/oauthwith no apiKey material, plus stored profilesand an environment credential —
authalone does not make the environment key declared.rather than quietly serving from that key.
The supported way to express an API-key backup is unchanged and still works: create an API-key auth
profile and add its id to
auth.order.<provider>(docs/concepts/model-failover.md).auth.ordercarries routing metadata only and holds no credential, so the profile must exist first.
Evidence
1. Regression test reproduces the reported configuration and fails on
main.prepare-auth.ambient-credential.test.tsbuilds the config from #117956 (anthropic plugin disabled soclaude-cliresolves as a bare custom provider, one subscription OAuth profile, noauth.order,ANTHROPIC_API_KEYin the environment) and asserts the prepared attempt list.On
main:With this change: passes. The
directentry is the undeclared credential.2. Same comparison, driven from a real host config file rather than a fixture — the affected
operator's
openclaw.jsonwith the plugin disabled and the key present:3. Not provider-specific. The same host also had
OPENAI_API_KEYset alongside a ChatGPT OAuthprofile. Identical exposure, with and without a store-level order override:
4. Declared
auth.orderfailover is preserved — two tests, both with an ambient key deliberatelypresent in the environment:
["openai:primary", "openai:backup"]["openai:chatgpt", "openai:platform"]The second is the configuration this PR recommends to affected operators, so it needed to be pinned.
5. Selector branch coverage in
provider-model-route-auth.test.ts: ambient dropped behind usableprofiles; declared fallback preserved behind usable profiles; ambient preserved with no declared
profiles; ambient not substituted for all-unavailable profiles; ambient not re-admitted when route
filtering empties the profile list.
6. Live gateway. Built and restarted a real gateway on this change, then exercised both routes
through a Discord channel. Normal operation is unaffected — the transcript records
api=cli provider=claude-cli model=claude-opus-5, i.e. the subscription path. Reproducing theincident configuration (plugin disabled, deliberately invalid dummy key in
env.vars) the run stayedon the declared profile —
modelApi: "anthropic-messages"— and completed with no auth error and norotation; the dummy key was never used.
7. Local validation. Typecheck clean, lint clean, 263 tests passing across the auth scope
(planner, selector, resolver, availability, setup-provider, and the new regression file).
Note for reviewers: this change is scoped to admission — which credentials are eligible. It does not
attempt to prove which credential a given run ultimately materializes, since that depends on the
failover behavior listed as a non-goal above.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Nwk2KaB6zL71xa1i3Xwgwi