Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support execve syscall on all OSs that can #1166

Merged
merged 1 commit into from
Feb 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions cli/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func ConfigureExecCommand(app *kingpin.Application, a *AwsVault) {
input.Config.NonChainedGetSessionTokenDuration = input.SessionDuration
input.Config.AssumeRoleDuration = input.SessionDuration
input.Config.SSOUseStdout = input.UseStdout
input.ShowHelpMessages = input.Command == "" && isATerminal() && os.Getenv("AWS_VAULT_DISABLE_HELP_MESSAGE") != "1"
input.ShowHelpMessages = !a.Debug && input.Command == "" && isATerminal() && os.Getenv("AWS_VAULT_DISABLE_HELP_MESSAGE") != "1"

f, err := a.AwsConfigFile()
if err != nil {
Expand Down Expand Up @@ -200,12 +200,14 @@ func ExecCommand(input ExecCommandInput, f *vault.ConfigFile, keyring keyring.Ke
}
printHelpMessage(subshellHelp, input.ShowHelpMessages)

if osSupportsExecSyscall() {
return doExecSyscall(input.Command, input.Args, cmdEnv)
err = doExecSyscall(input.Command, input.Args, cmdEnv) // will not return if exec syscall succeeds
if err != nil {
log.Println("Error doing execve syscall:", err.Error())
log.Println("Falling back to running a subprocess")
}
}

return runChildProcess(input.Command, input.Args, cmdEnv)
return runSubProcess(input.Command, input.Args, cmdEnv) // will only return once subprocess ends
}

func printHelpMessage(helpMsg string, showHelpMessages bool) {
Expand Down Expand Up @@ -319,8 +321,8 @@ func getDefaultShell() string {
return command
}

func runChildProcess(command string, args []string, env []string) error {
log.Printf("Starting subprocess: %s %s", command, strings.Join(args, " "))
func runSubProcess(command string, args []string, env []string) error {
log.Printf("Starting a subprocess: %s %s", command, strings.Join(args, " "))

cmd := osexec.Command(command, args...)
cmd.Stdin = os.Stdin
Expand Down Expand Up @@ -353,10 +355,6 @@ func runChildProcess(command string, args []string, env []string) error {
return nil
}

func osSupportsExecSyscall() bool {
return runtime.GOOS == "linux" || runtime.GOOS == "darwin" || runtime.GOOS == "freebsd" || runtime.GOOS == "openbsd"
}

func doExecSyscall(command string, args []string, env []string) error {
log.Printf("Exec command %s %s", command, strings.Join(args, " "))

Expand Down