Skip to content

feat: bind profiles to verified connection identity - #181

Merged
mohanagy merged 3 commits into
developmentfrom
feat/83-verified-identity
Jul 22, 2026
Merged

feat: bind profiles to verified connection identity#181
mohanagy merged 3 commits into
developmentfrom
feat/83-verified-identity

Conversation

@mohanagy

@mohanagy mohanagy commented Jul 22, 2026

Copy link
Copy Markdown
Owner

Summary

  • persist bounded, non-secret identity bindings per exact config/profile/upstream and expose verified, missing, changed, expired, or unavailable state
  • require deterministic explicit or confirmed current-session profile selection for configured risky account-bound operations
  • block expected/observed identity mismatches and unavailable required binding storage with stable redacted diagnostics
  • mirror only coarse identity state onto exact OAuth connection metadata while keeping OAuth validity separate from account identity
  • keep external durable state from silently mutating an active client's in-memory profile selection
  • document persistence, restart/session limits, audit boundaries, and operator configuration

Security notes

  • stores only configured allowlisted identity fields; raw provider output and sensitive errors are not persisted
  • audit omits duplicated persisted evidence and retains bounded/redacted live status
  • file persistence uses restrictive permissions, atomic replacement, and cross-process serialized merge updates
  • protected operations still perform live verification; persisted evidence is visibility, not authorization

Validation

  • npm run test:core — 404 passed, 23 platform-skipped
  • npm run test:coverage — 1,214 passed, 23 platform-skipped; 95.32% statements / 91.73% branches
  • npm run lint
  • npm run typecheck
  • npm run build
  • npm run smoke:cli
  • npm run check:pack
  • npm run test:package — 18 passed
  • focused identity/config/pipeline/OAuth/docs tests — green

The non-coverage aggregate npm test intermittently reproduced the already tracked loaded-suite timing cascades in #117/#122. Every reported file/case passed in isolation, and the complete inventory passed under the coverage run without timeout changes or skipped behavior.

Closes #83

Summary by CodeRabbit

  • New Features

    • Added durable, non-sensitive identity binding status across profiles and OAuth connections.
    • Profile tools now display configured identity state and available binding evidence.
    • Added optional explicit or confirmed profile selection for protected multi-profile actions.
    • Added clear policy errors when selection, confirmation, or identity binding is unavailable.
  • Bug Fixes

    • Prevented persisted evidence from replacing live verification.
    • Prevented external profile changes from silently switching an active session.
  • Documentation

    • Expanded identity, security, configuration, CLI, and OAuth behavior guidance.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 29 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: db53fd9e-3067-4201-ba3b-b14c155b2a38

📥 Commits

Reviewing files that changed from the base of the PR and between 61d5b53 and 6b528ce.

📒 Files selected for processing (7)
  • src/cli/doctor.ts
  • src/mcp/server/miftah-server.ts
  • tests/audit-outcomes.test.ts
  • tests/doctor.test.ts
  • tests/identity-docs-contract.test.ts
  • tests/operation-pipeline.test.ts
  • tests/remote-oauth-runtime.test.ts
📝 Walkthrough

Walkthrough

Identity verification now supports durable bounded evidence, distinct binding states, explicit or confirmed profile selection, redacted audit output, and coarse OAuth identity-state recording. Runtime and CLI initialization load the binding store, while management tools expose non-secret identity information.

Changes

Identity binding and profile selection

Layer / File(s) Summary
Selection configuration and status contracts
src/config/*, src/identity/identity-types.ts, src/utils/errors.ts, src/cli/exit-codes.ts, tests/config.test.ts, tests/cli-exit-codes.test.ts
Adds selectionMode validation, durable binding status fields, audit-safe identity output, and policy error mappings.
File-backed binding persistence and verification
src/identity/identity-binding-store.ts, src/identity/identity-manager.ts, tests/identity-binding-store.test.ts, tests/identity-manager.test.ts
Persists validated bounded evidence atomically, reloads it by configuration fingerprint, tracks expiry/unavailability, and keeps persisted evidence separate from live verification.
Protected profile selection and audit flow
src/mcp/server/operation-pipeline.ts, tests/operation-pipeline.test.ts, tests/profile-state.test.ts, tests/plugin-routing-pipeline.test.ts, tests/profile-lease-pipeline.test.ts
Requires explicit or confirmed current-session profile selection for configured protected operations and records redacted identity audit data.
OAuth, server, and runtime integration
src/mcp/server/*, src/oauth/*, src/runtime/*, src/cli/doctor.ts, tests/mcp-wrapper.test.ts, tests/remote-oauth-runtime.test.ts, tests/runtime-config-resolution.test.ts
Shares initialized identity management with runtime/server paths, exposes profile identity status, and records mapped coarse identity states on OAuth connections.
Documentation and contract coverage
docs/*.md, CHANGELOG.md, tests/identity-docs-contract.test.ts
Documents live versus durable identity state, persistence boundaries, selection modes, restart behavior, and protected-request requirements.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant MiftahServer
  participant OperationPipeline
  participant IdentityManager
  participant RemoteOAuthRuntime
  Client->>MiftahServer: request identity verification or protected operation
  MiftahServer->>OperationPipeline: execute with identity status callback
  OperationPipeline->>IdentityManager: verify identity and enforce profile selection
  IdentityManager-->>OperationPipeline: live status and binding state
  OperationPipeline->>RemoteOAuthRuntime: record coarse identity state
  OperationPipeline-->>MiftahServer: result and redacted audit status
  MiftahServer-->>Client: response
Loading

Possibly related PRs

  • mohanagy/miftah#61: Adds the upstream identity verification flow extended here with durable bindings and selection modes.
  • mohanagy/miftah#70: Shares IdentityManager verification-flow changes and options.
  • mohanagy/miftah#179: Provides the OAuth runtime foundation extended with identity-state recording.

Poem

I’m a bunny with bindings, neat and bright,
Saving safe proof through the night.
Pick your profile, confirm it true,
No stale account will hop through.
OAuth states now gently glow—
Audit trails keep secrets low.


Caution

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

  • Ignore

❌ Failed checks (1 error)

Check name Status Explanation Resolution
Docstring Coverage ❌ Error Docstring coverage is 16.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: binding profiles to verified connection identity.
Description check ✅ Passed The description covers summary, security notes, and validation with concrete results, which is mostly aligned with the template.
Linked Issues check ✅ Passed The changes satisfy #83 by adding bounded identity binding, explicit/confirmed selection, fail-closed mismatches, and audit-safe visibility.
Out of Scope Changes check ✅ Passed The code, docs, and tests all support the identity-binding objective; no clear unrelated changes stand out.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/83-verified-identity

Comment @coderabbitai help to get the list of available commands.

coderabbitai[bot]
coderabbitai Bot previously requested changes Jul 22, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/cli/doctor.ts`:
- Around line 469-472: Update runDoctor’s IdentityManager setup to canonicalize
the configuration path with realpath, matching createRuntime before passing it
to defaultIdentityBindingPath. Preserve the existing identity initialization
flow and add a regression test covering a symlinked configuration file so doctor
and runtime use the same binding file.

In `@src/cli/exit-codes.ts`:
- Around line 41-42: Update MiftahServer.auditStatus to recognize
PROFILE_IDENTITY_SELECTION_REQUIRED as “denied” like PROFILE_SELECTION_REQUIRED,
and PROFILE_IDENTITY_CONFIRMATION_REQUIRED as “confirmation-required” like
PROFILE_SWITCH_CONFIRMATION_REQUIRED, while preserving existing audit
classifications.

In `@src/mcp/server/miftah-server.ts`:
- Around line 3054-3071: Update oauthIdentityState so an unconfigured identity
returns OAuth state "unsupported" even when status.bindingState is
"unavailable"; distinguish the unconfigured status before the bindingState early
return, while preserving existing binding-state handling for other statuses.

In `@tests/identity-docs-contract.test.ts`:
- Around line 88-96: Update the status extraction assertions in the identity
documentation contract test to validate verificationStatuses and bindingStatuses
independently, asserting each is non-empty before combining them into statuses.
Preserve the existing security documentation check after both extraction checks
pass.

In `@tests/remote-oauth-runtime.test.ts`:
- Around line 224-228: Update the assertion following recordIdentityState in the
OAuth runtime test to compare the complete expected metadataStore.records set,
including the target profile, upstream, connection reference, and changed
identityState. Include unchanged unrelated records so the test verifies the
exact connection was updated and no other records were modified.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: ba7844e4-2a9f-4df5-b443-445f97a7db43

📥 Commits

Reviewing files that changed from the base of the PR and between 9be6181 and 61d5b53.

📒 Files selected for processing (36)
  • CHANGELOG.md
  • docs/architecture.md
  • docs/cli.md
  • docs/config.md
  • docs/library-api.md
  • docs/oauth-support.md
  • docs/security.md
  • docs/threat-model.md
  • src/cli/doctor.ts
  • src/cli/exit-codes.ts
  • src/config/schema.ts
  • src/config/types.ts
  • src/identity/identity-binding-store.ts
  • src/identity/identity-manager.ts
  • src/identity/identity-types.ts
  • src/mcp/server/management-tools.ts
  • src/mcp/server/miftah-server.ts
  • src/mcp/server/operation-pipeline.ts
  • src/oauth/connection-registry.ts
  • src/oauth/connection-types.ts
  • src/oauth/remote-oauth-runtime.ts
  • src/runtime/create-miftah-runtime.ts
  • src/runtime/create-runtime.ts
  • src/utils/errors.ts
  • tests/cli-exit-codes.test.ts
  • tests/config.test.ts
  • tests/identity-binding-store.test.ts
  • tests/identity-docs-contract.test.ts
  • tests/identity-manager.test.ts
  • tests/mcp-wrapper.test.ts
  • tests/operation-pipeline.test.ts
  • tests/plugin-routing-pipeline.test.ts
  • tests/profile-lease-pipeline.test.ts
  • tests/profile-state.test.ts
  • tests/remote-oauth-runtime.test.ts
  • tests/runtime-config-resolution.test.ts

Comment thread src/cli/doctor.ts
Comment thread src/cli/exit-codes.ts
Comment thread src/mcp/server/miftah-server.ts
Comment thread tests/identity-docs-contract.test.ts
Comment thread tests/remote-oauth-runtime.test.ts
@mohanagy
mohanagy dismissed coderabbitai[bot]’s stale review July 22, 2026 13:21

All five findings were fixed in 6596dc2 and 6b528ce, replied to, and resolved. Current-head CI and CodeRabbit status are green; CodeRabbit reports the rerun as rate-limited. Local Claude Opus and Fable review attempts were bounded but stalled without output, so this stale historic review is dismissed under the documented rate-limit exception.

@mohanagy
mohanagy merged commit 64c9755 into development Jul 22, 2026
12 checks passed
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.

[Safety] Bind profiles to verified connection identity and prevent ambiguous account use

1 participant