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

advancedtls: add new module for advanced TLS handshaker #3187

Merged
merged 1 commit into from
Jan 7, 2020

Conversation

ZhenLian
Copy link
Contributor

This PR contains the implementation and tests of a utility library for some advanced TLS features, including:

  1. Credential Reloading: users are able to reload their credentials without restarting the app. Note that the "credential" here can be a private key, its corresponding certificate bundle, or trusted CA certificate bundle.

  2. Server Authorization: on client side, we let users specify their own functions to check peers' identities when handshakes are finished. This feature is sometimes also referred to as "secure name checking" or "hostname verification".

There are some previous discussions in this deprecated PR: #3044. The goal of this PR remains the same, but change the APIs to provide better functionalities.
This PR includes the implementation and unit tests and integration tests for the client and server without credential reloading. Next PR will cover the integration tests for credential reloading.

@ZhenLian
Copy link
Contributor Author

@jiangtaoli2016 Could you please take a first round of review on the API design? Thank you so much for the help!

Copy link
Contributor

@jiangtaoli2016 jiangtaoli2016 left a comment

Choose a reason for hiding this comment

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

Thanks Zhen for implementation! Looks very good. A few questions.
I have not reviewed the test file yet.

security/advancedtls/advancedtls.go Show resolved Hide resolved
security/advancedtls/advancedtls.go Outdated Show resolved Hide resolved
security/advancedtls/advancedtls.go Outdated Show resolved Hide resolved
security/advancedtls/advancedtls.go Outdated Show resolved Hide resolved
Copy link
Contributor

@jiangtaoli2016 jiangtaoli2016 left a comment

Choose a reason for hiding this comment

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

Some minor comments on test.

security/advancedtls/advancedtls.go Show resolved Hide resolved
security/advancedtls/advancedtls_test.go Show resolved Hide resolved
security/advancedtls/advancedtls_test.go Outdated Show resolved Hide resolved
security/advancedtls/advancedtls_test.go Outdated Show resolved Hide resolved
security/advancedtls/advancedtls_test.go Show resolved Hide resolved
serverRoot *x509.CertPool
serverGetRoot func(rawConn net.Conn, rawCerts [][]byte) (*x509.CertPool, error)
serverExpectError bool
}{
Copy link
Contributor

Choose a reason for hiding this comment

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

We may want to test the cases where the root CA certs do not match the peer certificates. E.g., server provides a valid certificate, but server's CA cert is different from client Root cert.

Copy link
Contributor Author

@ZhenLian ZhenLian Nov 22, 2019

Choose a reason for hiding this comment

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

Added the following test cases:

  • Client_reload_both_certs_verifyFunc_Server_reload_both_certs_mutualTLS
  • Client_wrong_peer_cert_Server_reload_both_certs_mutualTLS
  • Client_wrong_trust_cert_Server_reload_both_certs_mutualTLS
  • Client_reload_both_certs_verifyFunc_Server_wrong_peer_cert
  • Client_reload_both_certs_verifyFunc_Server_wrong_trust_cert

@jiangtaoli2016
Copy link
Contributor

In current implementation, client has to provide either RootCA or GetRootCA.

We see use case grpc/grpc#20530 that client does not know root CA certs in advance. In that case, we give the power to client to validate via VerifyPeer function (since application can access target name and server certain chain).

Thus, if client does not provide RootCA or GetRootCA, instead of failing, we just don't validate the server cert and let application decide via VerifyPeer. @ZhenLian Could update your implementation as well?

@ZhenLian ZhenLian force-pushed the zhen_spiffe_1 branch 2 times, most recently from 128795a to 781f1c0 Compare November 22, 2019 22:25
@jiangtaoli2016
Copy link
Contributor

Thanks @ZhenLian for the implementation.
My knowledge in Golang is limited.
@cesarghali Please check Go readability and security suggestions.
@dfawley Please review on API and make sure you are comfortable.

@ZhenLian
Copy link
Contributor Author

ZhenLian commented Nov 23, 2019

The API is now updated as:
When the client side specifies neither RootCA nor GetRootCA but with VerifyPeer, we will only use VerifyPeer to see if this RPC call is valid.
Note that if client specifies none of the three, we will still fall back to default checks, which are certificate check and host name check.

Copy link
Contributor

@cesarghali cesarghali left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. I left some comments in advancedtls.go. I will review advancedtls_test.go next.

security/advancedtls/advancedtls.go Outdated Show resolved Hide resolved
security/advancedtls/advancedtls.go Show resolved Hide resolved
security/advancedtls/advancedtls.go Outdated Show resolved Hide resolved
security/advancedtls/advancedtls.go Outdated Show resolved Hide resolved
security/advancedtls/advancedtls.go Outdated Show resolved Hide resolved
security/advancedtls/advancedtls.go Outdated Show resolved Hide resolved
security/advancedtls/advancedtls.go Outdated Show resolved Hide resolved
security/advancedtls/advancedtls.go Outdated Show resolved Hide resolved
security/advancedtls/advancedtls.go Show resolved Hide resolved
security/advancedtls/advancedtls.go Outdated Show resolved Hide resolved
@ZhenLian ZhenLian force-pushed the zhen_spiffe_1 branch 5 times, most recently from 74939ed to 43d11d8 Compare December 5, 2019 06:01
@ZhenLian
Copy link
Contributor Author

ZhenLian commented Dec 5, 2019

@cesarghali Thank you so much for the review! I left a few more comments. Please let me know if anything could be further improved :-)

@ZhenLian
Copy link
Contributor Author

@cesarghali
Hi Cesar, I've updated the comments inside config() functions and refactored the Options struct as we discussed. Could you please take a look at it(as well as the tests) to see if there are any other things that could be improved? Thank you so much!

@ZhenLian
Copy link
Contributor Author

Friendly ping :-)

@ZhenLian ZhenLian force-pushed the zhen_spiffe_1 branch 3 times, most recently from 35fa648 to 67ad997 Compare December 21, 2019 22:55
@ZhenLian
Copy link
Contributor Author

@dfawley
Hi Doug, sorry for the delay of this PR. Now our team has completed the review process. Could you please take a look at the overall structure, the go module files, etc? Thanks in advance for your time!

Copy link
Member

@dfawley dfawley left a comment

Choose a reason for hiding this comment

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

Looks good overall, just some minor things.

security/advancedtls/advancedtls.go Outdated Show resolved Hide resolved
security/advancedtls/advancedtls.go Outdated Show resolved Hide resolved
security/advancedtls/advancedtls.go Outdated Show resolved Hide resolved
security/advancedtls/advancedtls.go Outdated Show resolved Hide resolved
security/advancedtls/advancedtls.go Outdated Show resolved Hide resolved
security/advancedtls/advancedtls.go Show resolved Hide resolved
security/advancedtls/advancedtls.go Show resolved Hide resolved
security/advancedtls/advancedtls.go Show resolved Hide resolved
security/advancedtls/advancedtls.go Outdated Show resolved Hide resolved
security/advancedtls/advancedtls.go Outdated Show resolved Hide resolved
@dfawley dfawley removed their assignment Jan 7, 2020
@ZhenLian
Copy link
Contributor Author

ZhenLian commented Jan 7, 2020

@dfawley
Hi Doug, thank you so much for the suggestions and comments. I have addressed them all. Could you please take a second look?
By the way, I made another PR, #3300, to fix a small issue found here but might also apply to that place. It would be good if you could take a look as well.
Thanks again for the help :-)

@ZhenLian ZhenLian requested a review from dfawley January 7, 2020 21:51
@dfawley dfawley added this to the 1.27 Release milestone Jan 7, 2020
@dfawley dfawley changed the title [1/2] SPIFFE: Util Lib for Advanced TLS Features advancedtls: add new module for advanced TLS handshaker Jan 7, 2020
@dfawley dfawley merged commit 4a4d179 into grpc:master Jan 7, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Type: Feature New features or improvements in behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants