Documentation
¶
Overview ¶
Package cliconsole turns one typed console line into a vetted argv for the platform CLI and runs it as a child process. It is never a shell.
Index ¶
- Constants
- Variables
- func Check(argv []string) (string, error)
- func DeniedFlags() []string
- func DispatchArgs(argv []string) []string
- func Env(apiURL, token, home, experimental string) []string
- func FlagDenied(name string) bool
- func IsHost(argv []string) bool
- func IsReject(err error) bool
- func KilledByEnv() bool
- func LocateBinary(binaryName string) (string, error)
- func ParseLine(line string) ([]string, error)
- func Redact(argv []string, path string) string
- func SanitizeLine(line string, maxBytes int, secrets ...string) string
- type AllowEntry
- type Command
- type Config
- type RejectError
- type Result
- type Runner
Constants ¶
const ( EnvKillSwitch = "APP_CLI_CONSOLE" EnvIdleTimeout = "APP_CLI_CONSOLE_IDLE_TIMEOUT" EnvCommandTimeout = "APP_CLI_CONSOLE_COMMAND_TIMEOUT" EnvMaxOutput = "APP_CLI_CONSOLE_MAX_OUTPUT_BYTES" EnvMaxLine = "APP_CLI_CONSOLE_MAX_LINE_BYTES" EnvMaxSession = "APP_CLI_CONSOLE_MAX_SESSION" EnvOpensPerMinute = "APP_CLI_CONSOLE_OPENS_PER_MINUTE" EnvBinary = "APP_CLI_BINARY" EnvRunAsUser = "APP_CLI_CONSOLE_USER" )
Environment knobs. APP_CLI_CONSOLE=off wins over the Settings switch.
const ( MaxLineBytes = 4096 MaxArgs = 64 )
Limits on one console line.
const ( StreamStdout = "stdout" StreamStderr = "stderr" )
Output streams.
Variables ¶
var ErrBinaryMissing = errors.New("CLI binary not found")
ErrBinaryMissing means no usable CLI binary was found.
Functions ¶
func Check ¶
Check vets argv against the CLI command tree, the command allowlist and the flag deny rules. It returns the matched command path, for audit.
func DeniedFlags ¶
func DeniedFlags() []string
DeniedFlags returns the refused flag names, sorted, for docs and tests.
func DispatchArgs ¶
DispatchArgs is the argv the CLI dispatches on after it removes scope flags.
func Env ¶
Env builds the child's whole environment: nothing inherited from the control plane, only the loopback API address and the session token.
func FlagDenied ¶
FlagDenied reports whether the console refuses flag name on every command.
func KilledByEnv ¶
func KilledByEnv() bool
KilledByEnv reports whether the environment switches the console off.
func LocateBinary ¶
LocateBinary finds the CLI: APP_CLI_BINARY, else "<binaryName>-cli" next to the running control plane. Never PATH, so the server's PATH cannot pick it.
func ParseLine ¶
ParseLine splits line into words with POSIX-style quoting and no expansion. Shell syntax is refused rather than passed through, so nothing typed here can look like it chains, redirects or substitutes.
func Redact ¶
Redact renders argv for the audit log with secret-looking values masked. It errs toward masking: an audit row never needs the value itself.
func SanitizeLine ¶
SanitizeLine makes one line of child output safe for the browser terminal and the audit log: no terminal escapes or control bytes, secrets masked, length capped. secrets are exact values to mask, such as the session token.
Types ¶
type AllowEntry ¶
AllowEntry is one reviewed command path the console may run.
func Allowlist ¶
func Allowlist() []AllowEntry
Allowlist returns the reviewed command table, for docs and the drift test.
type Config ¶
type Config struct {
IdleTimeout time.Duration
CommandTimeout time.Duration
MaxSession time.Duration
MaxOutputBytes int64
MaxLineBytes int
OpensPerMinute int
RunAsUser string
}
Config is the console's resolved environment.
func LoadConfig ¶
func LoadConfig() Config
LoadConfig reads the environment, falling back to safe defaults on bad values.
type RejectError ¶
type RejectError struct{ Reason string }
RejectError explains why a line was refused. Its message is safe to show the operator.
func (*RejectError) Error ¶
func (e *RejectError) Error() string