Documentation
¶
Overview ¶
Package dex is axa.Broker on an embedded Dex (the fork in pkg/dex).
Index ¶
- Constants
- Variables
- func BuildDexConnector(ctx context.Context, c axa.Connector, secrets SecretResolver) (dexstorage.Connector, error)
- func ConnectorOfSubject(sub string) string
- func PrepareTenantConnector(typ string, raw json.RawMessage, issuerURL string) (json.RawMessage, error)
- func Schema() string
- func SeedClient(id, secret, name string) axa.SeedFunc
- func SeedPassword(username string, bcryptHash []byte) axa.SeedFunc
- func UpstreamOfSubject(sub string) (userID, connID string)
- type BFFClientSeeder
- type CLIClientSeeder
- type Config
- type SecretResolver
- type Server
Constants ¶
const CLIClientID = "armornet-cli"
CLIClientID authenticates a HUMAN by device grant (RFC 8628); agents are MACHINES on client credentials.
Variables ¶
var ErrInvalidTenantConnector = errors.New("invalid connector")
ErrInvalidTenantConnector wraps every refusal, so a handler can answer 400 without string matching.
var ErrNotStarted = errors.New("identity/dex: broker not started")
ErrNotStarted: hook work that needs a live store as an axa.StartupSeeder.
var TenantConnectorTypes = []string{"oidc", "saml", "microsoft"}
TenantConnectorTypes excludes mocks (a fixed fake user), authproxy (trusts a header) and ldap (dials into the tenant's network).
Functions ¶
func BuildDexConnector ¶
func BuildDexConnector(ctx context.Context, c axa.Connector, secrets SecretResolver) (dexstorage.Connector, error)
BuildDexConnector builds a static, never-persisted connector for Config.Connectors.
func ConnectorOfSubject ¶
ConnectorOfSubject returns the connector id a Dex subject was issued through, or "" when sub is not a Dex subject.
A Dex sub is base64url(proto IDTokenSubject{user_id = 1, conn_id = 2}), so the connector is in the subject itself and survives every session: it is authoritative for "how does this person sign in" in a way the sessions table, which expires, is not. The codec is in Dex's internal package, so this reads the two fields with protowire rather than importing it.
func PrepareTenantConnector ¶
func PrepareTenantConnector(typ string, raw json.RawMessage, issuerURL string) (json.RawMessage, error)
PrepareTenantConnector decodes strictly (a typo is refused) and always sets redirectURI itself: a tenant never picks where the upstream responds.
func Schema ¶
func Schema() string
Schema is reference DDL the host runs (see pgstore.Schema). Idempotent, but it never upgrades a table that exists in an older shape.
func SeedClient ¶
SeedClient writes a confidential client under a secret the caller fixes, so a local config can carry it. A fixed secret is a dev convenience: gate the call on the host's dev mode. An existing client is left as it is.
func SeedPassword ¶
SeedPassword writes one account for Dex's "local" password connector. The username doubles as the stable user ID, so a changed hash keeps the same subject and the account keeps its memberships.
func UpstreamOfSubject ¶
UpstreamOfSubject returns the upstream user id and connector id a Dex subject was issued for, or two empty strings when sub is not a Dex subject. For the GitHub connector the user id is the person's numeric GitHub id.
Types ¶
type BFFClientSeeder ¶
type BFFClientSeeder struct {
// Secret is plaintext; Dex hashes it on write.
Secret string
// RedirectURI must match identity.redirect_uri in the server config.
RedirectURI string
}
BFFClientSeeder upserts armornet-bff on every start so the stored secret matches ARMORNET_IDENTITY_CLIENT_SECRET; drift meant 502s on callback.
func (*BFFClientSeeder) Name ¶
func (s *BFFClientSeeder) Name() string
type CLIClientSeeder ¶
type CLIClientSeeder struct{}
CLIClientSeeder runs in production: the CLI is PUBLIC (a shipped binary keeps no secret; the human approval protects it). Never add a fixed secret.
func (CLIClientSeeder) Name ¶
func (CLIClientSeeder) Name() string
type Config ¶
type Config struct {
// IssuerURL is required, with no trailing slash ("https://api.armornet.io/dex").
IssuerURL string
// RotateKeysAfter defaults to 6h; Dex keeps old keys in the JWKS for the
// token lifetime.
RotateKeysAfter time.Duration
// IDTokensValidFor is the lifetime of issued ID tokens. Defaults to 24h.
// Must be > RotateKeysAfter to ensure tokens stay valid across one rotation.
IDTokensValidFor time.Duration
// Seeders run once storage is healthy and must be idempotent.
Seeders []axa.StartupSeeder
// HostAuthUI redirects Dex's login, approval and error pages to the host's
// /dex-* SPA routes; false if it serves none.
HostAuthUI bool
// DatabaseURL is the Postgres DSN for Dex's Ent storage. Required; the host
// supplies it (the module does not read the environment).
DatabaseURL string
// Connectors are static: secrets resolve at Start and are never persisted.
Connectors []axa.Connector
// ConfigSealer seals stored connector configs; nil stores cleartext JSON.
ConfigSealer axa.ConfigSealer
// DialControl vets each address an upstream connector dials (discovery,
// token, userinfo). A tenant-supplied issuer is attacker-chosen, so a host
// that lets tenants add connectors should refuse internal addresses here.
// Nil dials anything. It is process-wide: Dex builds its clients itself.
DialControl func(network, address string, c syscall.RawConn) error
// DeviceApprover names the person signed in to the host on r, "" for
// nobody. Set, a device code is granted only to the person who approved it
// in the host (deviceapproval.go), so a device login carries the host's
// sign-in, MFA included. Nil keeps upstream Dex's device flow, where an
// upstream sign-in alone grants a code. Approvals are sealed with
// ConfigSealer; without one every device sign-in is refused.
DeviceApprover func(r *http.Request) string
}
type SecretResolver ¶
SecretResolver resolves a SecretRef to its plaintext value at write time.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server serves no HTTP itself; the host mounts Broker().Handler().
func (*Server) Health ¶
func (s *Server) Health() healthpkg.ComponentHealth
Health checks readiness, connectors, then the recent auth error rate.
func (*Server) NewVerifier ¶
NewVerifier skips discovery and fetches JWKS lazily in process: no network, no startup ordering.