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

Support TLS-enabled servers for the server-acl-init command #183

Merged
merged 1 commit into from
Dec 20, 2019

Conversation

ishustava
Copy link
Contributor

@ishustava ishustava commented Dec 20, 2019

This PR makes the following changes

  • Adds new flags: -use-https, -consul-ca-cert, and -consul-tls-server-name. The last one is specifically useful for the Helm chart since our certificates don't have Pod IPs as SANs. This allows us to set an SNI header with a custom server name.
  • Bumps Consul version to 1.6.2 to use tlsutil package for certificate generation in tests.

Ideally, I wanted to change this job to use DNS names of the servers for bootstrapping rather than IPs. But I didn't know how to write tests for it without requiring root privileges to run them. More specifically, we could programmatically add Kubernetes DNS names to etc/hosts but that will require sudo on the machine where the tests are run. This seemed a bit awkward.

@ishustava ishustava force-pushed the enable-tls-acl-init branch 3 times, most recently from bc9a747 to 15dcaae Compare December 20, 2019 02:54
Copy link
Member

@lkysow lkysow left a comment

Choose a reason for hiding this comment

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

I love how little change this required. I didn't know you could set the SNI header to enable verification when you're using an IP that's not in the IP SANS. Cool!

"Path to the PEM-encoded CA certificate of the Consul cluster.")
c.flags.StringVar(&c.flagConsulTLSServerName, "consul-tls-server-name", "",
"The server name to set as the SNI header when sending HTTPS requests to Consul.")
c.flags.BoolVar(&c.flagUseHTTPS, "use-https", false,
Copy link
Member

Choose a reason for hiding this comment

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

If we set consul-ca-cert or consul-tls-server-name with use-https=false, does it work? What about vice versa? Wondering if we should error out if not all the flags are set.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, good question. If you set use-https but choose to add your CA to the system trusted CAs, then this should still work. If you set ca cert and tls server name, but don't enable https, it won't have any effect because the job will just use HTTP for all connections, so I don't want to error here.

subcommand/server-acl-init/command_test.go Outdated Show resolved Hide resolved
// It returns file names in this order:
// CA certificate, server certificate, and server key.
// Note that it's the responsibility of the caller to
// remove the temporary files created by this function.
Copy link
Member

Choose a reason for hiding this comment

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

you could also return a function that the callers can run in a defer that cleans up the files:

func() a (string, func()) {
  return "a", func() {
    os.Remove("a")
  }
}

file, cleanup := a()
defer cleanup()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, that's an awesome idea. I'll do that!

- add new flags, -use-https, -consul-ca-cert, and
  -consul-tls-server-name.
- Bump Consul version to 1.6.2 to use tlsutil certificate
  generation functions in tests.
@ishustava ishustava merged commit f75b6f5 into master Dec 20, 2019
@ishustava ishustava deleted the enable-tls-acl-init branch December 20, 2019 22:51
@ishustava ishustava added type/enhancement New feature or request theme/tls About running Consul with TLS area/security Related to general security labels Jan 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/security Related to general security theme/tls About running Consul with TLS type/enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants