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

AWS auto-discovery #2459

Merged
merged 9 commits into from
Nov 3, 2016
Merged

AWS auto-discovery #2459

merged 9 commits into from
Nov 3, 2016

Conversation

kyhavlov
Copy link
Contributor

@kyhavlov kyhavlov commented Nov 1, 2016

Reworked #2039 to add EC2 discovery to -retry-join along with restructuring the config and adding multiple auth methods.

There's still some question of what to do about CI for the integration test (TestDiscoverEC2Hosts); for now I just wrote it to rely on the setup generated by our terraform AWS module and added a ConsulRole = Server tag to the instances in that. In Travis where the env vars aren't set, it just gets skipped until we decide what to do there.

config := c.EC2Discovery
awsConfig := &aws.Config{
Region: aws.String(config.Region),
Credentials: credentials.NewStaticCredentials(config.AccessKeyID, config.SecretAccessKey, ""),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this preclude use of the very useful IAM instance credentials? While statically defining the credentials is a useful option, IAM roles remove the management overhead of rotating those keys.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reminding me - I had meant to look into adding that after the first pass at this. It's definitely the more natural option when using an already AWS-specific feature

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use the default credential provider it'll accept it from any of the environment, cred-file, and IAM role.

Copy link
Contributor Author

@kyhavlov kyhavlov Nov 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up using a ChainProvider to match the order in which Terraform's AWS Provider looks for credentials

@kyhavlov kyhavlov force-pushed the f-aws-autodiscovery branch from a061df8 to 468bf73 Compare November 2, 2016 01:24
Credentials: credentials.NewStaticCredentials(config.AccessKeyID, config.SecretAccessKey, ""),
Region: aws.String(config.Region),
Credentials: credentials.NewChainCredentials(
[]credentials.Provider{
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please get support for ECS Task Roles here? This would allow Consul to fetch credentials meant specifically for it rather than using the instance role when running as a Docker container.

Sample code: https://github.com/aws/aws-sdk-go/blob/master/aws/defaults/defaults.go#L102

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, thanks for pointing this out.

return nil, err
}

servers := make([]string, 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style nit - I'd just say var servers []string since you aren't setting a size.

logger.Printf("[INFO] agent: Discovered %d servers from EC2...", len(servers))
}

servers = append(config.RetryJoin, servers...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will work fine, but I'd flip this to keep the servers so far in front, so servers = append(servers, config.RetryJoin...).

Copy link
Contributor

@slackpad slackpad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks awesome - noted some nits and the args should show up in the documentation in alphabetical order for both sections; they are a little out of place. Otherwise good to merge.

@kyhavlov kyhavlov merged commit 0737985 into master Nov 3, 2016
@kyhavlov kyhavlov deleted the f-aws-autodiscovery branch November 3, 2016 17:27
@CpuID
Copy link

CpuID commented Nov 11, 2016

This is pretty cool :) I currently take this a step further via a separate binary right now (to use with Docker + a bash wrapper) called ecs-discoverer, which detects which EC2 instances are running a specific Amazon ECS Task (based on an ECS Service Name).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants