server

package
v0.34.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 41 Imported by: 0

Documentation

Overview

Package server is `rig serve`: the Engine API over HTTPS for remote CLIs, MCP clients and the web inbox, with accounts, server-side policy, reauth, approvals, leases and one audit log per environment. Requests carry a bearer token; streams are newline-delimited JSON.

Index

Constants

View Source
const CodeFailed = -32010

CodeFailed carries engine.ErrFailed (a failed check) across the wire.

Variables

View Source
var ErrAuth = errors.New("wrong user, password or code")

Functions

func Call added in v0.30.0

func Call(w http.ResponseWriter, r *http.Request, e api.Engine, subj identity.Subject, reauthed func() bool)

Call answers the Engine call r names (POST .../{method}) on e for subj. reauthed settles a policy reauth; nil asks it as a confirm, for a local client.

func Certificate

func Certificate(certFile, keyFile, dir string, hosts []string) (tls.Certificate, string, error)

Certificate loads certFile and keyFile, or, when both are empty, a self-signed certificate kept in dir (made on first run for hosts). Clients pin a self-signed certificate by its fingerprint.

func Fingerprint

func Fingerprint(der []byte) string

func NewTOTP

func NewTOTP() string

NewTOTP is a fresh base32 secret for an authenticator app.

func TOTPCode

func TOTPCode(secret string, t time.Time) string

TOTPCode is the RFC 6238 code (SHA-1, 30s, 6 digits) for t.

func TOTPURL

func TOTPURL(issuer, user, secret string) string

TOTPURL is what an authenticator app scans.

func WithDefaults

func WithDefaults(c *policy.Config) *policy.Config

WithDefaults adds the built-in roles a project does not define itself.

Types

type OIDC

type OIDC struct {
	Issuer       string `yaml:"issuer" json:"issuer"`
	ClientID     string `yaml:"client_id" json:"client_id"`
	ClientSecret string `yaml:"client_secret" json:"client_secret"`
	// RedirectURL is this server's /v1/oidc/callback as the provider reaches it.
	RedirectURL string `yaml:"redirect_url" json:"redirect_url"`
	// UserClaim names the account (default preferred_username, then email).
	UserClaim   string   `yaml:"user_claim" json:"user_claim"`
	GroupsClaim string   `yaml:"groups_claim" json:"groups_claim"`
	Roles       []string `yaml:"roles" json:"roles"`
	// contains filtered or unexported fields
}

OIDC signs people in through an identity provider (Keycloak, GitLab, Google, Okta) with the authorization code flow and PKCE. The CLI opens /v1/oidc/start?state=S in a browser and polls /v1/oidc/poll for the session token the callback leaves under S.

type Server

type Server struct {
	// File is the project's rig.yaml.
	File  string
	Store *Store
	OIDC  *OIDC
	// Open opens the project on an environment; engine.Open when nil.
	Open func(file, env string) (*engine.App, error)
	// ReauthWindow is how long a reauth lasts (default 5m).
	ReauthWindow time.Duration
	// RatePerSecond caps each caller's requests (default 50).
	RatePerSecond int
	// contains filtered or unexported fields
}

func (*Server) Close

func (s *Server) Close()

Close stops every environment's engine.

func (*Server) Engine

func (s *Server) Engine(env string) (*engine.Local, error)

Engine is the engine for env ("" is the project's default), opened on first use.

func (*Server) Handler

func (s *Server) Handler() http.Handler

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store keeps accounts and tokens in one 0600 JSON file; tokens are kept as their SHA-256.

func OpenStore

func OpenStore(path string) (*Store, error)

func (*Store) Check

func (s *Store) Check(name, password, code string) bool

Check verifies a password or TOTP code again, for reauth.

func (*Store) Issue

func (s *Store) Issue(user, name string, ttl time.Duration, session bool) (string, Token, error)

Issue makes a token for user and returns its secret, shown once.

func (*Store) Login

func (s *Store) Login(name, password, code string) (User, error)

Login checks a password and, when the user has one, the current TOTP code.

func (*Store) PutUser

func (s *Store) PutUser(name string, u User, password string) error

PutUser adds or changes name; a non-empty password is hashed with argon2id.

func (*Store) RemoveUser

func (s *Store) RemoveUser(name string) error

func (*Store) Revoke

func (s *Store) Revoke(user, id string) error

Revoke drops the token with id; user, when set, must own it.

func (*Store) Token

func (s *Store) Token(secret string) (Token, bool)

Token is the live token secret names.

func (*Store) Tokens

func (s *Store) Tokens(user string) []Token

func (*Store) User

func (s *Store) User(name string) (User, bool)

func (*Store) Users

func (s *Store) Users() map[string]User

type Token

type Token struct {
	ID      string    `json:"id"`
	User    string    `json:"user"`
	Name    string    `json:"name"`
	Expires time.Time `json:"expires"`
	// Session tokens come from a login and may reauth; API tokens never can.
	Session bool `json:"session,omitempty"`
}

type User

type User struct {
	Hash   string   `json:"hash,omitempty"`
	TOTP   string   `json:"totp,omitempty"`
	Roles  []string `json:"roles,omitempty"`
	Groups []string `json:"groups,omitempty"`
	// OIDC users sign in through the identity provider only.
	OIDC bool `json:"oidc,omitempty"`
}

Jump to

Keyboard shortcuts

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