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

fix: listen on all interfaces for ecs-server #1199

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
35 changes: 20 additions & 15 deletions cli/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,19 @@ import (
)

type ExecCommandInput struct {
ProfileName string
Command string
Args []string
StartEc2Server bool
StartEcsServer bool
Lazy bool
JSONDeprecated bool
Config vault.ProfileConfig
SessionDuration time.Duration
NoSession bool
UseStdout bool
ShowHelpMessages bool
ProfileName string
Command string
Args []string
StartEc2Server bool
StartEcsServer bool
ServerListenAddress string
Lazy bool
JSONDeprecated bool
Config vault.ProfileConfig
SessionDuration time.Duration
NoSession bool
UseStdout bool
ShowHelpMessages bool
}

func (input ExecCommandInput) validate() error {
Expand Down Expand Up @@ -100,6 +101,10 @@ func ConfigureExecCommand(app *kingpin.Application, a *AwsVault) {

cmd.Flag("ecs-server", "Run a ECS credential server in the background for credentials (the SDK or app must support AWS_CONTAINER_CREDENTIALS_FULL_URI)").
BoolVar(&input.StartEcsServer)

cmd.Flag("listen-address", "Define which host the server should run listen. Defaults to 127.0.0.1").
Default("127.0.0.1").
StringVar(&input.ServerListenAddress)

cmd.Flag("lazy", "When using --ecs-server, lazily fetch credentials").
BoolVar(&input.Lazy)
Expand Down Expand Up @@ -202,7 +207,7 @@ func ExecCommand(input ExecCommandInput, f *vault.ConfigFile, keyring keyring.Ke
printHelpMessage(subshellHelp, input.ShowHelpMessages)
} else if input.StartEcsServer {
printHelpMessage("Starting a local ECS credential server; your app's AWS sdk must support AWS_CONTAINER_CREDENTIALS_FULL_URI.", input.ShowHelpMessages)
if err = startEcsServerAndSetEnv(credsProvider, config, input.Lazy, &cmdEnv); err != nil {
if err = startEcsServerAndSetEnv(credsProvider, config, input.Lazy, input.ServerListenAddress, &cmdEnv); err != nil {
return 0, err
}
printHelpMessage(subshellHelp, input.ShowHelpMessages)
Expand Down Expand Up @@ -260,8 +265,8 @@ func createEnv(profileName string, region string) environ {
return env
}

func startEcsServerAndSetEnv(credsProvider aws.CredentialsProvider, config *vault.ProfileConfig, lazy bool, cmdEnv *environ) error {
ecsServer, err := server.NewEcsServer(context.TODO(), credsProvider, config, "", 0, lazy)
func startEcsServerAndSetEnv(credsProvider aws.CredentialsProvider, config *vault.ProfileConfig, lazy bool, listenAddress string, cmdEnv *environ) error {
ecsServer, err := server.NewEcsServer(context.TODO(), credsProvider, config, "", 0, lazy, listenAddress)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions server/ecsserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ type EcsServer struct {
config *vault.ProfileConfig
}

func NewEcsServer(ctx context.Context, baseCredsProvider aws.CredentialsProvider, config *vault.ProfileConfig, authToken string, port int, lazyLoadBaseCreds bool) (*EcsServer, error) {
listener, err := net.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", port))
func NewEcsServer(ctx context.Context, baseCredsProvider aws.CredentialsProvider, config *vault.ProfileConfig, authToken string, port int, lazyLoadBaseCreds bool, serverListenAddress string) (*EcsServer, error) {
listener, err := net.Listen("tcp4", fmt.Sprintf("%s:%d", serverListenAddress, port))
if err != nil {
return nil, err
}
Expand Down