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

TLS server options #302

Merged
merged 8 commits into from
Oct 21, 2021
Merged

TLS server options #302

merged 8 commits into from
Oct 21, 2021

Conversation

tvoran
Copy link
Member

@tvoran tvoran commented Oct 19, 2021

Adds options for setting the TLS minimum version and supported cipher suites. Each can be set via command-line flag or environment variable.

Environment variable command-line flag default allowed values
AGENT_INJECT_TLS_MIN_VERSION -tls-min-version tls12 tls10 tls11 tls12 tls13
AGENT_INJECT_TLS_CIPHER_SUITES -tls-cipher-suites "" comma-separated list of cipher suites from the available ciphersuites

When deploying with vault-helm, these can be set using the injector.extraEnvironmentVariables chart option.

Requires #303 since this PR assumes tls Config.PreferServerCipherSuites is ignored/deprecated as it is in go 1.17.

Adds options (with defaults) for setting tls_min_version (1.2),
tls_cipher_suites (""), and tls_prefer_server_cipher_suites (true).
@@ -160,6 +171,13 @@ func (c *Command) init() {
c.flagSet.StringVar(&c.flagResourceLimitMem, "memory-limit", agent.DefaultResourceLimitMem,
fmt.Sprintf("Memory resource limit set in injected containers. Defaults to %s", agent.DefaultResourceLimitMem))

c.flagSet.StringVar(&c.flagTLSMinVersion, "tls-min-version", defaultTLSMinVersion,
fmt.Sprintf(`Minimum supported version of TLS. Defaults to %s. Accepted values are "tls10", "tls11", "tls12" or "tls13"`, defaultTLSMinVersion))
c.flagSet.StringVar(&c.flagTLSCipherSuites, "tls-cipher-suites", "",
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should include the env variable name in the usage?

Copy link
Contributor

@benashz benashz left a comment

Choose a reason for hiding this comment

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

Only a few minor nits, otherwise 👍

@@ -206,11 +211,28 @@ func (c *Command) Run(args []string) int {
}

var handler http.Handler = mux
minTLSVersion, ok := tlsutil.TLSLookup[c.flagTLSMinVersion]
if !ok {
c.UI.Error(fmt.Sprintf("Failed to parse minimum TLS version %q", c.flagTLSMinVersion))
Copy link
Contributor

Choose a reason for hiding this comment

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

The error message mentions parsing, but really we received an unsupported TLS version.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, changed in 05aeaaf to invalid or unsupported TLS version

subcommand/injector/command.go Outdated Show resolved Hide resolved
DefaultLogLevel = "info"
DefaultLogFormat = "standard"
defaultTLSMinVersion = "tls12"
defaultTLSPreferServerCipherSuites = true
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this flag/option needed? Reading from https://pkg.go.dev/crypto/tls#Config, it looks like this deprecated and is now completely ignored.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the deprecation happened recently, in go1.17 so this flag will still be used by the server since we're on 1.16. Having said that, I think that we should consider updating the go version we use to compile rather than introduce a parameter that will be ignored shortly after.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, we can remove the option if we update our builds to go 1.17; they're on 1.16 currently.

Copy link
Member Author

Choose a reason for hiding this comment

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

main is now building with go 1.17. I merged that into this branch, and removed the tls_prefer_server_cipher_suites option.

Copy link
Contributor

@benashz benashz left a comment

Choose a reason for hiding this comment

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

A few minor nits, then 👍

Copy link
Contributor

@tomhjp tomhjp left a comment

Choose a reason for hiding this comment

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

LGTM 👍

c.flagSet.StringVar(&c.flagTLSMinVersion, "tls-min-version", defaultTLSMinVersion,
fmt.Sprintf(`Minimum supported version of TLS. Defaults to %s. Accepted values are "tls10", "tls11", "tls12" or "tls13"`, defaultTLSMinVersion))
c.flagSet.StringVar(&c.flagTLSCipherSuites, "tls-cipher-suites", "",
"Comma-separated list of supported cipher suites")
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it worth mentioning that the order will not be respected? I think Golang will automatically reorder right? Maybe that's quite an advanced detail to include in quite high level help text though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps, but it is really a matter of which go version was used during the build. I suppose that was one advantage of the previous flag. The server preferred order would be enabled regardless of version of go that was used.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, in 1.17 the order is ignored, and it's also only honored for TLS 1.0-1.2 (I added that last part to the usage string in 50c85b8).

Copy link
Contributor

@benashz benashz left a comment

Choose a reason for hiding this comment

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

LGTM!

subcommand/injector/flags.go Outdated Show resolved Hide resolved
@@ -265,6 +274,28 @@ func (c *Command) handleReady(rw http.ResponseWriter, req *http.Request) {
rw.WriteHeader(204)
}

func (c *Command) makeTLSConfig() (*tls.Config, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

c.flagSet.StringVar(&c.flagTLSMinVersion, "tls-min-version", defaultTLSMinVersion,
fmt.Sprintf(`Minimum supported version of TLS. Defaults to %s. Accepted values are %s.`, defaultTLSMinVersion, tlsStr))
c.flagSet.StringVar(&c.flagTLSCipherSuites, "tls-cipher-suites", "",
"Comma-separated list of supported cipher suites for TLS 1.0-1.2")
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure I follow, does this mean we cannot set the cipher suites for any TLS version above 1.2?

Copy link
Member Author

Choose a reason for hiding this comment

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

According to the docs, Note that TLS 1.3 ciphersuites are not configurable.

When testing this, it seems to just ignore that flag when TLS 1.3 is set. No errors thrown or anything.

Copy link
Contributor

@benashz benashz Oct 21, 2021

Choose a reason for hiding this comment

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

Very interesting...

In that case, perhaps rephrasing it a bit to be:

Suggested change
"Comma-separated list of supported cipher suites for TLS 1.0-1.2")
"Comma-separated list of supported cipher suites (ignored for tls13 and higher)")

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, though I think we'll keep this phrasing for now.

@tvoran tvoran merged commit c02054a into main Oct 21, 2021
@tvoran tvoran deleted the VAULT-3730/tls-listener-settings branch October 21, 2021 18:23
RemcoBuddelmeijer pushed a commit to RemcoBuddelmeijer/vault-k8s that referenced this pull request Feb 22, 2022
Adds options (with defaults) for setting tls_min_version (1.2),
tls_cipher_suites ("").
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.

5 participants