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
+39
View File
@@ -10,6 +10,7 @@ import (
"github.com/andrew/superbrain/internal/handlers"
"log"
"net/http"
"strings"
"time"
)
@@ -97,6 +98,44 @@ func HandleAdminPatchUser(w http.ResponseWriter, r *http.Request) {
log.Printf("audit: admin %s changed role of %s: %s -> %s", s.RealID, b.UserID, target.Role, b.Role)
handlers.WriteJSON(w, 200, handlers.OK{OK: true})
}
// HandleAdminLinkOIDC explicitly links an existing local account to an
// Authelia subject. This is the operator escape hatch for an account that
// already has a password: the provisioning bridge deliberately refuses to
// auto-link those by email alone.
func HandleAdminLinkOIDC(w http.ResponseWriter, r *http.Request) {
var b struct {
UserID string `json:"userId"`
Subject string `json:"subject"`
}
if json.NewDecoder(http.MaxBytesReader(w, r.Body, 4096)).Decode(&b) != nil {
handlers.WriteJSON(w, 400, handlers.Error{Error: "Invalid JSON"})
return
}
b.UserID = strings.TrimSpace(b.UserID)
b.Subject = strings.TrimSpace(b.Subject)
if b.UserID == "" || b.Subject == "" || len(b.Subject) > 255 {
handlers.WriteJSON(w, 400, handlers.Error{Error: "Invalid link"})
return
}
s, _ := auth.SessionFromContext(r.Context())
e := db.NewUserRepo(db.FromContext(r.Context())).LinkExternal(r.Context(), b.UserID, "authelia", b.Subject)
if errors.Is(e, db.ErrNotFound) {
handlers.WriteJSON(w, 404, handlers.Error{Error: "Not found"})
return
}
if errors.Is(e, db.ErrAccountLinked) {
handlers.WriteJSON(w, 409, handlers.Error{Error: "Subject already linked"})
return
}
if e != nil {
handlers.WriteJSON(w, 500, handlers.Error{Error: "Unable to link account"})
return
}
log.Printf("audit: admin %s linked authelia subject to user %s", s.RealID, b.UserID)
handlers.WriteJSON(w, 200, handlers.OK{OK: true})
}
func HandleAdminViewAs(w http.ResponseWriter, r *http.Request) {
var b struct {
UserID *string `json:"userId"`