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
@@ -3,10 +3,13 @@ package store
|
||||
import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"database/sql"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/secrets"
|
||||
"time"
|
||||
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/secrets"
|
||||
)
|
||||
|
||||
// ClusterSecret returns the named secret, creating a random one the first time
|
||||
@@ -39,6 +42,43 @@ func (s *DB) ClusterSecret(ctx context.Context, name string) (string, error) {
|
||||
`SELECT value FROM cluster_secrets WHERE name = ?`, name).Scan(&v); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return s.openSecret(ctx, name, v)
|
||||
}
|
||||
|
||||
// SetClusterSecret keeps value under name, sealed when a master key is set,
|
||||
// in place of what was there: a secret an operator gives, such as the
|
||||
// password the directory is read with, the same for every control plane.
|
||||
func (s *DB) SetClusterSecret(ctx context.Context, name, value string) error {
|
||||
stored := value
|
||||
if s.sealer != nil {
|
||||
var err error
|
||||
if stored, err = s.sealer.Seal(ctx, []byte(value)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
_, err := s.db.ExecContext(ctx,
|
||||
`INSERT INTO cluster_secrets (name, value, created_at) VALUES (?, ?, ?)
|
||||
ON CONFLICT (name) DO UPDATE SET value = excluded.value, created_at = excluded.created_at`,
|
||||
name, stored, time.Now().UnixMilli())
|
||||
return err
|
||||
}
|
||||
|
||||
// StoredSecret is the named secret, ErrNotFound when none was kept; unlike
|
||||
// ClusterSecret it never makes one.
|
||||
func (s *DB) StoredSecret(ctx context.Context, name string) (string, error) {
|
||||
var v string
|
||||
err := s.db.QueryRowContext(ctx, `SELECT value FROM cluster_secrets WHERE name = ?`, name).Scan(&v)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return "", ErrNotFound
|
||||
}
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return s.openSecret(ctx, name, v)
|
||||
}
|
||||
|
||||
// openSecret is a kept value in the clear.
|
||||
func (s *DB) openSecret(ctx context.Context, name, v string) (string, error) {
|
||||
if secrets.IsSealed(v) {
|
||||
if s.sealer == nil {
|
||||
return "", fmt.Errorf("the store's secret %q is sealed, and secrets.master_key is not set to open it", name)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
@@ -23,3 +24,22 @@ func TestAClusterSecretIsMadeOnceAndKept(t *testing.T) {
|
||||
t.Error("two names share a secret")
|
||||
}
|
||||
}
|
||||
|
||||
func TestASecretGivenIsKeptReplacedAndNeverMade(t *testing.T) {
|
||||
db, err := Open(t.Context(), filepath.Join(t.TempDir(), "s.db"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer db.Close()
|
||||
if _, err := db.StoredSecret(t.Context(), "auth/ldap-bind"); !errors.Is(err, ErrNotFound) {
|
||||
t.Errorf("a secret never given: %v", err)
|
||||
}
|
||||
for _, v := range []string{"first", "second"} {
|
||||
if err := db.SetClusterSecret(t.Context(), "auth/ldap-bind", v); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got, err := db.StoredSecret(t.Context(), "auth/ldap-bind"); err != nil || got != v {
|
||||
t.Errorf("read %q %v, want %q", got, err, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user