Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

Enable Consul Connect on terraform-aws-consul #173

Closed
wants to merge 23 commits into from

Conversation

7hacker
Copy link

@7hacker 7hacker commented May 14, 2020

This PR addresses issue #165

Design

We add a flag, '--enable-connect' to the run-consul module that turns on Consul Connect while bootstrapping a new cluster. This flag creates the basic key-value pair in the servers configuration (default.json).

To use in production, we suggest overriding the default configuration as specified in the Readme. This enables the production deployments to:

  1. Adopt the best practices in ensuring secure communications, ACL as specified here: https://learn.hashicorp.com/consul/developer-mesh/connect-production

  2. Use an alternative CA provider like Vault or apply specific private_key and root_cert values to the default CA provider by Consul, as specified here: https://learn.hashicorp.com/consul/developer-mesh/connect-production

  3. Use Envoy as a proxy as specified here: https://www.consul.io/docs/connect/proxies/envoy

Examples

We also provide examples showing:

  1. How to setup a cluster with Consul Connect
  2. Deploying 3 Services with sidecar proxies
  3. Creating intentions between these 3 services and disabling communications from one of them to another

Test

Test include running through the example and verifying:

  1. A cluster comes up and the default Consul CA issues a root certificate
  2. Communication occurs via sidecar proxies (disabling a sidecar should disable communication)
  3. Intentions are respected. Services disallowed to communicate with other services, cannot.

@7hacker 7hacker requested a review from robmorgan as a code owner May 14, 2020 18:33
@hashicorp-cla
Copy link

hashicorp-cla commented May 14, 2020

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@yorinasub17 yorinasub17 left a comment

Choose a reason for hiding this comment

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

The examples, and tests seem reasonable, but I think the approach and docs feel a bit incomplete. I think the key thing missing for me is how the service setup works. Does the proxy and service configuration happen when you run run-consul? Or are you expected to manually run consul services register and consul connect proxy after run-consul?

Hashing these out into an overview docs on how to configure consul connect for both server and client side would help clarify things.

modules/run-consul/README.md Outdated Show resolved Hide resolved
Copy link
Contributor

@yorinasub17 yorinasub17 left a comment

Choose a reason for hiding this comment

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

The code updates looks good to me! Had one comment regarding the example, but can be punted for now.

examples/example-with-consul-connect/user-data-client.sh Outdated Show resolved Hide resolved
@7hacker
Copy link
Author

7hacker commented May 14, 2020

This is ready for review for the Trial project day. There are some concrete next steps here, namely:

  1. Set up intentions in the consul clients
  2. Test that the proxies do route communications and the intentions are respected
  3. A better way to register services and sidecar proxies for clients. Right now this is done crudely in user-data-client script as shown in the example, however this is a challenge if there is more than 1 client and you want to control the placement of services and sidecar proxies
  4. Integration with Envoy & Vault is an obvious next request from folks who end up using this in production
  5. Better documentation on setting things up

Copy link
Contributor

@yorinasub17 yorinasub17 left a comment

Choose a reason for hiding this comment

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

Thanks for sharing the next steps and the contribution! I had one more nit for the docs, but I think feature wise this is a good, self-contained implementation to kick start our support for Consul Connect.

Note that we can't merge this in until you sign the CLA for Hashicorp, and we will need at least one more review from one of the code owners (@brikis98 or @robmorgan ), but from my side I don't have much to add for this initial version!

modules/run-consul/README.md Outdated Show resolved Hide resolved
examples/example-with-consul-connect/user-data-client.sh Outdated Show resolved Hide resolved
7hacker and others added 3 commits May 14, 2020 17:02
Co-authored-by: Yoriyasu Yano <430092+yorinasub17@users.noreply.github.com>
Co-authored-by: Yoriyasu Yano <430092+yorinasub17@users.noreply.github.com>
Copy link
Collaborator

@brikis98 brikis98 left a comment

Choose a reason for hiding this comment

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

Thanks @7hacker!

@@ -530,6 +546,9 @@ function run {
--enable-gossip-encryption)
enable_gossip_encryption="true"
;;
--enable-connect)
enable_connect="true"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here. Declare above as a local variable and pass it explicitly to other functions that need it.

Copy link

@MatthiasScholz MatthiasScholz Jan 12, 2021

Choose a reason for hiding this comment

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

Tackeled in #202.

examples/example-with-consul-connect/README.md Outdated Show resolved Hide resolved
examples/example-with-consul-connect/main.tf Outdated Show resolved Hide resolved
nohup consul connect proxy -sidecar-for foo &>/dev/null &

# Start a proxy sidecar for service bar
nohup consul connect proxy -sidecar-for bar &>/dev/null &
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we have the services actually try to communicate with each other here? E.g., Send a request from one to the other?

Copy link
Author

Choose a reason for hiding this comment

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

no that doesnt happen yet, but should happen along with tests to verify the intentions

@@ -309,6 +313,17 @@ EOF
)
fi

local connect_configuration=""
if [[ "$enable_connect" == "true" && "$server" == "true" ]]; then
Copy link
Collaborator

Choose a reason for hiding this comment

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

enable_connect needs to be declared above and passed explicitly into the function. We use local rather than global variables.

Copy link

@MatthiasScholz MatthiasScholz Jan 12, 2021

Choose a reason for hiding this comment

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

Tackeled in #202.

7hacker and others added 2 commits May 15, 2020 09:02
Co-authored-by: Yevgeniy Brikman <brikis98@users.noreply.github.com>
Co-authored-by: Yevgeniy Brikman <brikis98@users.noreply.github.com>
variable "ssh_key_name" {
description = "The name of an EC2 Key Pair that can be used to SSH to the EC2 Instances in this cluster. Set to an empty string to not associate a Key Pair."
type = string
default = nt-trial
Copy link
Author

Choose a reason for hiding this comment

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

set this back to default = null

Copy link

@MatthiasScholz MatthiasScholz Jan 12, 2021

Choose a reason for hiding this comment

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

Tackeled in #202.

@MatthiasScholz
Copy link

@7hacker - I would like to jump in and help getting the PR merged. Any support needed?

@brikis98
Copy link
Collaborator

Closing this PR due to inactivity.

@brikis98 brikis98 closed this Jan 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants