Add Authelia identity bridge for NextAuth sessions
release gate / check (push) Failing after 6m40s

Keep NextAuth as the OIDC/session layer and add a trusted Go provisioning endpoint that maps verified Authelia subjects to local users. Existing password accounts require explicit admin linking; new users are provisioned without a password. Enable the Authelia login path and update docs. Also fix test schema search_path so pg_trgm opclasses resolve.
This commit is contained in:
Andrew S Erwin
2026-10-22 12:39:39 -05:00
parent d870eece1e
commit c432ff57e9
16 changed files with 796 additions and 150 deletions
+34 -27
View File
@@ -151,11 +151,12 @@ install it); the index-backed page search depends on it.
### Connecting Authelia (OIDC)
**Authelia sign-in is currently stubbed. Connecting it requires both server
configuration and developer integration; setting environment variables alone
does not enable it.** Email/password sign-in works while that integration is
pending. The full [Authelia connection guide](web/docs/AUTHELIA.md) includes
the client registration example and the implementation handoff.
Authelia is the primary sign-in path when configured. The trusted Next.js
server handles the OIDC authorization-code flow, validates the ID token, and
then exchanges the verified identity for a local Go user. Email/password
sign-in remains available as a fallback. The full
[Authelia connection guide](web/docs/AUTHELIA.md) includes the client
registration example and the identity-mapping details.
#### 1. Register the app in Authelia
@@ -187,30 +188,35 @@ OIDC_CLIENT_SECRET=<plain-client-secret>
Serve the web app through an HTTPS reverse proxy; the default Docker ports
bind to localhost. Keep your existing `AUTH_SECRET` unchanged. Apply the
environment changes with `docker compose up -d`, then check **Settings → OIDC**.
It will report that the variables are configured but integration is pending.
The login button remains disabled at this stage.
environment changes with `docker compose up -d --build`, then check
**Settings → OIDC**. When all three variables hold real values, the Authelia
button is enabled.
#### 3. Complete the developer integration
#### 3. How identity mapping works
The trusted Next.js server owns OIDC verification and the callback. The
remaining work is to:
The Next server owns OIDC verification and the callback. After Authelia returns
a verified identity, NextAuth's `jwt` callback calls the Go API's
`POST /api/auth/oidc/identity` endpoint with a short-lived service token
(`typ=oidc-provision`). Go resolves the OIDC subject to a local `User` through
the `Account` table:
1. Implement Go-backed lookup/provisioning of a local `User` and `Account`
for the verified Authelia identity. A provisioning endpoint is not yet
supplied; any new endpoint must authenticate the trusted Next server.
2. Update `web/auth.ts` to resolve the verified identity to the local
`User.id` and permit sign-in only after that succeeds. The session and
API assertion must use this local ID, not Authelia's `sub` claim. Existing
accounts need an explicit, verified account-linking policy.
3. Enable the readiness gate in `web/app/login/client.tsx` after mapping works,
rebuild with `docker compose up -d --build`, and verify sign-in, first-login
provisioning, returning users, and Go-backed data access.
- An existing provider link is authoritative.
- A matching local account with no password may be linked when Authelia asserts
a verified email.
- A matching local **password** account returns `409 Account link required`.
Email alone is not proof of identity; an administrator links it explicitly
with `POST /api/admin/oidc-link` (`{userId,subject}`).
- Otherwise Go creates a password-less local user. The first external user on a
fresh installation follows the same bootstrap-admin rules as signup.
The Go OIDC login/callback handlers in `internal/oidc/provider.go` deliberately
return **501**. They are not the NextAuth callback implementation. Config status
(including an `enabled` flag) indicates that values are present, not that an
end-to-end login has been implemented.
The NextAuth session and every API assertion use the **local** `User.id`, never
Authelia's `sub` claim. A Go `tokenVersion` bump on sign-out revokes both the
NextAuth-backed assertions and Go cookie sessions.
The Go OIDC login/callback handlers in `internal/oidc/provider.go` remain 501
stubs. They are not the NextAuth callback implementation; the Next server drives
the flow. Config status (including an `enabled` flag) indicates that values are
present, not that Go itself runs an OIDC client.
## Developer commands
@@ -307,8 +313,9 @@ separate accounts.
Current integration boundaries:
- Authelia still requires the developer identity-mapping work described above;
use email/password for this test build.
- Authelia is the primary sign-in path when configured; email/password remains
a fallback. Existing password accounts require explicit linking to an
Authelia identity.
- IMAP and Nextcloud require the client's own service credentials.
- Alerts are browser-only and checked every five minutes while the app is open.
- Page autosave needs an API connection. Check the save indicator; use **Save