dex

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 42 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package dex is axa.Broker on an embedded Dex (the fork in pkg/dex).

Index

Constants

View Source
const CLIClientID = "armornet-cli"

CLIClientID authenticates a HUMAN by device grant (RFC 8628); agents are MACHINES on client credentials.

Variables

View Source
var ErrInvalidTenantConnector = errors.New("invalid connector")

ErrInvalidTenantConnector wraps every refusal, so a handler can answer 400 without string matching.

View Source
var ErrNotStarted = errors.New("identity/dex: broker not started")

ErrNotStarted: hook work that needs a live store as an axa.StartupSeeder.

View Source
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

func ConnectorOfSubject(sub string) string

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

func SeedClient(id, secret, name string) axa.SeedFunc

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

func SeedPassword(username string, bcryptHash []byte) axa.SeedFunc

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

func UpstreamOfSubject(sub string) (userID, connID string)

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

func (*BFFClientSeeder) Seed

func (s *BFFClientSeeder) Seed(ctx context.Context, b axa.Broker) error

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

func (CLIClientSeeder) Seed

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

type SecretResolver interface {
	Resolve(ctx context.Context, ref axa.SecretRef) (string, error)
}

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 New

func New(cfg Config) (*Server, error)

func (*Server) Broker

func (s *Server) Broker() axa.Broker

Broker is non-nil from New, so it can be wired before Start.

func (*Server) Health

func (s *Server) Health() healthpkg.ComponentHealth

Health checks readiness, connectors, then the recent auth error rate.

func (*Server) NewVerifier

func (s *Server) NewVerifier(ctx context.Context, issuerURL string) *oidc.IDTokenVerifier

NewVerifier skips discovery and fetches JWKS lazily in process: no network, no startup ordering.

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

Start opens Postgres storage, builds Dex, runs the seeders, then blocks.

func (*Server) Stop

func (s *Server) Stop(ctx context.Context) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL