Skip to content

Add verify server hostname to tls default#17155

Merged
pglass merged 7 commits intohashicorp:mainfrom
fulviodenza:add-verify_server_hostname-to-tls-default
Jul 10, 2023
Merged

Add verify server hostname to tls default#17155
pglass merged 7 commits intohashicorp:mainfrom
fulviodenza:add-verify_server_hostname-to-tls-default

Conversation

@fulviodenza
Copy link
Copy Markdown
Contributor

Description

This PR solves Add verify_server_hostname to tls.defaults #17095
The PR improves the UX allowing the users to default the verify_server_hostname value avoiding anti-intuitive configurations such as

tls {
  defaults {
    key_file = "/etc/pki/tls/private/my.key"
    cert_file = "/etc/pki/tls/certs/my.crt"
    ca_file = "/etc/pki/tls/certs/ca-bundle.crt"
    verify_incoming = true
    verify_outgoing = true
  }

  internal_rpc {
    verify_server_hostname = true
  }
}

now the internal_rpc is not needed anymore in this configuration and can be written as follows:

tls {
  defaults {
    key_file = "/etc/pki/tls/private/my.key"
    cert_file = "/etc/pki/tls/certs/my.crt"
    ca_file = "/etc/pki/tls/certs/ca-bundle.crt"
    verify_incoming = true
    verify_outgoing = true
    verify_server_hostname = true
  }
}

as @jkirschner-hashicorp suggested in #17095 (comment)

Testing & Reproduction steps

Unit test in runtime_test

Links

#17095

PR Checklist

  • updated test coverage
  • external facing docs updated
  • appropriate backport labels added
  • not a security concern

@fulviodenza fulviodenza requested a review from a team as a code owner April 26, 2023 17:57
@github-actions github-actions bot added theme/config Relating to Consul Agent configuration, including reloading type/docs Documentation needs to be created/updated/clarified labels Apr 26, 2023
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for the diligence in updating these config examples in the docs :)

@jkirschner-hashicorp jkirschner-hashicorp requested review from a team, kisunji and pglass and removed request for a team April 26, 2023 18:30
@fulviodenza fulviodenza marked this pull request as draft April 26, 2023 19:27
@fulviodenza fulviodenza marked this pull request as ready for review April 26, 2023 20:51
Copy link
Copy Markdown

@pglass pglass left a comment

Choose a reason for hiding this comment

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

This looks great! Just some minor nits/comments.

Copy link
Copy Markdown
Collaborator

@huikang huikang left a comment

Choose a reason for hiding this comment

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

Shall we update the config doc at

  1. Add verify_server_hostname to

    - `defaults` ((#tls_defaults)) Provides default settings that will be applied

  2. Add the override note at

    - `verify_server_hostname` ((#tls_internal_rpc_verify_server_hostname)) When
    set to true, Consul verifies the TLS certificate presented by the servers
    match the hostname `server.<datacenter>.<domain>`. By default this is false,
    and Consul does not verify the hostname of the certificate, only that it
    is signed by a trusted CA.

Copy link
Copy Markdown
Collaborator

@huikang huikang Apr 26, 2023

Choose a reason for hiding this comment

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

Shall we add a test case testing that tls.internal_rpc.verify_server_hostname overrides tls.defaults.verify_server_hostname?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@fulviodenza , I am not sure if this test case has been added. Could you please confirm this? Thanks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, sorry, didn't push a change. Now should have been added

@fulviodenza fulviodenza requested a review from huikang April 27, 2023 07:49
Copy link
Copy Markdown
Contributor

@kisunji kisunji left a comment

Choose a reason for hiding this comment

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

:shipit:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we need to add Overrides [tls.defaults.verify_server_hostname](#tls_defaults_verify_server_hostname). at line 2187.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

you're right, thanks, I pushed the change

@fulviodenza fulviodenza requested a review from huikang April 28, 2023 21:47
@huikang
Copy link
Copy Markdown
Collaborator

huikang commented Apr 29, 2023

@fulviodenza the CI is failing due to a docker login. We are removing the step in another PR. Please rebase this one, once it's done.

@fulviodenza
Copy link
Copy Markdown
Contributor Author

Hey @huikang I've seen the pr has been merged in main, shall we move forward with this?

@jkirschner-hashicorp
Copy link
Copy Markdown
Contributor

Hi @fulviodenza,

It seems like some of the tests are still failing due to CI login failures for PRs submitted by contributors outside the HashiCorp org (nothing to do with the code you changed). It's something we'll need to look into.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure what folks prefer for styling but we could get rid of the else block by setting the default first. IMO this is a bit easier to read.

c.InternalRPC.VerifyServerHostname = boolVal(t.Defaults.VerifyServerHostname)

if t.InternalRPC.VerifyServerHostname != nil {
  c.InternalRPC.VerifyServerHostname = boolVal(t.InternalRPC.VerifyServerHostname)
}

@jkirschner-hashicorp
Copy link
Copy Markdown
Contributor

Hi @fulviodenza,

Once we've addressed the CI issue, we'll let you know. Until then, merging the latest changes from main into this PR won't change anything, unfortunately :(

Thank you for your patience!

@david-yu
Copy link
Copy Markdown
Contributor

david-yu commented Jul 8, 2023

It looks like all tests passed. Should we go ahead and merge @pglass ?

@fulviodenza fulviodenza requested a review from a team July 9, 2023 11:58
@fulviodenza fulviodenza requested a review from a team as a code owner July 9, 2023 11:58
@fulviodenza fulviodenza requested review from randyhdev and sarahethompson and removed request for a team July 9, 2023 11:58
@pglass pglass merged commit f4b0804 into hashicorp:main Jul 10, 2023
@fulviodenza fulviodenza deleted the add-verify_server_hostname-to-tls-default branch July 10, 2023 15:40