-
Notifications
You must be signed in to change notification settings - Fork 173
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
TLS server options #302
Changes from all commits
7b094b7
05aeaaf
f491c7d
b71282e
5eb06f8
892ba54
f646df3
50c85b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package injector | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestTLSConfig(t *testing.T) { | ||
tests := map[string]struct { | ||
tlsVersion string | ||
suites string | ||
expectedError error | ||
}{ | ||
"defaults": { | ||
tlsVersion: defaultTLSMinVersion, | ||
suites: "", | ||
expectedError: nil, | ||
}, | ||
"bad tls": { | ||
tlsVersion: "tls1000", | ||
suites: "", | ||
expectedError: fmt.Errorf(`invalid or unsupported TLS version "tls1000"`), | ||
}, | ||
"non-default tls": { | ||
tlsVersion: "tls13", | ||
suites: "", | ||
expectedError: nil, | ||
}, | ||
"suites specified": { | ||
tlsVersion: defaultTLSMinVersion, | ||
suites: "TLS_RSA_WITH_AES_128_GCM_SHA256,TLS_RSA_WITH_AES_256_GCM_SHA384", | ||
expectedError: nil, | ||
}, | ||
"invalid suites specified": { | ||
tlsVersion: defaultTLSMinVersion, | ||
suites: "suite1,suite2,suite3", | ||
expectedError: fmt.Errorf(`failed to parse TLS cipher suites list "suite1,suite2,suite3": unsupported cipher "suite1"`), | ||
}, | ||
} | ||
|
||
for name, tc := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
c := &Command{} | ||
c.flagTLSMinVersion = tc.tlsVersion | ||
c.flagTLSCipherSuites = tc.suites | ||
result, err := c.makeTLSConfig() | ||
assert.Equal(t, tc.expectedError, err) | ||
if tc.expectedError == nil { | ||
assert.NotZero(t, result.MinVersion) | ||
if len(tc.suites) == 0 { | ||
assert.Nil(t, result.CipherSuites) | ||
} else { | ||
assert.Len(t, result.CipherSuites, len(strings.Split(tc.suites, ","))) | ||
} | ||
} | ||
}) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3,18 +3,21 @@ package injector | |||||
import ( | ||||||
"flag" | ||||||
"fmt" | ||||||
"sort" | ||||||
"strconv" | ||||||
"strings" | ||||||
|
||||||
"github.com/hashicorp/go-hclog" | ||||||
"github.com/hashicorp/go-secure-stdlib/tlsutil" | ||||||
"github.com/hashicorp/vault-k8s/agent-inject/agent" | ||||||
"github.com/hashicorp/vault-k8s/helper/flags" | ||||||
"github.com/kelseyhightower/envconfig" | ||||||
) | ||||||
|
||||||
const ( | ||||||
DefaultLogLevel = "info" | ||||||
DefaultLogFormat = "standard" | ||||||
DefaultLogLevel = "info" | ||||||
DefaultLogFormat = "standard" | ||||||
defaultTLSMinVersion = "tls12" | ||||||
) | ||||||
|
||||||
// Specification are the supported environment variables, prefixed with | ||||||
|
@@ -100,6 +103,12 @@ type Specification struct { | |||||
|
||||||
// ResourceLimitMem is the AGENT_INJECT_MEM_LIMIT environment variable. | ||||||
ResourceLimitMem string `envconfig:"AGENT_INJECT_MEM_LIMIT"` | ||||||
|
||||||
// TLSMinVersion is the AGENT_INJECT_TLS_MIN_VERSION environment variable | ||||||
TLSMinVersion string `envconfig:"tls_min_version"` | ||||||
|
||||||
// TLSCipherSuites is the AGENT_INJECT_TLS_CIPHER_SUITES environment variable | ||||||
TLSCipherSuites string `envconfig:"tls_cipher_suites"` | ||||||
} | ||||||
|
||||||
func (c *Command) init() { | ||||||
|
@@ -160,6 +169,17 @@ 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)) | ||||||
|
||||||
tlsVersions := []string{} | ||||||
for v := range tlsutil.TLSLookup { | ||||||
tlsVersions = append(tlsVersions, v) | ||||||
} | ||||||
sort.Strings(tlsVersions) | ||||||
tlsStr := strings.Join(tlsVersions, ", ") | ||||||
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", "", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should include the |
||||||
"Comma-separated list of supported cipher suites for TLS 1.0-1.2") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the docs, When testing this, it seems to just ignore that flag when TLS 1.3 is set. No errors thrown or anything. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, though I think we'll keep this phrasing for now. |
||||||
|
||||||
c.help = flags.Usage(help, c.flagSet) | ||||||
} | ||||||
|
||||||
|
@@ -311,5 +331,13 @@ func (c *Command) parseEnvs() error { | |||||
c.flagResourceLimitMem = envs.ResourceLimitMem | ||||||
} | ||||||
|
||||||
if envs.TLSMinVersion != "" { | ||||||
c.flagTLSMinVersion = envs.TLSMinVersion | ||||||
} | ||||||
|
||||||
if envs.TLSCipherSuites != "" { | ||||||
c.flagTLSCipherSuites = envs.TLSCipherSuites | ||||||
} | ||||||
|
||||||
return nil | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍