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

Enhancements to setupTLSConfig #3284

Closed
wants to merge 1 commit into from

Conversation

simon-wenmouth
Copy link

The function setupTLSConfig is now implemented in terms of the
function SetupTLSConfig in consul/api.

The function also respects two additional configuration properties.

  • tls_server_name (optional) which sets the server name to use as
    the SNI host when connecting via TLS (for when it differs from the
    server name in address). Has the same behavior as the environment
    variable CONSUL_TLS_SERVER_NAME.
  • tls_ca_path (optional) which sets the path to a directory of CA
    certificates to use for Consul communication. Has the same behavior
    as the environment variable CONSUL_CAPATH.

The function also now logs:

  • a debug message containing the values used to create the Config
    from the crypto/tls package.
  • a warning message when only one of tls_key_file or tls_cert_file
    are provided in the conf map.

The function `setupTLSConfig` is now implemented in terms of the
function `SetupTLSConfig` in `consul/api`.

The function also respects two additional configuration properties.
- `tls_server_name` (optional) which sets the server name to use as
  the SNI host when connecting via TLS (for when it differs from the
  server name in `address`). Has the same behavior as the environment
  variable `CONSUL_TLS_SERVER_NAME`.
- `tls_ca_path` (optional) which sets the path to a directory of CA
  certificates to use for Consul communication. Has the same behavior
  as the environment variable `CONSUL_CAPATH`.

The function also now logs:
- a debug message containing the values used to create the `Config`
  from the `crypto/tls` package.
- a warning message when only one of `tls_key_file` or `tls_cert_file`
  are provided in the `conf` map.
insecureSkipVerify := false
if _, ok := conf["tls_skip_verify"]; ok {
insecureSkipVerify = true
serverName, ok := conf["tls_server_name"]
Copy link
Member

Choose a reason for hiding this comment

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

The default behavior still needs to be the net.SplitHostPort behavior, if not overridden with tls_server_name.

Copy link
Author

Choose a reason for hiding this comment

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

SetupTLSConfig extracts the host portion from the TLSConfig.Address using net.SplitHostPort which is why I did not repeat the effort here.

	if tlsConfig.Address != "" {
		server := tlsConfig.Address
		hasPort := strings.LastIndex(server, ":") > strings.LastIndex(server, "]")
		if hasPort {
			var err error
			server, _, err = net.SplitHostPort(server)
			if err != nil {
				return nil, err
			}
		}
		tlsClientConfig.ServerName = server
	}

@@ -100,6 +100,13 @@ connection. You can read more about encrypting Consul connections on the
[`ca_file`](https://www.consul.io/docs/agent/options.html#ca_file) setting in
Consul.

- `tls_ca_path` `(string: "")` – Specifies the path to a directory of
certificate authority files for Consul communication. Is an alternative to
`tls_ca_file`. This defaults to the system bundle if not specified.
Copy link
Member

Choose a reason for hiding this comment

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

Duplicate tls_ca_file value.

Copy link
Author

Choose a reason for hiding this comment

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

This is not a duplicate - i was trying to remark on the fact thattls_ca_path is used when tls_ca_file is not supplied (see rootcerts.LoadCACerts). Any suggestions for improved wording?

data, err := ioutil.ReadFile(tlsCaFile)
insecureSkipVerifyStr, ok := conf["tls_skip_verify"]
if ok {
insecureSkipVerify, err := strconv.ParseBool(insecureSkipVerifyStr)
Copy link
Member

Choose a reason for hiding this comment

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

I don't have an issue with you updating how this works, but please use parseutil.ParseBool instead.

Copy link
Author

Choose a reason for hiding this comment

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

having re-read the documentation i'm going to revert to the original implementation

return nil, fmt.Errorf("invalid 'tls_min_version'")
}

tlsClientConfig.MinVersion = tlsMinVersion
Copy link
Member

Choose a reason for hiding this comment

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

You did a whole lot of reordering which is making the diff hard to follow. Can you please change the ordering of parsing the various values back to how they were so that it's easier to make sure nothing is being left out?

Copy link
Author

Choose a reason for hiding this comment

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

okay, i'll rework the PR to minimize the diff

@jefferai jefferai added this to the next-release milestone Sep 8, 2017
@jefferai
Copy link
Member

Closing as OP seems gone.

@jefferai jefferai closed this Feb 13, 2018
@chrishoffman chrishoffman removed this from the next-release milestone Oct 9, 2018
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.

3 participants