@@ -108,7 +108,6 @@ func ConfigureExecCommand(app *kingpin.Application, a *AwsVault) {
108
108
StringVar (& input .ProfileName )
109
109
110
110
cmd .Arg ("cmd" , "Command to execute, defaults to $SHELL" ).
111
- Default (os .Getenv ("SHELL" )).
112
111
StringVar (& input .Command )
113
112
114
113
cmd .Arg ("args" , "Command arguments" ).
@@ -200,14 +199,15 @@ func updateEnvForAwsVault(env environ, profileName string, region string) enviro
200
199
}
201
200
202
201
func execEc2Server (input ExecCommandInput , config * vault.Config , credsProvider aws.CredentialsProvider ) error {
202
+ fmt .Fprintf (os .Stderr , "aws-vault: Starting an EC2 credential server.\n " )
203
203
if err := server .StartEc2CredentialsServer (context .TODO (), credsProvider , config .Region ); err != nil {
204
204
return fmt .Errorf ("Failed to start credential server: %w" , err )
205
205
}
206
206
207
207
env := environ (os .Environ ())
208
208
env = updateEnvForAwsVault (env , input .ProfileName , config .Region )
209
209
210
- return execCmd (input .Command , input .Args , env )
210
+ return doRunCmd (input .Command , input .Args , env )
211
211
}
212
212
213
213
func execEcsServer (input ExecCommandInput , config * vault.Config , credsProvider aws.CredentialsProvider ) error {
@@ -228,7 +228,9 @@ func execEcsServer(input ExecCommandInput, config *vault.Config, credsProvider a
228
228
env .Set ("AWS_CONTAINER_CREDENTIALS_FULL_URI" , ecsServer .BaseURL ())
229
229
env .Set ("AWS_CONTAINER_AUTHORIZATION_TOKEN" , ecsServer .AuthToken ())
230
230
231
- return execCmd (input .Command , input .Args , env )
231
+ fmt .Fprintf (os .Stderr , "aws-vault: Starting an ECS credential server; your app's AWS sdk must support AWS_CONTAINER_CREDENTIALS_FULL_URI.\n " )
232
+
233
+ return doRunCmd (input .Command , input .Args , env )
232
234
}
233
235
234
236
func execCredentialHelper (input ExecCommandInput , credsProvider aws.CredentialsProvider ) error {
@@ -293,10 +295,10 @@ func execEnvironment(input ExecCommandInput, config *vault.Config, credsProvider
293
295
}
294
296
295
297
if ! supportsExecSyscall () {
296
- return execCmd (input .Command , input .Args , env )
298
+ return doRunCmd (input .Command , input .Args , env )
297
299
}
298
300
299
- return execSyscall (input .Command , input .Args , env )
301
+ return doExecSyscall (input .Command , input .Args , env )
300
302
}
301
303
302
304
// environ is a slice of strings representing the environment, in the form "key=value".
@@ -319,8 +321,21 @@ func (e *environ) Set(key, val string) {
319
321
* e = append (* e , key + "=" + val )
320
322
}
321
323
322
- func execCmd (command string , args []string , env []string ) error {
323
- log .Printf ("Starting child process: %s %s" , command , strings .Join (args , " " ))
324
+ func getDefaultShell () string {
325
+ command := os .Getenv ("SHELL" )
326
+ if command == "" {
327
+ command = "/bin/sh"
328
+ }
329
+ return command
330
+ }
331
+
332
+ func doRunCmd (command string , args []string , env []string ) error {
333
+ if command == "" {
334
+ command = getDefaultShell ()
335
+ fmt .Fprintf (os .Stderr , "aws-vault: Starting a subshell %s\n " , command )
336
+ }
337
+
338
+ log .Printf ("Starting subprocess: %s %s" , command , strings .Join (args , " " ))
324
339
325
340
cmd := osexec .Command (command , args ... )
326
341
cmd .Stdin = os .Stdin
@@ -356,7 +371,12 @@ func supportsExecSyscall() bool {
356
371
return runtime .GOOS == "linux" || runtime .GOOS == "darwin" || runtime .GOOS == "freebsd" || runtime .GOOS == "openbsd"
357
372
}
358
373
359
- func execSyscall (command string , args []string , env []string ) error {
374
+ func doExecSyscall (command string , args []string , env []string ) error {
375
+ if command == "" {
376
+ command = getDefaultShell ()
377
+ fmt .Fprintf (os .Stderr , "aws-vault: Starting a subshell %s\n " , command )
378
+ }
379
+
360
380
log .Printf ("Exec command %s %s" , command , strings .Join (args , " " ))
361
381
362
382
argv0 , err := osexec .LookPath (command )
0 commit comments