auth

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0 modules, 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 auth defines the authentication vocabulary shared across the sqi server surface: the request Principal, the pluggable Authenticator interface, and a no-op anonymous authenticator used when auth is disabled.

Credential backends (sessions, API keys) live in the session and apikey subpackages and implement this same interface; Chain composes them. LDAP and OIDC (the ldap and oidc subpackages) are login-time verifiers, not Authenticators: a successful login mints the same session a local password login does.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContext

func NewContext(ctx context.Context, p Principal) context.Context

NewContext returns a copy of ctx carrying p.

Types

type Authenticator

type Authenticator interface {
	Authenticate(r *http.Request) (Principal, error)
}

Authenticator inspects a request's credentials and resolves them to a Principal. A non-nil error means the request is unauthenticated; the caller (REST middleware or WebSocket hook) responds 401 and does not proceed.

The same interface serves both the REST middleware and the WebSocket upgrade, since both receive the raw *http.Request. Chain combines several credential types by trying each in turn.

func Anonymous

func Anonymous() Authenticator

Anonymous returns an Authenticator that authenticates every request as the anonymous superuser principal.

func Chain

func Chain(authns ...Authenticator) Authenticator

Chain returns an Authenticator that tries each authenticator in order and returns the first successful Principal. An authenticator with no credential to offer errors (e.g. apikey.ErrNoCredential) and the chain moves on. If every authenticator errors, the last error is returned so middleware.Auth renders a 401. Order is caller-defined; the server wires key-first so a machine's Bearer credential leads and the browser cookie is the fallback.

type Kind

type Kind string

Kind classifies the credential type behind a Principal.

const (
	// KindAnonymous is the stand-in identity injected when auth is disabled.
	KindAnonymous Kind = "anonymous"
	// KindUser is a human account.
	KindUser Kind = "user"
	// KindAPIKey is a long-lived machine credential.
	KindAPIKey Kind = "apikey"
	// KindService is a reserved internal/service identity.
	KindService Kind = "service"
)

type Principal

type Principal struct {
	// Subject is the stable identity id; empty for the anonymous principal.
	Subject string
	// Username is the human-readable login name. It is the value bound to
	// Job.Owner and Job.Submitter, which are matched as strings by
	// ListJobsOptions.Owner and Search — binding those to the opaque Subject
	// would make every existing owner value unmatchable. Empty for the
	// anonymous principal.
	Username string
	// DisplayName is a human-facing label.
	DisplayName string
	// Roles are the identity's assigned roles, resolved from the user record.
	// Empty for the anonymous principal, which relies on Superuser instead.
	Roles []string
	// Kind classifies the credential type.
	Kind Kind
	// Superuser bypasses all authorization checks. Set on the anonymous
	// principal (auth off = no authorization) and reserved for bootstrap.
	Superuser bool
}

Principal is the authenticated identity attached to every request's context. It is populated by the auth middleware (REST) and the WebSocket hook.

func FromContext

func FromContext(ctx context.Context) (Principal, bool)

FromContext returns the Principal carried by ctx, if any.

Directories

Path Synopsis
Package apikey implements a Bearer-token auth.Authenticator: it reads an Authorization: Bearer <key> header, resolves the key's hash to a live, non-revoked, non-expired api_keys row and its owning user, and returns the corresponding auth.Principal.
Package apikey implements a Bearer-token auth.Authenticator: it reads an Authorization: Bearer <key> header, resolves the key's hash to a live, non-revoked, non-expired api_keys row and its owning user, and returns the corresponding auth.Principal.
Package jointoken mints and hashes worker join tokens: the one-time or reusable secrets an operator issues (via the CLI or the REST API) and a worker redeems to enroll and receive its broker credential.
Package jointoken mints and hashes worker join tokens: the one-time or reusable secrets an operator issues (via the CLI or the REST API) and a worker redeems to enroll and receive its broker credential.
Package ldap authenticates usernames and passwords against an LDAP or Active Directory server.
Package ldap authenticates usernames and passwords against an LDAP or Active Directory server.
Package oidc authenticates sqi web UI logins against an OAuth2/OIDC identity provider.
Package oidc authenticates sqi web UI logins against an OAuth2/OIDC identity provider.
Package password hashes and verifies user passwords with argon2id and mints opaque session tokens.
Package password hashes and verifies user passwords with argon2id and mints opaque session tokens.
Package policy is the authorization matrix for sqi's four built-in roles.
Package policy is the authorization matrix for sqi's four built-in roles.
Package rolemap resolves an external identity's group memberships to one of sqi's RBAC roles.
Package rolemap resolves an external identity's group memberships to one of sqi's RBAC roles.
Package session implements a cookie-backed auth.Authenticator: it reads the session cookie, resolves its hashed token to a live session and user, and returns the corresponding auth.Principal.
Package session implements a cookie-backed auth.Authenticator: it reads the session cookie, resolves its hashed token to a live session and user, and returns the corresponding auth.Principal.

Jump to

Keyboard shortcuts

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