sshgate

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 9 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 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

View Source
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.

View Source
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

View Source
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.

View Source
var ErrPattern = errors.New("not an ssh pattern")

ErrPattern is wrapped by every refusal of ValidatePattern.

View Source
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.

View Source
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

func HostKeyTarget(address, keyType, fingerprint string) string

HostKeyTarget is the Target of a host key's check: "fw.example ssh-ed25519 SHA256:…".

func Match

func Match(pat, target string) bool

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

func SplitTarget(target string) (Endpoint, Argv, bool)

SplitTarget reads a Target back: the endpoint and the command's words.

func Suggest

func Suggest(target string) []string

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

func Target(e Endpoint, argv Argv) string

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

func ValidatePattern(p string) error

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

func Parse(line string) (Argv, error)

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.

func (Argv) String

func (a Argv) String() string

String is the command's canonical form, the one a target and a rule show: a word of only safe characters as it is, any other in single quotes ('it'\”s'). Parse reads it back to the same words.

func (Argv) Wire

func (a Argv) Wire() string

Wire is what is sent as the exec request's command: every word single-quoted, the program too, so the login shell on the other side recognises no keyword, alias, assignment or operator in it and runs the program with exactly these arguments.

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

func ParseEndpoint(s string) (Endpoint, error)

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

func (e Endpoint) Address() string

Address is the host with its port, as the permission tree and a secret's destinations name it: "fw.example", "fw.example:2222".

func (Endpoint) Dial

func (e Endpoint) Dial() string

Dial is the address to connect to, the port always stated.

func (Endpoint) String

func (e Endpoint) String() string

Jump to

Keyboard shortcuts

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