Documentation
¶
Overview ¶
Package sshgate is what a command on a remote host means to the gate (ADR-35): the Kind ssh_exec checks, its target "<user>@<host> <command>", how a rule's pattern covers one (Match) and which wider rule an answer may choose (Suggest). Like netgate and pathgate it is a leaf: the permission tree's ssh target type matches through it, and the tool that runs commands (internal/ssh) builds its targets with it.
A command is never handed to a shell as the model wrote it. Parse reads it into words with a shell's quoting and refuses everything else a shell would interpret; Wire quotes every word for the remote login shell. So a rule that allows "docker ps *" allows docker with ps and arguments, and nothing chained, piped or substituted behind it: "docker ps; rm -rf /" is refused before it is checked, and "docker ps ';' rm" runs docker with the arguments ";" and "rm". A pipeline is `sh -c '…'`, a command of its own that only a rule naming sh covers.
Index ¶
- Constants
- Variables
- func HostKeyTarget(address, keyType, fingerprint string) string
- func Match(pat, target string) bool
- func SplitTarget(target string) (Endpoint, Argv, bool)
- func Suggest(target string) []string
- func Target(e Endpoint, argv Argv) string
- func ValidatePattern(p string) error
- type Argv
- type Endpoint
Constants ¶
const HostKeyKind = "ssh.hostkey"
HostKeyKind is the gate Kind of trusting a host's key on the first connection to it. Its Target is "<host> <key type> <fingerprint>" (HostKeyTarget). It is no node of the tree and nothing remembers an answer to it there: an approved key is kept in the workspace's known hosts.
const Kind = "ssh"
Kind is the gate Kind of running a command over SSH. Its Target is "<user>@<host> <command>" (Target), the host with its port when that is not 22.
Variables ¶
var ErrCommand = errors.New("not one plain command")
ErrCommand is wrapped by every refusal of Parse: a command that is not one plain command line.
var ErrPattern = errors.New("not an ssh pattern")
ErrPattern is wrapped by every refusal of ValidatePattern.
var HostKeySpec = kinds.Spec{Kind: HostKeyKind, Attended: kinds.Ask, Unattended: kinds.Ask}
HostKeySpec registers HostKeyKind: a confirmation of Kind (Spec.Confirms), asked of a person every time a host is new, never by voice.
var Spec = kinds.Spec{Kind: Kind, Attended: kinds.Ask, Unattended: kinds.Ask, Target: "ssh", Confirms: []string{HostKeyKind}}
Spec registers Kind: a command on a server asks wherever somebody could answer, and never by voice (a speaker in a room must not run anything on a server). Its target type is the tree's "ssh", and trusting a new host's key is its confirmation.
Functions ¶
func HostKeyTarget ¶
HostKeyTarget is the Target of a host key's check: "fw.example ssh-ed25519 SHA256:…".
func Match ¶
Match reports whether a rule's pattern covers a target: "*" covers every target; otherwise the user (when the pattern names one), the host by netgate.Match, and the command word by word. In a word, * matches any run of characters and ? one, neither of them "/" nor a "." that starts a path segment, as a shell's pathname glob would ("/var/log/*" covers neither "/var/log/a/b" nor "/var/log/.."). A malformed pattern or target covers nothing. It is the matcher of the permission tree's ssh target type.
func SplitTarget ¶
SplitTarget reads a Target back: the endpoint and the command's words.
func Suggest ¶
Suggest lists the widenings an answer may choose instead of the exact target: the same command's first word or two with any arguments after them ("admin@fw docker ps *" for "docker ps -a"), and the same command on the parent domain's hosts. It never offers every command: "<host> *" is something the owner writes out. Nor does it widen a command whose first words name a runner (runners: "sh -c *", "python3 *", "sudo *" would each be every command): those keep their exact words, on the host or its parent domain.
func Target ¶
Target is the Target of a Kind check: "<user>@<host> <command>", the command in its canonical form (Argv.String). The user is the login the secret names, never one the model chose.
func ValidatePattern ¶
ValidatePattern refuses what Match would never let cover a target: a pattern without a command, a malformed host or user, a command a shell would have to interpret. "*" alone is valid: every endpoint and every command, a blank cheque the owner writes out.
Types ¶
type Argv ¶
type Argv []string
Argv is a command as the words it runs with: Argv[0] is the program, the rest its arguments. No shell has interpreted it and none will: Wire quotes every word, so the remote login shell, which runs every SSH exec and must be POSIX sh-compatible, sees exactly these words.
func Parse ¶
Parse reads a command line into its words, with the quoting a POSIX shell has and nothing else: single quotes, double quotes (in which \" \\ \$ and \` are escapes) and a backslash before any character. Everything a shell would do beyond splitting words is refused rather than passed on, unquoted: operators (; & | < > ( )), expansions ($ `), globs (* ? [ ]), braces, a tilde, a comment and "!". So is a control character anywhere, a newline included, a word that never ends, and an empty command. A refusal says what to quote, or that a pipeline is `sh -c '…'`, a command of its own that a rule must allow by its name.
A word that holds a backslash is refused too, however it was quoted: Wire's single quotes keep one literal only for a POSIX shell, and a login shell that reads "\'" inside them as an escape (fish) pairs the quotes differently: the word a\';reboot;# would run reboot there.
type Endpoint ¶
type Endpoint struct {
User string
// Host is lower-case, without a trailing dot; Port is "" for 22.
Host string
Port string
}
Endpoint is where a command runs: a login on a host, with the port when it is not 22.
func ParseEndpoint ¶
ParseEndpoint reads "[user@]host[:port]" as a tool's argument or a secret's destination says it. The host is a name or an IPv4 address (letters, digits, '.', '-', '_'), folded to lower case; port 22 is dropped, so "fw.example:22" and "fw.example" are one endpoint. A user is optional here.
func (Endpoint) Address ¶
Address is the host with its port, as the permission tree and a secret's destinations name it: "fw.example", "fw.example:2222".