-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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: Rename custom verification function APIs #7140
Changes from 6 commits
5c7819f
79b35eb
e1248b0
0d6185d
53323db
5920acc
010d89e
718e858
6bcc5f8
e6f065e
84aa942
52dbf58
bb4d7b2
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 |
---|---|---|
|
@@ -73,8 +73,8 @@ type VerificationResults = PostHandshakeVerificationResults | |
// PostHandshakeVerificationFunc is the function defined by users to perform | ||
// custom verification checks after chain building and regular handshake | ||
// verification has been completed. | ||
// PostHandshakeVerificationFunc returns nil | ||
// if the authorization fails; otherwise returns an empty struct. | ||
// PostHandshakeVerificationFunc should return (nil, error) if the authorization | ||
// should fail, with the error containing information on why it failed. | ||
type PostHandshakeVerificationFunc func(params *HandshakeVerificationInfo) (*PostHandshakeVerificationResults, error) | ||
|
||
// CustomVerificationFunc is the function defined by users to perform custom | ||
|
@@ -186,10 +186,17 @@ type ClientOptions struct { | |
// IdentityOptions is OPTIONAL on client side. This field only needs to be | ||
// set if mutual authentication is required on server side. | ||
IdentityOptions IdentityCertificateOptions | ||
// AdditionalPeerVerification is a custom verification check after certificate signature | ||
// check. | ||
// If this is set, we will perform this customized check after doing the | ||
// normal check(s) indicated by setting VType. | ||
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. VType->VerificationType? 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. Ah I think I lost some in the merge, good catch |
||
AdditionalPeerVerification PostHandshakeVerificationFunc | ||
// VerifyPeer is a custom verification check after certificate signature | ||
// check. | ||
// If this is set, we will perform this customized check after doing the | ||
// normal check(s) indicated by setting VType. | ||
// | ||
// Deprecated: use AdditionalPeerVerification instead. | ||
VerifyPeer PostHandshakeVerificationFunc | ||
// RootOptions is OPTIONAL on client side. If not set, we will try to use the | ||
// default trust certificates in users' OS system. | ||
|
@@ -225,10 +232,17 @@ type ClientOptions struct { | |
type ServerOptions struct { | ||
// IdentityOptions is REQUIRED on server side. | ||
IdentityOptions IdentityCertificateOptions | ||
// AdditionalPeerVerification is a custom verification check after certificate signature | ||
// check. | ||
// If this is set, we will perform this customized check after doing the | ||
// normal check(s) indicated by setting VType. | ||
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. VerificationType 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. Good catch |
||
AdditionalPeerVerification PostHandshakeVerificationFunc | ||
// VerifyPeer is a custom verification check after certificate signature | ||
// check. | ||
// If this is set, we will perform this customized check after doing the | ||
// normal check(s) indicated by setting VType. | ||
// | ||
// Deprecated: use AdditionalPeerVerification instead. | ||
VerifyPeer PostHandshakeVerificationFunc | ||
// RootOptions is OPTIONAL on server side. This field only needs to be set if | ||
// mutual authentication is required(RequireClientCert is true). | ||
|
@@ -258,13 +272,18 @@ type ServerOptions struct { | |
} | ||
|
||
func (o *ClientOptions) config() (*tls.Config, error) { | ||
// TODO(gtcooke94) Remove this block when remove o.VerifyPeer | ||
// Set AdditionalPeerVerification if the user is still using VerifyPeer. | ||
if o.VerifyPeer != nil { | ||
o.AdditionalPeerVerification = o.VerifyPeer | ||
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.
Or ignore the old deprecated field if o.AdditionalPeerVerification == nil {
o.AdditionalPeerVerification = o.VerifyPeer
} 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. It's not required, so the error return I think doesn't make the most sense. The reverse works too, I guess it just matters for the precedence - I was going with "if the old field is set they probably haven't migrated", but the bottom is good too as a "if the new field isn't set take whatever is in the old field" 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. The error would be "you set two fields that mean the same thing, one of which is deprecated: what were you thinking?" 😆 |
||
} | ||
// TODO(gtcooke94). VType is deprecated, eventually remove this block. This | ||
// will ensure that users still explicitly setting `VType` will get the | ||
// setting to the right place. | ||
if o.VType != CertAndHostVerification { | ||
o.VerificationType = o.VType | ||
} | ||
if o.VerificationType == SkipVerification && o.VerifyPeer == nil { | ||
if o.VerificationType == SkipVerification && o.AdditionalPeerVerification == nil { | ||
return nil, fmt.Errorf("client needs to provide custom verification mechanism if choose to skip default verification") | ||
} | ||
// Make sure users didn't specify more than one fields in | ||
|
@@ -340,13 +359,18 @@ func (o *ClientOptions) config() (*tls.Config, error) { | |
} | ||
|
||
func (o *ServerOptions) config() (*tls.Config, error) { | ||
// TODO(gtcooke94) Remove this block when remove o.VerifyPeer | ||
// Set AdditionalPeerVerification if the user is still using VerifyPeer. | ||
if o.VerifyPeer != nil { | ||
o.AdditionalPeerVerification = o.VerifyPeer | ||
} | ||
// TODO(gtcooke94). VType is deprecated, eventually remove this block. This | ||
// will ensure that users still explicitly setting `VType` will get the | ||
// setting to the right place. | ||
if o.VType != CertAndHostVerification { | ||
o.VerificationType = o.VType | ||
} | ||
if o.RequireClientCert && o.VerificationType == SkipVerification && o.VerifyPeer == nil { | ||
if o.RequireClientCert && o.VerificationType == SkipVerification && o.AdditionalPeerVerification == nil { | ||
return nil, fmt.Errorf("server needs to provide custom verification mechanism if choose to skip default verification, but require client certificate(s)") | ||
} | ||
// Make sure users didn't specify more than one fields in | ||
|
@@ -621,7 +645,7 @@ func NewClientCreds(o *ClientOptions) (credentials.TransportCredentials, error) | |
config: conf, | ||
isClient: true, | ||
getRootCAs: o.RootOptions.GetRootCertificates, | ||
verifyFunc: o.VerifyPeer, | ||
verifyFunc: o.AdditionalPeerVerification, | ||
verificationType: o.VerificationType, | ||
revocationConfig: o.RevocationConfig, | ||
} | ||
|
@@ -640,7 +664,7 @@ func NewServerCreds(o *ServerOptions) (credentials.TransportCredentials, error) | |
config: conf, | ||
isClient: false, | ||
getRootCAs: o.RootOptions.GetRootCertificates, | ||
verifyFunc: o.VerifyPeer, | ||
verifyFunc: o.AdditionalPeerVerification, | ||
verificationType: o.VerificationType, | ||
revocationConfig: o.RevocationConfig, | ||
} | ||
|
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.
Suggestion:
PeerVerificationFunc
(and all associated types)? It's a shorter name and (maybe?) is named after the intent of the thing vs. when it happens.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.
We want to make sure that we are differentiating between verification happening after the normal chain building and verification that happens by default (which this is), and overriding the base chain building and verification itself.
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.
I'm not sure I follow all this.
What is "post handshake verification" exactly? And you're saying this can be used to replace the default behavior? What is the default behavior? Do you have any examples of what users would want to do with this?
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.
There's two main different ways users could desire to customize verification behavior.
During verification we takes the peer's untrusted chain and build a chain from it to a trusted root.
A concrete example of (2) is doing additional check on the hostname of the peer's cert.
A concrete example of (1) would be fully changing the process by which you build a chain to a trusted root using other information, for example SPIFFE IDs.
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.
What's the API for (2)?
VerifyPeer
?So is it the case that if you specify this callback then
VerifyPeer
isn't called?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.
Yes the API for (2) is
VerifyPeer
. When set it eventually cascades to here -grpc-go/security/advancedtls/advancedtls.go
Lines 581 to 582 in 34de5cf
And
VerifyPeer
is of typePostHandshakeVerificationFunc
, I think renaming this option fromVerifyPeer
to something more clear is probably belongs in this PR as wellThere 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.
Renamed
VerifyPeer
in the settings struct, PTAL