Skip to content

feat(auth): add Binding V2 typed subjects and safe migration gates #645

Description

@XiaoSeS

Context

Follow-up to #628 and #640. The unified identity core still stores the external subject in the legacy untyped identity_binding.subject column, which cannot safely represent typed aliases or concurrent migration.

Authoritative design: docs/21-unified-identity-federation-design.md, PR 2.

Scope

  • Add identity_binding_subject with typed primary/alias subjects, status and timestamps.
  • Preserve legacy reads and dual writes during the mixed-version window.
  • Backfill legacy bindings and reject unsafe or ambiguous rows before contract activation.
  • Enforce exactly one active primary subject per active binding in a separate Contract migration.
  • Fail closed when aliases resolve to different bindings or legacy and typed lookups disagree.
  • Cover concurrent first login, rolling upgrade and rollback to the PR 1-compatible version.

Rollout

This issue intentionally requires two ordered PRs:

  1. Expand + backfill/preflight.
  2. Contract gate after Expand validation and old-Pod retirement checks.

Acceptance

  • Real PostgreSQL migration and concurrency tests pass repeatedly.
  • Existing OAuth bindings upgrade without changing their legacy subject.
  • Mixed-version reads/writes remain compatible during Expand.
  • Contract rejects zero or multiple active primary subjects.
  • Rollback evidence proves the PR 1-compatible image can read Expand data before revocation semantics are used.
  • Both PRs are validated through big-main; neither goes directly to main.

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/m中等改动,存在一定协同成本 / Medium change with noticeable coordination cost.priority/p1高优先级 / High priority triage bucket.risk/high涉及安全、鉴权、迁移或公共契约 / Touches security, auth, migrations, or public contracts.triage/needs-info需要补充更多信息后才能分流 / Issue needs more detail before it can be routed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions