| shell_exec_whitelist |
function |
go |
infra |
1.0.0 |
impure |
func ShellExecWhitelist(opts ShellExecOpts) (ShellExecResult, error) |
Ejecuta argv shell con whitelist obligatoria de binarios, SIN shell expansion, timeout context-cancellable con SIGTERM+SIGKILL, stdout/stderr separados con truncate opcional. Para device_agent y otros sandboxes que reciben requests externos. |
| shell |
| exec |
| security |
| sandbox |
| device-agent |
| infra |
| agents |
| docker |
|
|
| shell_exec_result_go_infra |
| error_go_core |
|
| shell_exec_result_go_infra |
|
false |
error_go_core |
| bytes |
| context |
| fmt |
| os |
| os/exec |
| os/user |
| path/filepath |
| strconv |
| strings |
| syscall |
| time |
|
true |
| echo whitelisted returns stdout |
| binary not in whitelist rejected without spawn |
| timeout kills process and sets TimedOut |
| empty whitelist returns error |
| stdin payload passes to process |
| output exceeding MaxOutputBytes is truncated |
| absolute path in whitelist matches resolved binary |
|
functions/infra/shell_exec_whitelist_test.go |
functions/infra/shell_exec_whitelist.go |
| name |
desc |
| opts.Cmd |
argv completo. Cmd[0] es el binario (path absoluto o nombre en PATH). Obligatorio, no puede estar vacío. |
|
| name |
desc |
| opts.BinariesAllowed |
Whitelist de binarios permitidos. EMPTY = rechaza todo sin spawn (defense in depth). Entry con / se compara con path resolvido; entry bare name se compara con basename del resolvido. |
|
| name |
desc |
| opts.Env |
Variables de entorno KEY=VAL. Si vacío, se aplica entorno mínimo: PATH=/usr/bin:/bin, HOME, USER, LANG. |
|
| name |
desc |
| opts.WorkingDir |
Directorio de trabajo. Si vacío usa HOME del usuario actual. |
|
| name |
desc |
| opts.TimeoutSeconds |
Timeout máximo en segundos. Default 30. Al expirar: SIGTERM → espera 1s → SIGKILL. |
|
| name |
desc |
| opts.StdinPayload |
Bytes a pasar como stdin al proceso. Nil/vacío = sin stdin. |
|
| name |
desc |
| opts.MaxOutputBytes |
Límite de bytes por stream (stdout y stderr por separado). Default 1 MB. Activa Truncated=true si se supera. |
|
| name |
desc |
| opts.User |
Usuario para ejecutar el proceso (nombre o 'uid:gid'). Requiere uid=0. Vacío = usuario actual. |
|
|
ShellExecResult con ExitCode, Stdout, Stderr, Duration (ms), Truncated y TimedOut. |