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

Add More TLS Tests and Verification of TLS Root Certificate #11300

Merged
merged 7 commits into from
Apr 12, 2021

Conversation

HridoyRoy
Copy link
Contributor

This PR expands upon the use of the Verify method to make sure that the root CA, when specified in the listener config, is checked by the diagnose command.

The PR also implements some additional tests verifying prior functionality, and adds a check in for the TLS version configuration in the listener.

Related tickets:

https://hashicorp.atlassian.net/browse/VAULT-1998

https://hashicorp.atlassian.net/browse/VAULT-2002

@HridoyRoy HridoyRoy added the Diagnose Command Dev PRs linked to Vault Diagnose label Apr 7, 2021
@vercel vercel bot temporarily deployed to Preview – vault-storybook April 7, 2021 18:12 Inactive
@vercel vercel bot temporarily deployed to Preview – vault April 7, 2021 18:12 Inactive
Copy link
Contributor

@swayne275 swayne275 left a comment

Choose a reason for hiding this comment

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

just a few nitpicks or code quality things, but overall looks good

vault/diagnose/tls.go Outdated Show resolved Hide resolved
vault/diagnose/tls.go Outdated Show resolved Hide resolved
vault/diagnose/tls.go Outdated Show resolved Hide resolved
vault/diagnose/tls_test.go Outdated Show resolved Hide resolved
vault/diagnose/tls_test.go Outdated Show resolved Hide resolved
vault/diagnose/tls_test.go Outdated Show resolved Hide resolved
vault/diagnose/tls_test.go Outdated Show resolved Hide resolved
vault/diagnose/tls_test.go Outdated Show resolved Hide resolved
@vercel vercel bot temporarily deployed to Preview – vault April 8, 2021 17:21 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook April 8, 2021 17:22 Inactive
vault/diagnose/tls.go Outdated Show resolved Hide resolved
@vercel vercel bot temporarily deployed to Preview – vault-storybook April 8, 2021 21:07 Inactive
@vercel vercel bot temporarily deployed to Preview – vault April 8, 2021 21:07 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook April 9, 2021 16:41 Inactive
@vercel vercel bot temporarily deployed to Preview – vault April 9, 2021 16:41 Inactive
@HridoyRoy HridoyRoy requested a review from swayne275 April 9, 2021 16:59
const maxVersionError = "'tls_max_version' value %q not supported, please specify one of [tls10,tls11,tls12,tls13]"

func ListenerChecks(listeners []listenerutil.Listener) error {
for _, listener := range listeners {
Copy link
Contributor Author

@HridoyRoy HridoyRoy Apr 9, 2021

Choose a reason for hiding this comment

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

Future functionality: check that client related certificate paths exist.

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 incorporate reading and loading.

if err != nil {
return err
}
x509Cert, err := x509.ParseCertificate(cert.Certificate[0])
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 can be removed.

}

// TLSFileChecks contains manual error checks against the TLS configuration
func TLSFileChecks(certFilePath, keyFilePath string) error {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Modularize this to load the cert from a file path separately, and have the checks in a separate function so that we can load from urls as well.

Copy link
Contributor

@swayne275 swayne275 left a comment

Choose a reason for hiding this comment

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

the comments in your functions and tests were SUPER helpful!


var err error
// Perform checks on the TLS Cryptographic Information.
if err = TLSFileChecks(l.TLSCertFile, l.TLSKeyFile); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a reason to not declare err here with :=?

}
err := ListenerChecks(listeners)
if err == nil {
t.Error("TLS Config check on fake certificate should fail")
Copy link
Contributor

Choose a reason for hiding this comment

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

i think these should be fails (not errors), since you can't do the next check if err is nil (presumably that's a caught panic with the test infra)

Copy link
Contributor

Choose a reason for hiding this comment

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

there are multiple cases like this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm so sorry! I didn't realized you had left some comments @swayne275 with the approval. Yeah, fails here would be better. I'll push a PR out today cleaning that up.

I can also use := for the error var in the cleanup PR. For the !string.Contains() comment below, I can't do that for this particular test, because the error message thrown by the library is a concatenation of a few error messages. I didn't want to copy that whole string here, so I just checked the necessary part to distinguish this failure from the other cases.

Thanks for the comments, and sorry about the premature merge! I'll have followup PR with the improvements ASAP!

Copy link
Contributor

Choose a reason for hiding this comment

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

No problem! I wouldn't have approved it if I wasn't okay with it going without fixes/responses to the comments

The panic in tests isn't that big of a deal, it's just a lot cleaner to avoid it

Copy link
Contributor Author

@HridoyRoy HridoyRoy Apr 12, 2021

Choose a reason for hiding this comment

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

I'm changing these to Fatals instead of Fails -- Error is equivalent to a Log followed by a Fail, and Fail continues execution. Fatal stops the test with a FailNow.

Copy link
Contributor

Choose a reason for hiding this comment

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

oh yeah fatal is probably what i meant, cool!

if err == nil {
t.Error("TLS Config check on fake certificate should fail")
}
if err.Error() != "tls: private key type does not match public key type" {
Copy link
Contributor

Choose a reason for hiding this comment

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

did you want these to be !string.Contains() as you've done for your other tests?

@HridoyRoy HridoyRoy merged commit e9ee430 into master Apr 12, 2021
catsby added a commit that referenced this pull request Apr 14, 2021
* master: (78 commits)
  docs: update vault-helm to 0.11.0 (#11355)
  Add documentation for vault-csi-provider namespace config (#11344)
  docs: update vault-k8s to 0.10.0 (#11354)
  patch(docs): fix link color (#11352)
  Add TFE/TFC auth plugin to plugin portal (#11348)
  fix a couple typos (#11343)
  TLS Diagnose Formatting Fixes  (#11342)
  Add More TLS Tests and Verification of TLS Root Certificate (#11300)
  Add HA only autopilot to changelog (#11339)
  Support autopilot when raft is for HA only (#11260)
  Fixes for db connection file type field (#11331)
  Fix flakey TestAgent_Template_Retry test (#11332)
  Darwin/ARM64 build target (#11321)
  Fix broken OIDC Providers link (#11327)
  Bug: DB secret engine not showing "Select one" in role select options (#11294)
  bumping alpine version, improving security (#11271)
  Run a more strict formatter over the code (#11312)
  docs: add persistent cache (#11272)
  Fix a few static analysis findings (#11307)
  Changing from "changelog" to "release-note" (#11303)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Diagnose Command Dev PRs linked to Vault Diagnose
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants