Skip to content

feat(auth): add managed OAuth login custody - #153046

Open
kevinslin wants to merge 10 commits into
mainfrom
dev/kevinlin/oce-managed-oauth-login
Open

kevinslin wants to merge 10 commits into
mainfrom
dev/kevinlin/oce-managed-oauth-login

Conversation

@kevinslin

@kevinslin kevinslin commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

OpenClaw needs a managed OAuth login runtime that can commit an Agent-owned profile without changing user defaults, leaking credentials, or racing against a changed stored profile.

Related OCE consumer: openclaw/openclaw-enterprise#252.

User Impact

User impact: OpenClaw Enterprise can call a supported managed-login SDK surface from an isolated Agent runtime, provided the deployment selects an immutable image built from this change.

This does not change the normal interactive login path. It does not publish or select a default OCE runtime image.

Why This Change Was Made

This adds the narrow runManagedModelsAuthLoginFlow facade and fences the native persistence path needed by OCE OAuth activation:

  • Exports openclaw/plugin-sdk/provider-auth-managed-login-runtime and documents the SDK runtime surface.
  • Adds an explicit supported-version marker and rejects facade calls that do not provide managed mode. Lifecycle authority remains with the native caller through beforePersist and assertCurrent.
  • Runs provider login from supplied config and isolated state, ignoring configured credential-directory overrides. It suppresses ambient Gateway refresh unless the caller supplies a refresh callback, and makes no config/default promotion.
  • Gives the managed persistence callback the transaction-current profile data before SQLite replacement, so reconnects can reject account/profile changes while first-time consent can create the profile. Cancellation is rechecked at that same write boundary after asynchronous handoff and lock waits.
  • Preserves valid refresh tokens when provider responses omit rotation, bounds token-response reads, and prefers usable token claims for OpenAI account matching before stored metadata.

Evidence

  • Scoped correctness, simplicity, and test-quality review found no remaining P0-P2 findings in the final fix delta.
  • Focused auth Vitest passed across the command, managed-flow, public SDK facade, and real-store provider-resolution suites. The real-store case proves configured and ambient credential stores remain unchanged while the managed transaction rejects a changed owner.
  • Managed SDK facade and OpenAI provider contract tests passed; previous refresh/persistence coverage remains applicable to unchanged code.
  • Public managed SDK to real SQLite proof covers allowed completion, cancelled handoff, revoked ownership, and transaction-current account mismatch while preserving configured external and ambient credential stores. The cancellation regression failed before the guard fix and passed afterward.
  • Existing OpenAI matcher coverage verifies that profiles without stored userId can match using usable account/user claims in their access token, while profiles lacking a usable user identity fail closed. An OpenAI extension case verifies the supported older row using the actual matcher and real SQLite seed/write/readback. The separate core public-SDK case verifies the managed transaction guard with a provider fixture.
  • SDK surface/export/declaration checks, core TypeScript, affected core-test type stripes, exact CI line-cap ratchet, export-name collision checks, and touched formatting passed.
  • Follow-up CI fixes isolate shared login types to remove an import cycle and satisfy the assertion-safety and core lint checks. Provider-specific legacy-profile proof lives in the OpenAI extension contract suite so core command tests stay independent of bundled extension code. After relocation, the affected core lint stripe and OpenAI extension lint also passed.
  • CI maintenance splits the existing gateway talk tests into their own TypeScript shard after merging main, preserving exactly-once coverage and the existing 700-root cap.
  • The earlier local image predates the final SDK export alignment. A compatible immutable image must be rebuilt and verified from the final native source; no published/default image is claimed.

Not yet proved here: live provider authorization, refresh after real provider rotation, restart with live refreshed credentials, or provider-side revocation. Those remain OCE/live-provider acceptance gaps.

@clawsweeper

clawsweeper Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-19T17:06:20.852146Z ca43885 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components. This comment is informational because the PR author has repository Maintain or Admin access.

  • Current SHA: 314758d46ef4db2deb4084f2c44ee81573fac461
  • Maintainer: @kevinslin
  • Repository role: maintain

These security sensitive changes were made:

  • src/agents/auth-profiles/credential-schema.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/store-read-helpers.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/store.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/upsert-with-lock.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.

Carefully review these changes before merging.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ca43885a6b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/commands/models/auth.ts Resolved
Comment thread src/commands/models/auth.ts Resolved
Comment thread src/commands/models/auth.ts Resolved
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 19, 2026
@clawsweeper

clawsweeper Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 19, 2026, 3:25 PM ET / 19:25 UTC (Revision 7).

ClawSweeper review

What this changes

Adds a public SDK operation for host-managed OAuth login that saves isolated credentials, preserves defaults, and checks current ownership and account identity before replacement.

Merge readiness

✅ Ready for maintainer review

This maintainer-sponsored PR remains useful: inspected main lacks the managed login contract. The earlier isolation and cancellation findings are addressed, and no remaining blocking defect was identified.

Priority: P2
Reviewed head: 314758d46ef4db2deb4084f2c44ee81573fac461

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused managed-auth contract with meaningful persistence proof and resolved prior findings.
Proof confidence 🐚 platinum hermit (4/6) ✨ media proof bonus Sufficient (linked_artifact): The reported after-fix public-SDK harness exercises actual provider discovery and SQLite persistence with injected ownership changes, proving allowed replacement and rejection of cancellation, revocation, and transaction-current account mismatch. This satisfies the native custody boundary; it does not establish live provider or deployment acceptance.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The reported after-fix public-SDK harness exercises actual provider discovery and SQLite persistence with injected ownership changes, proving allowed replacement and rejection of cancellation, revocation, and transaction-current account mismatch. This satisfies the native custody boundary; it does not establish live provider or deployment acceptance.
Evidence reviewed 9 items Review continuity: Comparison with the previous reviewed head shows only the gateway-talk TypeScript shard registration and matching include/exclude changes; production authentication code is unchanged.
Still necessary on inspected main: Main's core login entry still delegates directly to the interactive flow. Searches found no managed runner or managed.v1 contract, and tree checks found no managed SDK facade in either fetched main or v2026.9.5.
Managed isolation and final-write authority: The flow derives credential storage from the supplied state root, uses a supplied config snapshot, and skips ambient Gateway refresh. Its persistence callback checks cancellation and current ownership, then compares account identity against the transaction-current profile before replacement.
Findings None None.
Security None None.

How this fits together

Provider login converts browser consent into stored credentials used by OpenClaw agents. The managed flow lets a host supply lifecycle authority and an isolated storage root, then receive credential metadata without token material.

flowchart TD
  A[Host login request] --> B[Validate explicit managed inputs]
  B --> C[Provider OAuth flow]
  C --> D[Host ownership handoff]
  D --> E[Check cancellation and current account]
  E -->|Allowed| F[Commit isolated SQLite credentials]
  E -->|Rejected| G[Preserve existing credentials]
  F --> H[Return metadata to host]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +472, Tests +1012, Docs +49, Config +4, Other +9. Total +1546 across 34 files.

View PR surface stats
Area Files Added Removed Net
Source 15 694 222 +472
Tests 13 1045 33 +1012
Docs 2 49 0 +49
Config 1 4 0 +4
Generated 0 0 0 0
Other 3 12 3 +9
Total 34 1804 258 +1546

Review metrics

Metric Value Why it matters
Contract expansion 1 public SDK entry point; 1 optional persisted identity field The documented host integration and legacy-row coverage make the added contract explicit.
Production versus test growth Production +472 net lines; tests and test support +1,000 net lines Production growth implements managed custody and shared flow extraction; most net growth supplies boundary and compatibility coverage.

Technical review

Best possible solution:

Keep one provider-login and credential-persistence owner, with host-managed custody enforced at the final write and deployment acceptance handled by the consuming host.

Do we have a high-confidence way to reproduce the issue?

Not applicable as a feature request. The prior cancellation defect has a recorded failing-before/passing-after regression through the public SDK and real SQLite store; no tests were executed during this read-only review.

Is this the best way to solve the issue?

Yes. The narrow facade reuses existing provider and persistence owners, preserves interactive behavior, and checks host authority against current stored credentials before replacement.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against ba113dc71191.

Labels

Label justifications:

  • P2: This is a bounded host-managed authentication capability, with no demonstrated urgent regression in existing login workflows.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): The reported after-fix public-SDK harness exercises actual provider discovery and SQLite persistence with injected ownership changes, proving allowed replacement and rejection of cancellation, revocation, and transaction-current account mismatch. This satisfies the native custody boundary; it does not establish live provider or deployment acceptance.
  • proof: sufficient: Contributor real behavior proof is sufficient. The reported after-fix public-SDK harness exercises actual provider discovery and SQLite persistence with injected ownership changes, proving allowed replacement and rejection of cancellation, revocation, and transaction-current account mismatch. This satisfies the native custody boundary; it does not establish live provider or deployment acceptance.

Evidence

What I checked:

  • Review continuity: Comparison with the previous reviewed head shows only the gateway-talk TypeScript shard registration and matching include/exclude changes; production authentication code is unchanged. (scripts/lib/tsgo-core-test-shards.mts:82, 314758d46ef4)
  • Still necessary on inspected main: Main's core login entry still delegates directly to the interactive flow. Searches found no managed runner or managed.v1 contract, and tree checks found no managed SDK facade in either fetched main or v2026.9.5. (src/commands/models/auth.ts:1090, ba113dc71191)
  • Managed isolation and final-write authority: The flow derives credential storage from the supplied state root, uses a supplied config snapshot, and skips ambient Gateway refresh. Its persistence callback checks cancellation and current ownership, then compares account identity against the transaction-current profile before replacement. (src/commands/models/auth-managed-login.ts:123, 314758d46ef4)
  • Production-boundary authority proof: The inspected harness enters through the public managed SDK, discovers a fixture provider, and uses real credential persistence and SQLite readback. It covers allowed replacement, cancellation during handoff, revoked ownership, and an intervening account change while checking that ambient and configured stores remain unchanged. The supplied author comment reports the cancellation case failing before the guard fix and passing afterward; this review did not execute tests. (src/commands/models.auth.provider-resolution.test.ts:229, 314758d46ef4)
  • Existing credential compatibility: The optional userId metadata field is retained by the existing credential decoder. The OpenAI extension test seeds an older credential without userId, applies the actual account matcher using token claims, replaces it through the real store, and reads it back. Ordinary login retains its existing branch. (extensions/openai/provider-auth.contract.test.ts:62, 314758d46ef4)
  • Documented trust boundary and review disposition: The maintainer's supplied review reply explains that the capability string is compatibility metadata and that the native caller owns lifecycle authorization. This matches SECURITY.md's trusted installed-plugin model and the new SDK documentation. The concrete storage, config-read, and Gateway-refresh findings were separately repaired. (SECURITY.md:151, 314758d46ef4)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • obviyus: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (6 earlier review cycles)
  • reviewed 2026-09-19T17:38:05.464Z sha 16846cd :: needs real behavior proof before merge. :: [P2] Recheck cancellation at the managed credential write boundary
  • reviewed 2026-09-19T17:57:18.360Z sha 863aac9 :: needs real behavior proof before merge. :: [P2] Recheck cancellation at the managed credential write boundary
  • reviewed 2026-09-19T18:08:31.996Z sha 8a16e05 :: blocked before merge. :: none
  • reviewed 2026-09-19T18:35:25.801Z sha 786ac96 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-19T18:48:02.102Z sha 68d6590 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-19T19:13:39.639Z sha 20dd622 :: needs maintainer review before merge. :: none

@kevinslin

Copy link
Copy Markdown
Contributor Author

Addressed the cancellation finding and scoped proof gaps in 8a16e05.

The managed final-write callback now checks the supplied AbortSignal immediately before the existing ownership/account guard and SQLite replacement. Cancellation during handoff or a persistence lock wait therefore cannot leave credential-write authority active.

The regression in src/commands/models.auth.provider-resolution.test.ts enters through the public managed SDK with an isolated test provider and the real native credential store. It verifies allowed completion, cancellation during beforePersist, revoked ownership, transaction-current account mismatch, and unchanged ambient/configured external stores. Before the source fix, the cancellation case failed with promise resolved ... instead of rejecting; after the fix, the selected case passed. The combined focused auth/SDK suites also passed.

A separate real-store case seeds an OpenAI row without stored userId, uses the actual OpenAI OAuth matcher with usable JWT account/user claims, passes through the managed transaction guard, and verifies replacement by native-store readback. That selected case passed. This preserves the existing fail-closed behavior when neither token claims nor stored metadata establishes the user identity; it adds no compatibility fallback.

Core TypeScript, the affected core-test stripe 4/5, assertion-safety and line-cap ratchets, formatting, and independent review/verification passed. The PR description now records this evidence. Genuine provider consent/refresh/restart/revocation and rebuilding the final compatible image remain explicitly pending; these local tests do not claim that live proof.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 19, 2026
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Sep 19, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling commands Command implementations docs Improvements or additions to documentation extensions: openai maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. plugin: file-transfer proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts security-sensitive-changed size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant