Documentation
¶
Overview ¶
Package server is the tensile-auth server: the library packaged as one binary, so apps in any language can use it over HTTP. The app proxies /auth/ to it, so sessions stay in __Host- cookies on the app's own origin.
The binary in cmd/tensile-auth-server calls Main. Tests and Go apps can call Main too, to start a server in-process. The design is in docs/design/server.md.
Index ¶
Constants ¶
const AdminPrefix = "/admin/"
AdminPrefix is where the admin API is mounted. Every request under it needs a human with AssuranceMulti, whichever route serves it.
const AppKeyHeader = "Tensile-App-Key"
AppKeyHeader carries the app key on every /v1 call.
const ClientIPHeader = "Tensile-Client-IP"
ClientIPHeader carries the end user's address on a request that the SDK's proxy forwards. The server trusts it only on a request that also carries a live app key in AppKeyHeader.
const DefaultConfigFile = "/etc/tensile-auth/config.toml"
DefaultConfigFile is where the server looks for its file when neither --config nor TENSILE_AUTH_CONFIG names one. A missing default file is not an error; a missing named file is.
const EnvPrefix = "TENSILE_AUTH_"
EnvPrefix starts every environment variable the server reads.
const SubjectHeader = "Tensile-Subject"
SubjectHeader carries the subject on GET routes that act for a person: base64url JSON in the shape of a check's credential.
Variables ¶
var Version = "dev"
Version is the server's version, stamped at build time with -ldflags.
Functions ¶
Types ¶
type AdminConfig ¶
type AdminConfig struct {
// AllowedNetworks are CIDRs whose clients may reach /admin/. Empty
// means any.
AllowedNetworks []string `toml:"allowed_networks"`
}
AdminConfig is the [admin] table.
type CacheConfig ¶
type CacheConfig struct {
// Enabled wraps the store in cachestore, kept fresh by pgstore.Watch.
Enabled bool `toml:"enabled"`
}
CacheConfig is the [cache] table.
type Config ¶
type Config struct {
// DatabaseURL is a postgres:// URL, or sqlite:///path for a single
// node.
DatabaseURL string `toml:"database_url" secret:"true"`
// Origins are the app's public origins.
Origins []string `toml:"origins"`
// RPID is the passkey relying party ID. Default: the host of the
// first origin.
RPID string `toml:"rp_id"`
// RPName is the name some authenticators show. Default: RPID.
RPName string `toml:"rp_name"`
// MasterKey is 32 random bytes in standard base64. It wraps every key
// the server stores.
MasterKey string `toml:"master_key" secret:"true"`
// Listen is the API listener.
Listen string `toml:"listen"`
// OpsListen is the health and metrics listener. Never proxy it.
OpsListen string `toml:"ops_listen"`
// TrustedProxies are CIDRs whose X-Forwarded-For the server trusts.
TrustedProxies []string `toml:"trusted_proxies"`
// Preset is the preset the service, passwords, and routes are built
// from.
Preset string `toml:"preset"`
// Migrate is auto, check, or off.
Migrate string `toml:"migrate"`
ShutdownTimeout Duration `toml:"shutdown_timeout"`
Passwords PasswordsConfig `toml:"passwords"`
Cache CacheConfig `toml:"cache"`
RateLimits RateLimitsConfig `toml:"rate_limits"`
Sessions SessionsConfig `toml:"sessions"`
Hooks HooksConfig `toml:"hooks"`
Webhooks WebhooksConfig `toml:"webhooks"`
Admin AdminConfig `toml:"admin"`
OAuth OAuthConfig `toml:"oauth"`
Log LogConfig `toml:"log"`
}
Config is the server's configuration. Each field is one key of the TOML file; a nested struct is a TOML table. A field tagged secret:"true" can also be read from a file with the _FILE suffix, and has no plain flag, so the secret never appears in a process list.
type Duration ¶
Duration is a time.Duration written as a Go duration string, for example "8s", in the file, a variable, or a flag.
func (Duration) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*Duration) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type Env ¶
type Env struct {
// Args are the arguments after the program name.
Args []string
// Environ is the environment, as KEY=value strings.
Environ []string
Stdout io.Writer
Stderr io.Writer
// ReadFile reads the configuration file and _FILE secrets.
ReadFile func(name string) ([]byte, error)
// Getuid returns the process's user ID.
Getuid func() int
// Stdin is standard input. StdinTerminal and StdoutTerminal report
// whether standard input and output are terminals; nil means not.
Stdin io.Reader
StdinTerminal func() bool
StdoutTerminal func() bool
// ReadPassword reads a line from the terminal without echoing it.
ReadPassword func() ([]byte, error)
// Listening, when set, is called with the API and ops addresses once
// the server accepts connections.
Listening func(api, ops string)
// contains filtered or unexported fields
}
Env is what Main reads and writes, so a test can run it without the process's own arguments, environment, files, or user.
type HooksConfig ¶
type HooksConfig struct {
// URL is the app's endpoint for synchronous hooks: sign-up and
// session scopes. Each answer must be signed.
URL string `toml:"url"`
}
HooksConfig is the [hooks] table.
type LogConfig ¶
type LogConfig struct {
// Format is json or text.
Format string `toml:"format"`
}
LogConfig is the log table.
type OAuthClient ¶
type OAuthClient struct {
ID string `toml:"id"`
Name string `toml:"name"`
// SecretSHA256 holds the hex SHA-256 of each valid client secret, so
// the file holds no secret. A client without one is public.
SecretSHA256 []string `toml:"secret_sha256"`
RedirectURIs []string `toml:"redirect_uris"`
Native bool `toml:"native"`
// Grants are authorization_code, refresh_token, device_code, or
// token_exchange.
Grants []string `toml:"grants"`
Scopes []string `toml:"scopes"`
AccessTTL Duration `toml:"access_ttl"`
Refresh bool `toml:"refresh"`
FirstParty bool `toml:"first_party"`
}
OAuthClient is one [[oauth.clients]] table.
type OAuthConfig ¶
type OAuthConfig struct {
// Enabled mounts the OAuth and OpenID Connect provider.
Enabled bool `toml:"enabled"`
// Issuer is the provider's URL. Default: the first origin.
Issuer string `toml:"issuer"`
// Interaction is the app's consent page. Default: the first origin
// followed by /oauth/consent.
Interaction string `toml:"interaction"`
// DevicePage is the path of the app's device page. Default:
// /login/device.
DevicePage string `toml:"device_page"`
Clients []OAuthClient `toml:"clients"`
Resources []OAuthResource `toml:"resources"`
}
OAuthConfig is the oauth table. Clients and resources are arrays of tables, [[oauth.clients]] and [[oauth.resources]], so they come only from the file.
type OAuthResource ¶
type OAuthResource struct {
URI string `toml:"uri"`
Name string `toml:"name"`
Scopes []string `toml:"scopes"`
}
OAuthResource is one [[oauth.resources]] table: a protected resource, such as an MCP server.
type PasswordsConfig ¶
type PasswordsConfig struct {
// Enabled false serves passkeys only.
Enabled bool `toml:"enabled"`
// MailerURL is an smtp:// or smtps:// URL, or an https:// webhook.
MailerURL string `toml:"mailer_url" secret:"true"`
// AcceptBcrypt verifies bcrypt hashes imported from other products,
// and replaces each with Argon2id on its first correct sign-in.
AcceptBcrypt bool `toml:"accept_bcrypt"`
}
PasswordsConfig is the [passwords] table.
type RateLimitsConfig ¶
type RateLimitsConfig struct {
// Backend is "postgres", "memory" for a single node, or a redis://
// or rediss:// URL. Default: postgres on Postgres, and memory on
// SQLite and in dev.
Backend string `toml:"backend" secret:"true"`
}
RateLimitsConfig is the [rate_limits] table.
type SessionsConfig ¶
type SessionsConfig struct {
// DefaultScopes are the scopes of every session.
DefaultScopes []string `toml:"default_scopes"`
}
SessionsConfig is the [sessions] table.
type WebhooksConfig ¶
type WebhooksConfig struct {
// URL is the app's endpoint for events, delivered after they commit.
URL string `toml:"url"`
}
WebhooksConfig is the [webhooks] table.