mesh-cli: carry what a pipe or a file gives standard input with the line, at most 64 KiB
mesh/merge-gate pass: builds mesh-cli → ace, g14, novox, shanks; no bus step; every machine composes with the change as it did without (4 of 4 compose)
mesh/repo-check pass: its merge-check.sh passed, each part in its toolchain: merge-check.sh (go), merge-check-typescript.sh (typescript)
mesh/delivery delivered
mesh/merge-gate pass: builds mesh-cli → ace, g14, novox, shanks; no bus step; every machine composes with the change as it did without (4 of 4 compose)
mesh/repo-check pass: its merge-check.sh passed, each part in its toolchain: merge-check.sh (go), merge-check-typescript.sh (typescript)
mesh/delivery delivered
So a secret reaches the controller's terminal without standing on a command line: mesh-cli secret accept <node> <module> <name> --from - < file. A terminal is never read, more than the bound is refused before anything is asked, and nothing carried is printed. mesh-sdk moves to f047d0a.
This commit is contained in:
@@ -23,12 +23,42 @@ import (
|
||||
// socket is where the node-engine answers; a variable so a test can name its own.
|
||||
var socket = cli.Socket
|
||||
|
||||
// standardInput is mesh-cli's own standard input, and whether it is a terminal (or a device such as /dev/null),
|
||||
// which is never read; a variable so a test can say.
|
||||
var standardInput = func() (io.Reader, bool) {
|
||||
info, err := os.Stdin.Stat()
|
||||
if err != nil {
|
||||
return os.Stdin, true
|
||||
}
|
||||
return os.Stdin, info.Mode()&os.ModeCharDevice != 0
|
||||
}
|
||||
|
||||
// carried is what mesh-cli carries of its standard input for the line: what a pipe or a file held, at most
|
||||
// cli.MaxStdin, for the controller's terminal alone (a secret given with `secret accept … --from -`). A terminal is
|
||||
// never read: the line is asked without. More than the bound is refused, and nothing is asked.
|
||||
func carried() ([]byte, error) {
|
||||
in, terminal := standardInput()
|
||||
if terminal {
|
||||
return nil, nil
|
||||
}
|
||||
body, err := io.ReadAll(io.LimitReader(in, cli.MaxStdin+1))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("standard input could not be read (%v); nothing was asked", err)
|
||||
}
|
||||
if len(body) > cli.MaxStdin {
|
||||
return nil, fmt.Errorf("standard input is more than %d bytes, which mesh-cli does not carry; nothing was asked", cli.MaxStdin)
|
||||
}
|
||||
return body, nil
|
||||
}
|
||||
|
||||
const usage = `mesh-cli — the controller's command lines, from this node (novox/hq ADR 0272)
|
||||
|
||||
mesh-cli <command line> e.g. mesh-cli status, mesh-cli settings show zsh --node <node>
|
||||
nox <command line> the same, in interactive zsh
|
||||
|
||||
Run it as yourself, never under sudo: the node-engine tells the controller which account asks.
|
||||
What a pipe or a file gives its standard input (at most 64 KiB) goes with the line to the controller's
|
||||
terminal alone, e.g. a secret: mesh-cli secret accept <node> <module> <name> --from - < file
|
||||
On the control-node, from its operator's account, the line runs as the controller's terminal.
|
||||
Anywhere else it is an ordinary call, and a terminal-only change is refused with the reason.
|
||||
'mesh-cli help' asks the controller for its own list of command lines.
|
||||
@@ -52,7 +82,12 @@ func run(ctx context.Context, args []string, stdout, stderr io.Writer) int {
|
||||
"Nothing was asked\n", verb)
|
||||
return 1
|
||||
}
|
||||
a, err := cli.Ask(ctx, socket, args)
|
||||
in, err := carried()
|
||||
if err != nil {
|
||||
fmt.Fprintf(stderr, "mesh-cli: %v\n", err)
|
||||
return 1
|
||||
}
|
||||
a, err := cli.AskWith(ctx, socket, cli.Request{Line: args, Stdin: in})
|
||||
if err != nil {
|
||||
if errors.Is(ctx.Err(), context.Canceled) {
|
||||
fmt.Fprintln(stderr, "mesh-cli: stopped waiting; the line may still be running on the controller")
|
||||
|
||||
Reference in New Issue
Block a user