Repository navigation
feat(hub): establish provider-neutral identity persistence #118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
940d1a1
feat(hub): persist identity records and credentials
Copilot b80ec6d
feat(hub): establish provider-neutral identity persistence
ebcd4c6
fix(hub): harden authentication state handling
980be2d
fix(hub): evaluate attempt expiry after lock
738dc31
fix(hub): address identity foundation review
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # Hub identity | ||
|
|
||
| Hub persists a provider-neutral identity foundation. User authentication proves an external identity. Hub installation membership records whether that user belongs to this Hub and whether they are an administrator. This persistence layer does not define prototype access rules. | ||
|
|
||
| ## Persisted boundaries | ||
|
|
||
| - `User` is the Hub-owned account. It does not contain a provider identifier or administrator flag. | ||
| - `ExternalIdentity` links a provider, issuer, and subject to one Hub user. One user may link several identities. The issuer is part of uniqueness so separate OIDC tenants may reuse subjects safely. | ||
| - `InstallationMembership` stores a user's status, role, and source for this Hub installation. | ||
| - `AuthenticationProvider` and its versioned revisions store authentication configuration without tying it to one provider. An OIDC configuration does not require GitHub source credentials. | ||
| - `Session` records the Hub user, external identity, and authentication provider revision that established it. Rotating GitHub source credentials does not change session identity context. | ||
| - `AuthorizationAttempt` stores digested state and browser bindings, a PKCE verifier, an optional OIDC nonce, provider revision, purpose, optional originating session, and expiry. Consumption deletes the record in the same transaction so concurrent callbacks cannot reuse it. | ||
| - `SecurityAudit` stores the event and minimal optional identity context. | ||
|
|
||
| Queries are available without a lock. Mutations run through one database transaction that locks a fixed store row. Related records and audit events therefore commit or roll back together, and overlapping mutations observe committed state. | ||
|
|
||
| Security audit queries return at most 100 records from the previous 90 days. Each new audit write deletes records older than 90 days. Operators who require a longer security history must export records before that limit. | ||
|
|
||
| ## GitHub source credentials | ||
|
|
||
| GitHub source access is an optional integration boundary, not the global identity boundary. Set `HUB_GITHUB_CREDENTIAL_PROVIDER` in the [environment example](../.env.example): | ||
|
|
||
| | Provider | Credentials | | ||
| | --- | --- | | ||
| | `database` (default) | Generate `HUB_GITHUB_CREDENTIAL_KEY` with `openssl rand -hex 32`. The provider encrypts GitHub integration credentials before storage and authenticates their context when reading. | | ||
| | `environment` | Set every `GITHUB_*` value, including `GITHUB_INSTALLATION_ID`. This provider is read-only and ignores database credentials. | | ||
|
|
||
| Both providers currently validate an App ID, installation ID, client ID, client secret, and RSA private key. IDs are positive decimal strings. The key must contain at least 2048 bits. | ||
|
|
||
| Database credentials use AES-256-GCM with contextual additional authenticated data. Keep the encryption key outside the database and back it up separately. Losing or replacing it makes saved credentials unreadable. Invalid provider settings or unreadable ciphertext cause errors. Hub never falls back to another provider. | ||
|
|
||
| ## Foundation scope | ||
|
|
||
| This layer provides persistence only. It does not add HTTP sign-in routes, production OIDC or SCIM flows, prototype or product models, an authorization evaluator, GitHub permission synchronization, artifact ingestion, or UI. GitHub authentication configuration and GitHub source credentials remain separate so either capability can change without redefining Hub identity. | ||
|
|
||
| Apply the rewritten initial migration with `npm run db:deploy`. See [Database](database.md) for setup and schema rules. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| model AuthenticationProviderRevision { | ||
| // ID columns | ||
| id String @id @default(uuid()) @db.Uuid | ||
| authenticationProviderId String @map("authentication_provider_id") @db.Uuid | ||
|
|
||
| // Relations | ||
| authenticationProvider AuthenticationProvider @relation(fields: [authenticationProviderId], references: [id], onDelete: Cascade) | ||
| authorizationAttempts AuthorizationAttempt[] | ||
| sessions Session[] | ||
|
|
||
| // Attribute columns | ||
| revision Int | ||
| issuer String | ||
| configuration Json | ||
|
|
||
| // Timestamp columns | ||
| createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3) | ||
| updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz(3) | ||
|
|
||
| @@unique([authenticationProviderId, revision]) | ||
| @@index([issuer]) | ||
| @@map("authentication_provider_revisions") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| model AuthenticationProvider { | ||
| // ID columns | ||
| id String @id @default(uuid()) @db.Uuid | ||
|
|
||
| // Relations | ||
| revisions AuthenticationProviderRevision[] | ||
|
|
||
| // Attribute columns | ||
| key String @unique | ||
| type String | ||
| enabled Boolean @default(true) | ||
|
|
||
| // Timestamp columns | ||
| createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3) | ||
| updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz(3) | ||
|
|
||
| @@map("authentication_providers") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| model AuthorizationAttempt { | ||
| // ID columns | ||
| id String @id @default(uuid()) @db.Uuid | ||
| authenticationProviderRevisionId String @map("authentication_provider_revision_id") @db.Uuid | ||
| originatingSessionId String? @map("originating_session_id") @db.Uuid | ||
|
|
||
| // Relations | ||
| authenticationProviderRevision AuthenticationProviderRevision @relation(fields: [authenticationProviderRevisionId], references: [id], onDelete: Cascade) | ||
| originatingSession Session? @relation("OriginatingSession", fields: [originatingSessionId], references: [id], onDelete: Cascade) | ||
|
|
||
| // Attribute columns | ||
| stateDigest String @unique @map("state_digest") | ||
| browserDigest String @map("browser_digest") | ||
| pkceVerifier String @map("pkce_verifier") | ||
| nonce String? | ||
| purpose String | ||
| expiresAt DateTime @map("expires_at") @db.Timestamptz(3) | ||
|
|
||
| // Timestamp columns | ||
| createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3) | ||
| updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz(3) | ||
|
|
||
| @@index([expiresAt]) | ||
| @@index([authenticationProviderRevisionId]) | ||
| @@index([originatingSessionId]) | ||
| @@map("authorization_attempts") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| model ExternalIdentity { | ||
| // ID columns | ||
| id String @id @default(uuid()) @db.Uuid | ||
| userId String @map("user_id") @db.Uuid | ||
|
|
||
| // Relations | ||
| user User @relation(fields: [userId], references: [id], onDelete: Cascade) | ||
| sessions Session[] | ||
|
|
||
| // Attribute columns | ||
| provider String | ||
| issuer String | ||
| subject String | ||
| username String? | ||
| displayName String? @map("display_name") | ||
| avatarUrl String? @map("avatar_url") | ||
|
|
||
| // Timestamp columns | ||
| createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3) | ||
| updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz(3) | ||
|
|
||
| @@unique([provider, issuer, subject]) | ||
| @@index([userId]) | ||
| @@map("external_identities") | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.