config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package config loads lockssh profiles from the project and user config files, applies the defaults, refuses anything that looks like a secret, and computes the security-relevant policy of a profile. The file lookup, the secret-safe decoding, the shared profile base and the diff helpers are lockkit's.

Index

Constants

View Source
const (
	// ActConnect: use the console's SSH session (a connect ticket; under
	// "ask" the lock takes a human's approval of the first one of each
	// console run and approved policy).
	ActConnect = "connect"
	// ActRun: a command an allow rule matches. Under "auto" it runs at
	// once: the human approved the allow list in the policy review.
	ActRun = "run"
	// ActExec: a command no allow rule matches, on a profile with
	// exec = true.
	ActExec = "exec"
	// ActUnmask: a command's output in clear. Never approved by an auto
	// rule, whatever this rule says: only deny changes anything.
	ActUnmask = "unmask"
)

Actions of the auto rules.

View Source
const (
	MaxOutputCeiling  = 512 << 10
	MaxRequestTimeout = 10 * time.Minute
)

Ceilings of the per-command limits.

View Source
const (
	MinIdleTimeout = time.Minute
	MaxMaxSession  = 24 * time.Hour
)

Bounds of the session limits: MinIdleTimeout <= idle_timeout <= max_session <= MaxMaxSession.

View Source
const (
	DefaultIdleTimeout = 20 * time.Minute
	DefaultMaxSession  = 4 * time.Hour
)

Default session limits.

View Source
const (
	AuthKey      = kconfig.SSHAuthKey
	AuthPassword = kconfig.SSHAuthPassword
)

Authentication methods of a profile.

View Source
const CredentialsNone = console.CredentialsNone

CredentialsNone is the credentials mode of an unencrypted key: the console asks for nothing.

View Source
const FullAuto = "full-auto"

FullAuto is the preset that sets every action to auto (`auto = "full-auto"`).

Variables

AutoActions lists every action, in display order.

Functions

func DefaultDetectors

func DefaultDetectors() []string

DefaultDetectors is the detector set of a profile that sets none: the usual personal values, public IP addresses (command output is full of them) and secrets (a config file or an environment dump). National id detectors are opt-in.

func Load

func Load(cwd string) (map[string]Profile, string, error)

Load reads the project config (found by walking up from cwd) and the user config. On a profile name present in both, the project profile wins as a whole. It also returns the project root ("" when none).

func LoadFile

func LoadFile(path string) (map[string]Profile, error)

LoadFile reads the profiles of one config file.

func LoadFrom

func LoadFrom(cwd, userConfigPath string) (map[string]Profile, string, error)

LoadFrom is Load with an explicit user config path ("" for none). A missing user config file is not an error.

func ParseProfiles

func ParseProfiles(data []byte, name string) (map[string]Profile, error)

ParseProfiles decodes and validates config data; name labels errors. Errors never quote a value that could hold a secret.

Types

type AutoRules

type AutoRules struct {
	Connect AutoValue `json:"connect,omitempty"`
	Run     AutoValue `json:"run,omitempty"`
	Exec    AutoValue `json:"exec,omitempty"`
	Unmask  AutoValue `json:"unmask,omitempty"`
}

AutoRules are a profile's auto rules. An empty field is the action's default (AutoDefault): Canonical empties the fields equal to it, so a profile that sets no rule keeps the fingerprint it had before the rules existed.

func (AutoRules) Effective

func (a AutoRules) Effective() map[string]AutoValue

Effective is every action with its effective rule.

func (AutoRules) IsFullAuto

func (a AutoRules) IsFullAuto() bool

IsFullAuto reports whether every action is auto.

func (AutoRules) Rule

func (a AutoRules) Rule(action string) AutoValue

Rule is the effective rule of action: the profile's, or the default. An unknown action is denied (fail closed).

func (AutoRules) RuleID

func (a AutoRules) RuleID(action string) string

RuleID names the rule that applies to action, for the audit and the ticket screen: "auto.<action>=<value>".

func (AutoRules) String

func (a AutoRules) String() string

String is the effective rules on one line ("connect ask · list auto …").

type AutoValue

type AutoValue string

AutoValue is how `lox run`'s auto mode treats one action of a profile: approved without a question (auto), asked of the human (ask), or refused even when asked (deny). Manual mode asks everything a ticket carries whatever the rule; deny refuses in both modes.

const (
	AutoDeny AutoValue = "deny"
	AutoAsk  AutoValue = "ask"
	AutoAuto AutoValue = "auto"
)

Auto values, from the tightest to the loosest.

func AutoDefault

func AutoDefault(action string) AutoValue

AutoDefault is the rule of action when the profile sets none.

func ParseAutoValue

func ParseAutoValue(s string) (AutoValue, error)

ParseAutoValue parses auto, ask or deny. Its error never quotes s.

type Limits

type Limits struct {
	// RequestTimeout ends a command that runs longer (its session is
	// closed; the result says timed_out).
	RequestTimeout time.Duration `json:"request_timeout"`
	// MaxOutputBytes caps stdout and stderr, each, before masking.
	MaxOutputBytes int `json:"max_output_bytes"`
}

Limits bound one command.

func DefaultLimits

func DefaultLimits() Limits

DefaultLimits returns the limits applied to unset limit fields.

type Policy

type Policy struct {
	Profile Profile `json:"profile"`
}

Policy is the security-relevant view of one profile: what the console fingerprints, compares with the last approved one and asks the human about before applying any loosening.

func Canonical

func Canonical(p Policy) Policy

Canonical sorts and de-duplicates the lists of p: its JSON is the fingerprinted form.

func NewPolicy

func NewPolicy(p Profile) Policy

NewPolicy builds the canonical policy of p.

func (Policy) Describe

func (p Policy) Describe() []string

Describe is the policy as lines for the console's status screen.

func (Policy) Diff

func (p Policy) Diff(approved kconfig.Policy) []kconfig.Change

Diff lists the changes from approved to p and marks each loosening: a new allow rule, exec turned on, another known_hosts file, a removed detector, a larger output cap, a longer request timeout, an auto rule made looser (deny < ask < auto), and the shared rules of the profile base (kconfig.DiffBase: the login, the SSH target, production, credentials).

type Profile

type Profile struct {
	Name string `json:"name"`
	kconfig.Base
	// KnownHosts is the known_hosts file the host key is checked against;
	// "" is the console account's ~/.ssh/known_hosts, where an unknown key
	// may be trusted on the console.
	KnownHosts string `json:"known_hosts,omitempty"`
	// Exec lets the agent ask for a command no allow rule matches (each
	// one a ticket the human decides).
	Exec bool `json:"exec"`
	// Allow are the allow rules in canonical text form, sorted.
	Allow     []string `json:"allow"`
	Detectors []string `json:"detectors"`
	Limits    Limits   `json:"limits"`
	// Auto are the profile's auto rules (`lox run`'s auto mode).
	Auto AutoRules `json:"auto,omitzero"`
}

Profile is one SSH host with its policy. It never holds a secret. Its SSH target is Base.SSH (host, port, user, auth, key, credentials), so that lockkit's console treats a change of any of them as a connection change.

func (Profile) Auth

func (p Profile) Auth() string

Auth is the profile's SSH authentication method.

func (Profile) Host

func (p Profile) Host() string

Host is the profile's SSH host.

func (Profile) Key

func (p Profile) Key() string

Key is the profile's private key file ("" with password auth).

func (Profile) Port

func (p Profile) Port() int

Port is the profile's SSH port.

Jump to

Keyboard shortcuts

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