@@ -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" ).
@@ -209,14 +208,15 @@ func updateEnvForAwsVault(env environ, profileName string, region string) enviro
209
208
}
210
209
211
210
func execEc2Server (input ExecCommandInput , config * vault.Config , credsProvider aws.CredentialsProvider ) error {
211
+ fmt .Fprintf (os .Stderr , "aws-vault: Starting an EC2 credential server.\n " )
212
212
if err := server .StartEc2CredentialsServer (context .TODO (), credsProvider , config .Region ); err != nil {
213
213
return fmt .Errorf ("Failed to start credential server: %w" , err )
214
214
}
215
215
216
216
env := environ (os .Environ ())
217
217
env = updateEnvForAwsVault (env , input .ProfileName , config .Region )
218
218
219
- return execCmd (input .Command , input .Args , env )
219
+ return doRunCmd (input .Command , input .Args , env )
220
220
}
221
221
222
222
func execEcsServer (input ExecCommandInput , config * vault.Config , credsProvider aws.CredentialsProvider ) error {
@@ -237,7 +237,9 @@ func execEcsServer(input ExecCommandInput, config *vault.Config, credsProvider a
237
237
env .Set ("AWS_CONTAINER_CREDENTIALS_FULL_URI" , ecsServer .BaseURL ())
238
238
env .Set ("AWS_CONTAINER_AUTHORIZATION_TOKEN" , ecsServer .AuthToken ())
239
239
240
- return execCmd (input .Command , input .Args , env )
240
+ fmt .Fprintf (os .Stderr , "aws-vault: Starting an ECS credential server; your app's AWS sdk must support AWS_CONTAINER_CREDENTIALS_FULL_URI.\n " )
241
+
242
+ return doRunCmd (input .Command , input .Args , env )
241
243
}
242
244
243
245
func execEnvironment (input ExecCommandInput , config * vault.Config , credsProvider aws.CredentialsProvider ) error {
@@ -265,10 +267,10 @@ func execEnvironment(input ExecCommandInput, config *vault.Config, credsProvider
265
267
}
266
268
267
269
if ! supportsExecSyscall () {
268
- return execCmd (input .Command , input .Args , env )
270
+ return doRunCmd (input .Command , input .Args , env )
269
271
}
270
272
271
- return execSyscall (input .Command , input .Args , env )
273
+ return doExecSyscall (input .Command , input .Args , env )
272
274
}
273
275
274
276
// environ is a slice of strings representing the environment, in the form "key=value".
@@ -291,8 +293,21 @@ func (e *environ) Set(key, val string) {
291
293
* e = append (* e , key + "=" + val )
292
294
}
293
295
294
- func execCmd (command string , args []string , env []string ) error {
295
- log .Printf ("Starting child process: %s %s" , command , strings .Join (args , " " ))
296
+ func getDefaultShell () string {
297
+ command := os .Getenv ("SHELL" )
298
+ if command == "" {
299
+ command = "/bin/sh"
300
+ }
301
+ return command
302
+ }
303
+
304
+ func doRunCmd (command string , args []string , env []string ) error {
305
+ if command == "" {
306
+ command = getDefaultShell ()
307
+ fmt .Fprintf (os .Stderr , "aws-vault: Starting a subshell %s\n " , command )
308
+ }
309
+
310
+ log .Printf ("Starting subprocess: %s %s" , command , strings .Join (args , " " ))
296
311
297
312
cmd := osexec .Command (command , args ... )
298
313
cmd .Stdin = os .Stdin
@@ -328,7 +343,12 @@ func supportsExecSyscall() bool {
328
343
return runtime .GOOS == "linux" || runtime .GOOS == "darwin" || runtime .GOOS == "freebsd" || runtime .GOOS == "openbsd"
329
344
}
330
345
331
- func execSyscall (command string , args []string , env []string ) error {
346
+ func doExecSyscall (command string , args []string , env []string ) error {
347
+ if command == "" {
348
+ command = getDefaultShell ()
349
+ fmt .Fprintf (os .Stderr , "aws-vault: Starting a subshell %s\n " , command )
350
+ }
351
+
332
352
log .Printf ("Exec command %s %s" , command , strings .Join (args , " " ))
333
353
334
354
argv0 , err := osexec .LookPath (command )
0 commit comments