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

agent: convert listener config to TLS types #12522

Merged
merged 37 commits into from
Mar 24, 2022

Conversation

mikemorris
Copy link
Contributor

@mikemorris mikemorris commented Mar 4, 2022

Replaces #11647 after the listener TLS refactoring work in #12504.

I think I've pushed the use of types versus as close to the surface I can -agent/config/builder.go appears to be a boundary where generic string values capturing user config input that could be invalid can be parsed into types, and pbconfig.TLS appears to be another boundary for autoconfig to avoid breaking backwards compatibility.

Reviewer Notes:

  • ParseTLSVersion and ParseCiphers both implement some logic specific to agent config (the fallback logic to support tls10 etc values and the comma-delimited cipher string) so I don't think these would belong in types/tls.go
    • Per suggestion from @boxofrad, these have been subsumed into agent config builder parsing functions directly.
  • It appears CipherString is only used for generating pbconfig.TLS autoconfig, should it be renamed for clarity?

TODO:

  • Update website docs per comment in agent: use TLS types for config #11647 (review)
  • Update tls_cipher_suites search link in website docs
  • Add validation to error or warn when configuring cipher suites with TLS min verison 1.3
  • Close out remaining FIXMEs and TODOs
  • Add changelog entries

@mikemorris mikemorris requested a review from boxofrad March 4, 2022 16:29
@github-actions github-actions bot added theme/certificates Related to creating, distributing, and rotating certificates in Consul theme/cli Flags and documentation for the CLI interface theme/config Relating to Consul Agent configuration, including reloading theme/envoy/xds Related to Envoy support theme/tls Using TLS (Transport Layer Security) or mTLS (mutual TLS) to secure communication type/docs Documentation needs to be created/updated/clarified labels Mar 4, 2022
@mikemorris mikemorris changed the base branch from main to boxofrad/per-listener-tls-configuration March 4, 2022 16:29
@hashicorp-ci
Copy link
Contributor

🤔 This PR has changes in the website/ directory but does not have a type/docs-cherrypick label. If the changes are for the next version, this can be ignored. If they are updates to current docs, attach the label to auto cherrypick to the stable-website branch after merging.

@vercel vercel bot temporarily deployed to Preview – consul-ui-staging March 4, 2022 22:41 Inactive
@vercel vercel bot temporarily deployed to Preview – consul March 4, 2022 22:41 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging March 4, 2022 23:12 Inactive
@vercel vercel bot temporarily deployed to Preview – consul March 4, 2022 23:12 Inactive
@@ -6330,8 +6330,8 @@ func TestLoad_FullConfig(t *testing.T) {
CAPath: "nu4PlHzn",
CertFile: "1yrhPlMk",
KeyFile: "1bHapOkL",
TLSMinVersion: "mK14iOpz",
CipherSuites: []uint16{tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
TLSMinVersion: types.TLSv1_3,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should fail, TLS 1.3 cipher suites are not configurable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Config combinations like this are being handled as expected now (config builder error when specifying cipher suites alongside or with an inherited TLS min version 1.3, cipher suites omitted from config when they would be inherited by a listener config only specifying a TLS min version of 1.3).

tlsutil/config.go Outdated Show resolved Hide resolved
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging March 4, 2022 23:26 Inactive
@vercel vercel bot temporarily deployed to Preview – consul March 4, 2022 23:26 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging March 5, 2022 00:00 Inactive
@vercel vercel bot temporarily deployed to Preview – consul March 5, 2022 00:00 Inactive
@mikemorris
Copy link
Contributor Author

The remaining test failures actually look good! Invalid config that was previously being passed through is now being rejected, will update test expectations next, but this looks almost ready!

@hashicorp-cla
Copy link

hashicorp-cla commented Mar 12, 2022

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@boxofrad boxofrad left a comment

Choose a reason for hiding this comment

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

This is awesome! Thanks so much for taking the time to re-work your changes on top of #12504, @mikemorris 👏🏻 🎉

I've left a few comments for your consideration. Let me know if you'd like to talk any of them through synchronously.

agent/config/builder.go Outdated Show resolved Hide resolved
agent/config/builder.go Outdated Show resolved Hide resolved
agent/config/runtime_test.go Outdated Show resolved Hide resolved
agent/consul/auto_config_endpoint.go Outdated Show resolved Hide resolved
tlsutil/config.go Outdated Show resolved Hide resolved
tlsutil/config.go Outdated Show resolved Hide resolved
tlsutil/config.go Show resolved Hide resolved
Comment on lines 586 to 561
// FIXME: move cipherSuiteLookup to be called externally, maybe
// in agent/config/runtime parsing before the tlsutil.Config struct is
// created?
Copy link
Contributor

Choose a reason for hiding this comment

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

Yep agree, this should be done up-front rather than when we're trying to use the cipher suites.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking at this again, this actually feels like an appropriate place to handle the conversion from types.TLSCipherSuite to crypto/tls values for creating the tls.Config object.

tlsutil/config.go Outdated Show resolved Hide resolved
Base automatically changed from boxofrad/per-listener-tls-configuration to main March 18, 2022 10:47
tlsutil: add test for parsing deprecated agent TLS version strings

tlsutil: return TLSVersionInvalid with error

tlsutil: start moving tlsutil cipher suite lookups over to types/tls

tlsutil: rename tlsLookup to ParseTLSVersion, add cipherSuiteLookup

agent: attempt to use types in runtime config

agent: implement b.tlsVersion validation in config builder

agent: fix tlsVersion nil check in builder

tlsutil: update to renamed ParseTLSVersion and goTLSVersions

tlsutil: fixup TestConfigurator_CommonTLSConfigTLSMinVersion

tlsutil: disable invalid config parsing tests

tlsutil: update tests

auto_config: lookup old config strings from base.TLSMinVersion

auto_config: update endpoint tests to use TLS types

agent: update runtime_test to use TLS types

agent: update TestRuntimeCinfig_Sanitize.golden

agent: update config runtime tests to expect TLS types
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging March 21, 2022 21:07 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging March 21, 2022 21:22 Inactive
@mikemorris mikemorris marked this pull request as ready for review March 21, 2022 21:25
@mikemorris mikemorris requested a review from a team as a code owner March 21, 2022 21:25
@mikemorris
Copy link
Contributor Author

mikemorris commented Mar 22, 2022

@boxofrad I can't quite figure out why these failing TestAutoConfig_Integration tests seem to be skipping the deprecated config parsing. Does applyDeprecatedConfig as called at

c, warns := applyDeprecatedConfig(&target)
need to be added somewhere to the auto-config code path?
func (ac *AutoConfig) ReadConfig() (*config.RuntimeConfig, error) {

It does appear to be appropriately setting tls12 in pbconfig.TLS for backwards compatibility, but instead of the agent just logging a warning and updating the config to TLS.Defaults.TLSMinVersion: TLSv1_2 internally at

if deprecatedVersion, ok := types.DeprecatedConsulAgentTLSVersions[*v]; ok {
// Log warning about deprecated config values
warns = append(warns, fmt.Sprintf("The value for 'tls_min_version' field is deprecated, please specify one of %v", types.TLSVersions()))
deprecatedVersionString := deprecatedVersion.String()
defaults.TLSMinVersion = &deprecatedVersionString
it just hits the validation error and fails to start the agent.

--- FAIL: TestAutoConfig_Integration (1.76s)
    agent_test.go:5065: testagent.go:107: b3a9ac58-755b-c31f-f007-24cd304f7085 test-client Error starting agent: failed to fully resolve configuration: 1 error occurred:
                * tls.defaults.tls_min_version: invalid TLS version: no matching TLS version found for tls12, please specify one of [TLS_AUTO, TLSv1_0, TLSv1_1, TLSv1_2, TLSv1_3]

@vercel vercel bot temporarily deployed to Preview – consul March 23, 2022 20:00 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging March 23, 2022 20:00 Inactive
Copy link
Contributor

@boxofrad boxofrad left a comment

Choose a reason for hiding this comment

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

Great job 👏🏻 I've left one last nit, but please feel free to take or leave it.

Comment on lines +1997 to +2002
func validateTLSVersionCipherSuitesCompat(tlsMinVersion types.TLSVersion) error {
if tlsMinVersion == types.TLSv1_3 {
return fmt.Errorf("TLS 1.3 cipher suites are not configurable")
}
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for adding this validation, it's a great UX improvement 🙌🏻

agent/config/deprecated.go Outdated Show resolved Hide resolved
Co-authored-by: Dan Upton <daniel@floppy.co>
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging March 24, 2022 11:58 Inactive
@vercel vercel bot temporarily deployed to Preview – consul March 24, 2022 11:58 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging March 24, 2022 15:43 Inactive
@vercel vercel bot temporarily deployed to Preview – consul March 24, 2022 15:43 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging March 24, 2022 15:54 Inactive
@vercel vercel bot temporarily deployed to Preview – consul March 24, 2022 15:54 Inactive
@mikemorris mikemorris merged commit f8a2ae2 into main Mar 24, 2022
@mikemorris mikemorris deleted the agent/listener-tls-config-types branch March 24, 2022 19:32
@hc-github-team-consul-core
Copy link
Collaborator

🍒 If backport labels were added before merging, cherry-picking will start automatically.

To retroactively trigger a backport after merging, add backport labels and re-run https://circleci.com/gh/hashicorp/consul/613317.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr/no-metrics-test theme/certificates Related to creating, distributing, and rotating certificates in Consul theme/cli Flags and documentation for the CLI interface theme/config Relating to Consul Agent configuration, including reloading theme/envoy/xds Related to Envoy support theme/tls Using TLS (Transport Layer Security) or mTLS (mutual TLS) to secure communication type/docs Documentation needs to be created/updated/clarified
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants