-
Notifications
You must be signed in to change notification settings - Fork 526
Detect misconfiguration of bundle_endpoint_profile #3395
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
Conversation
Signed-off-by: Ryuma Yoshida <[email protected]>
5086c66
to
4de58b1
Compare
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 think this is a good diagnostic! Thanks for this, @ryysud!
pkg/server/bundle/client/client.go
Outdated
var hostnameError *x509.HostnameError | ||
if errors.As(err, &hostnameError) && c.c.SPIFFEAuth == nil { | ||
id, e := spiffeid.FromString(hostnameError.Certificate.URIs[0].String()) | ||
if e != nil { | ||
return nil, errs.New("failed to fetch bundle: %v", err) | ||
} | ||
return nil, errs.New("failed to fetch bundle, the server certificate contains SPIFFE ID %q, should specify https_spiffe instead of https_web: %v", id, err) | ||
} |
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.
Line 78 will panic if the certificate does not contain a URI SAN. Also, the branch when e != nil
is not necessary since we can fall through to the return statement on line 84:
var hostnameError *x509.HostnameError | |
if errors.As(err, &hostnameError) && c.c.SPIFFEAuth == nil { | |
id, e := spiffeid.FromString(hostnameError.Certificate.URIs[0].String()) | |
if e != nil { | |
return nil, errs.New("failed to fetch bundle: %v", err) | |
} | |
return nil, errs.New("failed to fetch bundle, the server certificate contains SPIFFE ID %q, should specify https_spiffe instead of https_web: %v", id, err) | |
} | |
var hostnameError *x509.HostnameError | |
if errors.As(err, &hostnameError) && c.c.SPIFFEAuth == nil && len(hostnameError.Certificate.URIs) > 0 { | |
if id, idErr := spiffeid.FromString(hostnameError.Certificate.URIs[0].String()); idErr == nil { | |
return nil, errs.New("failed to authenticate bundle endpoint using web authentication but the server certificate contains SPIFFE ID %q: maybe use https_spiffe instead of https_web: %v", id, err) | |
} | |
} |
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.
pkg/server/bundle/client/client.go
Outdated
@@ -72,6 +73,12 @@ func NewClient(config ClientConfig) (Client, error) { | |||
func (c *client) FetchBundle(ctx context.Context) (*bundleutil.Bundle, error) { | |||
resp, err := c.client.Get(c.c.EndpointURL) | |||
if err != nil { | |||
var hostnameError *x509.HostnameError |
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 was doing some quick testing and noticed that the x509 stack returns this error as a struct value (i.e. x509.HostnameError{}
), not a pointer to struct value (i.e. &x509.HostnameError
). This means that errors.As will return false unless passed a pointer to the struct, not a pointer to a pointer.
var hostnameError *x509.HostnameError | |
var hostnameError x509.HostnameError |
I can push a commit with my tests.
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.
Fix: 9562435
Signed-off-by: Ryuma Yoshida <[email protected]>
…o detect-misconfiguration
Thanks for your help shepherding this @azdagron - @amartinezfayo has volunteered to review when you're done |
Signed-off-by: Andrew Harding <[email protected]>
I've added a unit test. @amartinezfayo if you could please take a look. |
Oops. I forgot one crucial change to the test framework to support this :) Change incoming. |
Signed-off-by: Andrew Harding <[email protected]>
Signed-off-by: Andrew Harding <[email protected]>
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.
* Detect misconfiguration of bundle_endpoint_profile Signed-off-by: Ryuma Yoshida <[email protected]> Co-authored-by: Andrew Harding <[email protected]>
Signed-off-by: Ryuma Yoshida [email protected]
Pull Request check list
Affected functionality
Federation.
Description of change
Detect misconfiguration of bundle_endpoint_profile.
https://github.com/spiffe/spire/blob/v1.4.0/doc/spire_server.md#configuration-options-for-federationfederates_withtrust-domainbundle_endpoint
Which issue this PR fixes