Documentation
¶
Index ¶
- Constants
- func NewExecCmd(newClient clientFactory, ios *utils.IOStreams) *cobra.Command
- func ParseEnvArg(ios *utils.IOStreams, arg string, env map[string]string) string
- func RemoteExec(ios *utils.IOStreams, newClient clientFactory, stdout, stderr io.Writer, ...) error
- func RunCommandWithRetry(ac *client.AlpaconClient, serverName, command, username, groupname string, ...) error
- func RunExecWithApprovalWait(ios *utils.IOStreams, ac *client.AlpaconClient, ...) error
- func RunExecWithPresenceStepUp(ios *utils.IOStreams, ac *client.AlpaconClient, ...) error
- func RunFileExecWithApprovalWait(ios *utils.IOStreams, ac *client.AlpaconClient, serverName string, ...) error
- func ShellJoin(parts []string) string
- type FileExecArgs
- type Invocation
- type RemoteExecArgs
Constants ¶
const DefaultInterpreter = "/bin/bash"
DefaultInterpreter runs a verified file when --interpreter names none.
const FileContentMaxBytes = 65536
FileContentMaxBytes is the server's ceiling on a verified file's content: 64 KB, counted in UTF-8 bytes. Checked locally so an oversized script is refused before it travels.
const PurposeMaxLength = 2000
PurposeMaxLength is the server's ceiling on a stated purpose. Checked here so an over-long one is a usage error rather than a 400 that costs a parked command its one demand.
Variables ¶
This section is empty.
Functions ¶
func NewExecCmd ¶ added in v1.20.0
func ParseEnvArg ¶ added in v1.9.0
ParseEnvArg parses a --env token into env. A bare KEY reads the shell value, warning and skipping if unset; malformed input returns an error message.
func RemoteExec ¶ added in v1.20.0
func RemoteExec(ios *utils.IOStreams, newClient clientFactory, stdout, stderr io.Writer, parsed RemoteExecArgs) error
RemoteExec is the shared post-parse execution path for exec and websh command mode, returning the failure as a utils.ExitError. Requires Server, Command or File, and the parsed --output applied.
func RunCommandWithRetry ¶ added in v1.3.2
func RunCommandWithRetry(ac *client.AlpaconClient, serverName, command, username, groupname string, env map[string]string, selection *worksession.Selection, purpose string, out io.Writer) error
RunCommandWithRetry streams a command and handles submission retries on one event stream. It reads selection before every attempt so a settled WorkSession reaches the resend.
func RunExecWithApprovalWait ¶ added in v1.7.2
func RunExecWithApprovalWait(ios *utils.IOStreams, ac *client.AlpaconClient, serverName, command, username, groupname string, env map[string]string, selection *worksession.Selection, purpose string, waitTimeout time.Duration, out io.Writer) error
RunExecWithApprovalWait runs a command via RunExecWithPresenceStepUp and, when it is denied with an approval request in flight and waitTimeout is positive, polls the command's detail until a reviewer grants or refuses the request or the timeout elapses. A job the server parked at awaiting_approval is instead streamed once approved. With no positive waitTimeout, or on a terminal denial, it returns the first err unchanged.
A poll that never reached the server is not an answer: the loop backs off. A timeout, a run of failed polls, or a fatal 4xx on the read returns the denial that opened the wait, so the caller still exits on the pending contract.
The poll reads sudo_grant_status rather than re-submitting the command, which would file a fresh approval request on every tick.
func RunExecWithPresenceStepUp ¶ added in v1.7.2
func RunExecWithPresenceStepUp(ios *utils.IOStreams, ac *client.AlpaconClient, serverName, command, username, groupname string, env map[string]string, selection *worksession.Selection, purpose string, out io.Writer) error
RunExecWithPresenceStepUp runs a command via RunCommandWithRetry and, when it is denied for a missing recent MFA (SUDO_PRESENCE_REQUIRED) on an interactive terminal, offers an MFA step-up and retries once. A non-interactive human gets the verification link for out-of-band MFA. Agent mode carries the link in the denial for commandResultFailure to render as a next action. Interactive websh keeps its own sudo MFA flow.
func RunFileExecWithApprovalWait ¶ added in v1.13.1
func RunFileExecWithApprovalWait(ios *utils.IOStreams, ac *client.AlpaconClient, serverName string, file event.FileExecution, username, groupname string, selection *worksession.Selection, purpose string, waitTimeout time.Duration, out io.Writer) error
RunFileExecWithApprovalWait is RunExecWithApprovalWait for the verified file lane. Only the submission differs—the file object in place of a command line—so the presence step-up, the approval wait and the re-run after a grant are the same layers the generic lane runs through.
func ShellJoin ¶ added in v1.4.8
ShellJoin reassembles tokenized command parts into a single string. Parts containing whitespace or single quotes are re-quoted to preserve argument boundaries; metacharacters pass through for the remote shell. A single-element slice is returned as-is (already a formed command line).
Types ¶
type FileExecArgs ¶ added in v1.13.1
type FileExecArgs struct {
// Path is the script's location on the target server, and by default the
// local file the content is read from.
Path string
// From, when set, is the local file the content is read from instead.
From string
// Interpreter runs the file on the target; DefaultInterpreter when empty.
Interpreter string
// Args are passed to the script as given, one argv entry each.
Args []string
// ReuseDays is the proposed reuse duration in days; 0 means none was given.
ReuseDays int
// Upload writes the content to Path on the server before the submission,
// so the file need not be there already.
Upload bool
// Overwrite lets Upload replace a file already at Path; without it the
// agent refuses an existing file.
Overwrite bool
// FromServer reads the content from Path on the server instead of a local
// file, for a script that exists only there.
FromServer bool
}
FileExecArgs is the file lane as given on the command line: --file, --file-from, --interpreter, --reuse-days, --upload, --overwrite, --from-server and the arguments after --. From and Interpreter stay empty when their flag was not given, so a re-run hint repeats only what the user typed.
type Invocation ¶ added in v1.9.2
type Invocation string
Invocation names the command the user ran, so a hint can show an example they can copy without translating it first. A defined type rather than a bare string, so an arbitrary string variable cannot reach it without a conversion that names the intent. Websh command mode reaches this package through RemoteExecArgs.InvokedAs; the zero value renders as exec.
const ( ExecInvocation Invocation = "alpacon exec" WebshInvocation Invocation = "alpacon websh" )
ExecInvocation and WebshInvocation are the two Invocation values (see the Invocation type below).
type RemoteExecArgs ¶ added in v1.3.2
type RemoteExecArgs struct {
Username string
Groupname string
WorkSessionID string
OutputFormat string
OutputGiven bool
OutputMissing bool
Server string
Command string
// What this command is for. Sent on submission, so the assessor judges
// with it on the first pass and no demand is issued.
Purpose string
// InvokedAs selects which syntax a hint renders its example in. The caller
// sets it, not ParseRemoteExecArgs: websh command mode marks its args
// WebshInvocation, and exec leaves it empty, which the hint reads as exec.
InvokedAs Invocation
Env map[string]string
WaitApproval time.Duration
// WaitApprovalRaw is --wait-approval as typed, trimmed, so a hint repeats the user's own value.
WaitApprovalRaw string
Detach bool
Wait bool
ShowHelp bool
Err string
// File is set by --file and selects the verified file lane, in which case Command is empty and
// the words after -- are the script's arguments. Nil on the generic lane.
File *FileExecArgs
}
RemoteExecArgs holds parsed arguments for remote command execution.
func ParseRemoteExecArgs ¶ added in v1.3.2
func ParseRemoteExecArgs(ios *utils.IOStreams, args []string) RemoteExecArgs
ParseRemoteExecArgs parses raw CLI arguments with manual flag handling. Flags are recognized only before the server name.
The -- separator has two roles depending on position:
- After the server name: everything after it is the remote command, with no further flag parsing.
- Before the server name: it ends the flags; the first arg after it is the server, the rest is the command.
Without --, everything after the server name is the remote command.
Layout: [flags] [USER@]SERVER [--] COMMAND...
With --file the words after the server are the script's arguments and must follow --, so a command line is never mistaken for a verified file's arguments.
func (RemoteExecArgs) WaitTimeout ¶ added in v1.9.1
func (a RemoteExecArgs) WaitTimeout() time.Duration
WaitTimeout returns the effective approval-wait timeout, or 0 when not waiting.