Skip to content

feat(auth): introduce unified identity core and provider authority lock #640

Description

@XiaoSeS

Background

Implement P1 / PR 1 from #628 and docs/21-unified-identity-federation-design.md after the P0 authentication hardening work.

The current OAuth/OIDC login path is centered on OAuthClaims, while account-state checks and PlatformPrincipal construction are duplicated across external and local login. Provider codes are also not pinned to a stable identity authority.

Scope

  • Add the unified identity core value model:
    • ProviderAuthenticationResult
    • core-owned IdentityAssertionFactory / IdentityAssertion
    • ProviderReference, typed ExternalSubject
    • EmailAssurance, AuthenticationEvidence
    • IdentityLoginOutcome
  • Add trusted provider route/descriptor resolution for the existing GitHub, GitLab, and OIDC client registrations.
  • Add ProviderAuthorityLockService and the additive identity_provider_state Flyway migration.
  • Enforce database compare-and-set authority pinning, sticky mismatch, and same-authority explicit recovery.
  • Filter AuthMethodCatalog through the trusted descriptor and persisted authority state.
  • Add shared AccountLoginGuard and PlatformPrincipalFactory.
  • Migrate GitHub/GitLab/OIDC login to ExternalIdentityLoginService.
  • Reuse the shared guard and principal factory from local password login.
  • Keep the current identity_binding table and existing provisioning behavior for compatibility.
  • Keep session creation outside the identity transaction and only accept Authenticated outcomes.

Explicitly out of scope

  • LDAP, DingTalk, CAS, SAML, SCIM, trusted-header adapters
  • Binding V2 / persisted typed subject aliases
  • Dynamic provider registry or runtime plugins
  • Full profile sync and provisioning policy redesign
  • PlatformPrincipal schema changes

Security invariants

  • Provider code, protocol, authority, subject rules, and attribute mappings come only from a trusted server-side descriptor.
  • Adapter results cannot select a platform account, role, provider code, authority, or session.
  • Authority fingerprint is lowercaseHex(SHA-256(UTF-8(protocol + "\\n" + canonicalAuthority))).
  • Authority mismatch fails closed and remains sticky until explicit same-fingerprint recovery or a future audited migration.
  • Primary subject is required, typed, bounded, and descriptor-allowed.
  • Non-empty aliases fail closed until Binding V2.
  • PENDING, DISABLED, MERGED, and system accounts cannot establish an interactive session.
  • Tokens, tickets, cookies, credentials, and raw upstream responses never enter the assertion or ordinary audit data.

Acceptance criteria

  • Trusted descriptor source rejects unknown/ambiguous providers and authority.
  • Fixed authority fingerprint vectors pass.
  • First pin, concurrent same-authority pin, restart mismatch, sticky mismatch, and explicit same-authority recovery are tested against compare-and-set behavior.
  • Invalid/missing/oversized primary subjects and non-empty aliases fail closed.
  • Existing GitHub, GitLab, and generic OIDC login behavior remains compatible.
  • Local login uses the shared account guard and principal factory.
  • Only IdentityLoginOutcome.Authenticated reaches PlatformSessionService.
  • Existing OAuth bindings remain readable and rollback-compatible.
  • Relevant backend tests, frontend checks, migration/startup validation, and staging smoke checks pass before merge.

Integration policy

Develop and validate on big-main first. Do not merge directly to main; create a clean-main PR only after prerequisite P0/design commits are present on main and origin/main..HEAD contains only this issue's commits.

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