Documentation
¶
Overview ¶
Package console is the human side of locksql: it holds the credentials and the only database connection, enforces the approved policy, shows every query to the human for approval, masks the results and writes the audit trail. Clients (the CLI and the MCP server) reach it over the per-profile socket and never see a secret.
Index ¶
- Constants
- Variables
- func Run(ctx context.Context, o Options) error
- func SameUserRefused(sys *sysconf.Config) error
- type Approver
- type Beller
- type Decision
- type IO
- type Key
- type KeySource
- type LineSource
- type Options
- type Outcome
- type Result
- type Server
- func (s *Server) CheckPolicy()
- func (s *Server) Command(ctx context.Context, line string)
- func (s *Server) End(reason string)
- func (s *Server) Ended() (string, bool)
- func (s *Server) Handle(ctx context.Context, req ipc.Request) ipc.Response
- func (s *Server) Key(k Key)
- func (s *Server) Serve(ctx context.Context, ln net.Listener, lines <-chan string) error
- func (s *Server) Tick()
- type ServerConfig
- type Sized
- type StatusLine
- type Terminal
Constants ¶
const ( // The idle timeout and the maximum session length are the profile's // limits.idle_timeout and limits.max_session. ApprovalTimeout = kconsole.ApprovalTimeout PlanTTL = 10 * time.Minute // PolicyPoll is how often the config files are checked for changes. PolicyPoll = kconsole.PolicyPoll )
Session timeouts, spec §6.
const ( KeyShiftTab = kconsole.KeyShiftTab KeyCtrlO = kconsole.KeyCtrlO )
The control keys.
const ( Approved = kconsole.Approved Denied = kconsole.Denied Unanswered = kconsole.Unanswered RetypeRequested = kconsole.RetypeRequested NoFinger = kconsole.NoFinger )
Outcomes of an approval.
const FingerDeadline = kconsole.FingerDeadline
FingerDeadline bounds the wait for a finger after a typed yes.
const ResponseQuantum = kconsole.ResponseQuantum
ResponseQuantum levels the time a statement takes, as the client sees it: the answer to query.run, success or failure, leaves at the next multiple of it after the run started. A query cannot turn the time it takes into a fine-grained signal (a timing side channel).
Variables ¶
var ErrConfig = kconsole.ErrConfig
ErrConfig marks usage and configuration errors (exit code 3). It is lockkit's, which the isolation checks wrap too.
var ErrTooManyNoMatch = kconsole.ErrTooManyNoMatch
ErrTooManyNoMatch is set on the third consecutive no-match: the caller ends the console.
Functions ¶
func Run ¶
Run is `locksql console`: the start-up sequence of spec §6, then the request loop until Ctrl-C, logout, :quit or a timeout.
func SameUserRefused ¶ added in v0.1.2
SameUserRefused is the refusal of a console without a separated setup (sys nil, as sysconf.Load returns it), or nil.
Types ¶
type Beller ¶ added in v0.5.0
The console's terminal and its optional abilities (lockkit's console).
type KeySource ¶ added in v0.5.0
The console's terminal and its optional abilities (lockkit's console).
type LineSource ¶
type LineSource = kconsole.LineSource
The console's terminal and its optional abilities (lockkit's console).
type Options ¶
type Options struct {
Profile string
// Auto starts the console in auto mode (--auto); Shift+Tab switches
// the mode while it runs.
Auto bool
// AllowUnmask lets clients ask for unmasked output (--allow-unmask).
AllowUnmask bool
// ShowResults starts with the clear results on (--show-results);
// Ctrl-O switches them while the console runs.
ShowResults bool
Cwd string
IO IO
// Now defaults to time.Now.
Now func() time.Time
// StateDir defaults to config.StateDir().
StateDir string
// Version is the console version reported to clients.
Version string
// TTY is the console's terminal device (nil when unknown): its owner
// must be the console's account in a separated setup.
TTY *os.File
}
Options configure Run.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server serves client requests one at a time against one session. It is not safe for concurrent use: Serve runs every request on one goroutine.
func NewServer ¶
func NewServer(cfg ServerConfig) (*Server, error)
NewServer checks cfg and returns a server enforcing cfg.Policy.
func (*Server) CheckPolicy ¶
func (s *Server) CheckPolicy()
CheckPolicy re-reads the policy from the config files. Changes that only tighten are applied at once; a loosening waits for :review, and plans are refused with CodePolicyPending meanwhile.
func (*Server) Handle ¶
Handle serves one request. It is the whole client surface of the console: none of the methods loosens the policy.
func (*Server) Serve ¶
Serve accepts clients on ln and serves their requests one at a time until ctx ends or the session ends (logout, timeouts, :quit). lines are the console commands typed by the human (nil for none); the control keys come from the IO when it is a KeySource. ln is closed on return, which removes the socket. It is lockkit's request loop.
type ServerConfig ¶
type ServerConfig struct {
// Policy is the approved policy the server enforces.
Policy config.Policy
// RulesPath is the PII rules file: <project>/.locksql/pii.toml, or
// pii.toml in the user config directory outside a project.
RulesPath string
// StateDir and ApprovedKey locate the approved policy file.
StateDir string
ApprovedKey string
Session engine.Session
// DBUser is the database account in use (it may have been asked for).
DBUser string
Databases []string
Audit *audit.Log
IO IO
// Approver takes every human decision; nil means typed approvals.
Approver Approver
// Fingerprint is true when Approver is the fingerprint approver
// (level 2): a typed answer alone then never widens anything.
Fingerprint bool
// Boundary names the desktop boundary for the status screen ("" in
// the session shape).
Boundary string
Now func() time.Time
// Auto starts in auto mode: on non-production profiles, statements
// allowed by the tier and the weight check run without a prompt (never
// unmask, never REFUSE). Shift+Tab switches the mode while the console
// runs.
Auto bool
// AllowUnmask starts with unmasked output allowed: clients may ask for
// it, and each such query is approved in the console. Without it an
// unmask plan is refused before anything else. :unmask switches it
// while the console runs.
AllowUnmask bool
// ShowResults starts with the clear results on: the result of each
// masked run printed in the console, in clear; the client still gets
// it masked. Ctrl-O switches them while the console runs.
ShowResults bool
Version string
// LoadPolicy re-reads the current policy from the config files. Nil
// disables CheckPolicy.
LoadPolicy func() (config.Policy, error)
// Reconnect opens a new session after a lost connection, under p, the
// profile in force at that time. Nil means a lost connection ends the
// console.
Reconnect func(ctx context.Context, p config.Profile) (engine.Session, error)
// Quantum levels the response time of query.run (ResponseQuantum in
// the real console, 0 to disable).
Quantum time.Duration
// PeerAllowed decides which clients are served, from the kernel's
// credentials of the peer. Nil serves the console's own account only.
PeerAllowed func(ipc.Cred) bool
// Health is reported in status for locksql doctor.
Health *ipc.Health
}
ServerConfig holds what a Server needs once the start-up sequence is done. Run builds it; tests build it directly.
type StatusLine ¶ added in v0.5.0
type StatusLine = kconsole.StatusLine
The console's terminal and its optional abilities (lockkit's console).