Sign-in is set up from the console, and a directory tried before it is kept
People → Sign-in shows single sign-on, Active Directory and SCIM, and the directory's last sync. E sets up Entra ID from the tenant and client IDs; D sets up Active Directory, tried from the control plane first: each server bound, people who may sign in, members of each mapped group. The secrets go into the store as store:auth/..., sealed by the master key, and the CA into the settings, so no control plane needs a file. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
4b6b3eeddb
commit
ac25a9136a
24 files changed
+1753
-18
No files matched your search
@@ -6,10 +6,12 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/account"
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/config"
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/control/adminapi"
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/directory"
|
||||
storepkg "gitea.mynodes.xyz/ilker/llmgw/internal/store"
|
||||
)
|
||||
@@ -24,6 +26,9 @@ type ldapDirectory struct {
|
||||
every time.Duration
|
||||
label string
|
||||
log *slog.Logger
|
||||
|
||||
mu sync.Mutex
|
||||
last *adminapi.DirectorySyncView
|
||||
}
|
||||
|
||||
func newLDAPDirectory(cfg config.LDAP, st *storepkg.DB, log *slog.Logger) (*ldapDirectory, error) {
|
||||
@@ -92,16 +97,26 @@ func (d *ldapDirectory) sync(ctx context.Context, leader func() bool) {
|
||||
func (d *ldapDirectory) syncOnce(ctx context.Context) {
|
||||
ctx, cancel := context.WithTimeout(ctx, 5*time.Minute)
|
||||
defer cancel()
|
||||
last := &adminapi.DirectorySyncView{At: time.Now()}
|
||||
defer func() {
|
||||
d.mu.Lock()
|
||||
d.last = last
|
||||
d.mu.Unlock()
|
||||
}()
|
||||
people, err := d.dir.People(ctx, d.keeper.Mapping)
|
||||
if err != nil {
|
||||
d.log.Warn("could not read the directory; accounts left as they are", "err", err)
|
||||
last.Error = "could not read the directory: " + err.Error()
|
||||
return
|
||||
}
|
||||
last.People = len(people)
|
||||
rep, err := d.keeper.Sync(ctx, people)
|
||||
if err != nil {
|
||||
d.log.Error("the directory sync stopped", "err", err, "people", len(people))
|
||||
last.Error = err.Error()
|
||||
return
|
||||
}
|
||||
last.Accounts, last.Suspended, last.Reinstated, last.RolesChanged = rep.Seen, rep.Suspended, rep.Reinstated, rep.Updated
|
||||
for _, where := range rep.Unmapped {
|
||||
d.log.Warn("auth.ldap.memberships maps a group to a place the tree does not have", "place", where)
|
||||
}
|
||||
@@ -110,3 +125,54 @@ func (d *ldapDirectory) syncOnce(ctx context.Context) {
|
||||
"suspended", rep.Suspended, "reinstated", rep.Reinstated, "roles_changed", rep.Updated)
|
||||
}
|
||||
}
|
||||
|
||||
// lastSync is how the leader's last read of the directory went; nil before
|
||||
// the first, and on a standby.
|
||||
func (d *ldapDirectory) lastSync() *adminapi.DirectorySyncView {
|
||||
d.mu.Lock()
|
||||
defer d.mu.Unlock()
|
||||
return d.last
|
||||
}
|
||||
|
||||
// AuthStatus is how people sign in on this gateway, for the admin API.
|
||||
func (r *Router) AuthStatus() adminapi.AuthView {
|
||||
v := adminapi.AuthView{SCIM: r.scim.TokenFile != "", BaseURL: r.mail.BaseURL}
|
||||
if r.accounts != nil {
|
||||
v.SignupOpen = r.accounts.SignupOpen()
|
||||
}
|
||||
if o := r.oidc; o.Enabled() {
|
||||
v.OIDC = &adminapi.OIDCView{Issuer: o.Issuer, ClientID: o.ClientID, Label: o.Label,
|
||||
CreateAccounts: o.CreateAccounts, NoPasswords: o.NoPasswords}
|
||||
}
|
||||
if l := r.ldap; l.Enabled() {
|
||||
v.LDAP = &adminapi.LDAPView{URLs: l.URLs, BaseDN: l.BaseDN, BindDN: l.BindDN, Label: l.Label, Off: r.ldapOff}
|
||||
if r.directory != nil {
|
||||
v.LDAP.LastSync = r.directory.lastSync()
|
||||
}
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// TestDirectory tries an auth.ldap block, given as YAML, before it is kept:
|
||||
// checked as the settings would be, then each step against the directory.
|
||||
func (r *Router) TestDirectory(ctx context.Context, settings, password string) ([]adminapi.CheckView, error) {
|
||||
l, err := config.ParseLDAP([]byte(settings))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dir, err := directory.NewLDAP(l)
|
||||
if err != nil {
|
||||
return []adminapi.CheckView{{Step: "certificate", Detail: err.Error()}}, nil
|
||||
}
|
||||
if password != "" {
|
||||
dir.WithPassword(password)
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(ctx, time.Minute)
|
||||
defer cancel()
|
||||
checks := dir.Check(ctx, directory.Mapping{Roles: l.Roles, Memberships: l.Memberships})
|
||||
out := make([]adminapi.CheckView, len(checks))
|
||||
for i, c := range checks {
|
||||
out[i] = adminapi.CheckView(c)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
@@ -28,3 +28,18 @@ func TestADirectoryThatCannotBeUsedHereLeavesTheGatewayUp(t *testing.T) {
|
||||
t.Errorf("/login: %d", w.Code)
|
||||
}
|
||||
}
|
||||
|
||||
// Settings tried are checked as kept ones are: a plaintext server is
|
||||
// refused before anything is sent to it.
|
||||
func TestDirectorySettingsTriedAreCheckedFirst(t *testing.T) {
|
||||
r := &Router{}
|
||||
if _, err := r.TestDirectory(t.Context(), "urls: [ldap://dc1]\nbind_dn: CN=svc\nbind_password_file: store:auth/ldap-bind\nbase_dn: DC=corp\n", "pw"); err == nil ||
|
||||
!strings.Contains(err.Error(), "plaintext") {
|
||||
t.Errorf("err %v", err)
|
||||
}
|
||||
checks, err := r.TestDirectory(t.Context(), "urls: [ldaps://dc1]\nca: \"-----BEGIN CERTIFICATE-----\\nAAAA\\n-----END CERTIFICATE-----\"\n"+
|
||||
"bind_dn: CN=svc\nbind_password_file: store:auth/ldap-bind\nbase_dn: DC=corp\n", "pw")
|
||||
if err != nil || len(checks) != 1 || checks[0].Step != "certificate" || checks[0].OK {
|
||||
t.Errorf("a broken CA: %+v %v", checks, err)
|
||||
}
|
||||
}
|
||||
@@ -43,6 +43,7 @@ import (
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/router/proxy"
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/router/scheduler"
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/router/scrape"
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/secrets"
|
||||
storepkg "gitea.mynodes.xyz/ilker/llmgw/internal/store"
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/web"
|
||||
)
|
||||
@@ -120,7 +121,11 @@ type Router struct {
|
||||
// notifier says what the operator must act on; nil says nothing.
|
||||
notifier *notify.Notifier
|
||||
// directory is auth.ldap's: sign-in and the accounts kept in step.
|
||||
// ldap is the setting, and ldapOff why this control plane could not
|
||||
// use it.
|
||||
directory *ldapDirectory
|
||||
ldap config.LDAP
|
||||
ldapOff string
|
||||
// guard judges requests and answers; nil judges nothing. guardLibrary
|
||||
// is the policies it was built from, for the pages that show them.
|
||||
guard guard.Guard
|
||||
@@ -358,6 +363,9 @@ func New(cfg config.Server, log *slog.Logger) (*Router, error) {
|
||||
return nil, fmt.Errorf("auth store: %w", err)
|
||||
}
|
||||
r.store = st
|
||||
// Secrets the settings name as store:… are the same on every
|
||||
// control plane: read from here.
|
||||
secrets.SetStore(st.StoredSecret)
|
||||
r.usageRetention = cfg.Auth.UsageRetention
|
||||
// Applied where no scope set one, so a project created without limits
|
||||
// is still metered. Zero leaves it unlimited, which was the old
|
||||
@@ -402,8 +410,10 @@ func New(cfg config.Server, log *slog.Logger) (*Router, error) {
|
||||
// here (a CA file missing on this machine) must not keep them all
|
||||
// down, where nothing could be used to put it right. Local
|
||||
// accounts still sign in.
|
||||
r.ldap = cfg.Auth.LDAP
|
||||
if d, err := newLDAPDirectory(cfg.Auth.LDAP, st, log); err != nil {
|
||||
log.Error("sign-in with the directory is off on this control plane", "err", err)
|
||||
r.ldapOff = err.Error()
|
||||
} else {
|
||||
r.directory = d
|
||||
r.accounts.SetDirectory(d)
|
||||
|
||||
Reference in new issue
Block a user