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

credentials: check and expose SPIFFE ID #3626

Merged
merged 6 commits into from Jul 16, 2020

Conversation

ZhenLian
Copy link
Contributor

@ZhenLian ZhenLian commented May 18, 2020

This PR does the following three things:

  1. add a new field SpiffeID to the struct TLSInfo
  2. add a function ParseSpiffeID to TLSInfo that will check the format of SPIFFE ID, and fill in
    if the check passes
  3. call ParseSpiffeID at the end of ClientHandshake and ServerHandshake to fill the SpiffeID

After this change, users could use

ctx context.Context
p, ok := peer.FromContext(ctx)
tlsInfo, ok := p.AuthInfo.(credentials.TLSInfo)

to get the SPIFFE ID information(error handling omitted).

Note that parsing of URI fields is only supported in go version >= 1.10. For earlier versions, we log the error information and don't expose the field, and return a nil error.

@ZhenLian
Copy link
Contributor Author

@jiangtaoli2016 Can you please first take a look at the correctness of the plumbing flow and SPIFFE ID check? Thanks in advance!

@ZhenLian
Copy link
Contributor Author

F.Y.I. https://github.com/spiffe/spiffe/blob/master/standards/SPIFFE-ID.md#23-maximum-spiffe-id-length this describes the maximum length of a SPIFFE ID.

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! A minor comment.

credentials/tls.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.

Thanks @ZhenLian for revision. A few minor comments.

credentials/tls.go Outdated Show resolved Hide resolved
credentials/go10.go Outdated Show resolved Hide resolved
credentials/go10.go Outdated Show resolved Hide resolved
@jiangtaoli2016
Copy link
Contributor

We should also choose a Golang readability reviewer.

@jiangtaoli2016
Copy link
Contributor

PS: I am fine with not parsing SPIFFE ID for go version 1.9 and before -- for now. We may revisit this later.

credentials/go10.go Outdated Show resolved Hide resolved
@ZhenLian
Copy link
Contributor Author

ZhenLian commented Jun 2, 2020

@doug Since this change touches some part of tls pkg, could you review it please? Thanks in advance!

@ZhenLian ZhenLian requested a review from dfawley June 2, 2020 05:29
@ZhenLian
Copy link
Contributor Author

ZhenLian commented Jun 11, 2020

Sorry it seems I @ ed the wrong person... @dfawley this change touches some part of tls package. could you please take a look at this please? Feel free to let me know if you have any concerns.
Thank you so much!

@dfawley dfawley self-assigned this Jun 11, 2020
credentials/credentials_go10_test.go Outdated Show resolved Hide resolved
credentials/go10.go Outdated Show resolved Hide resolved
credentials/go10.go Outdated Show resolved Hide resolved
credentials/go10.go Outdated Show resolved Hide resolved
credentials/tls.go Outdated Show resolved Hide resolved
credentials/go10.go Outdated Show resolved Hide resolved
)

func (t *TLSInfo) ParseSpiffeID() error {
grpclog.Info("go version prior to 1.10 doesn't support parsing URIs in certificates. Please consider a newer version")
Copy link
Member

Choose a reason for hiding this comment

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

You can delete this; users don't need a log line every time they make a connection, and Go 1.9 isn't supported anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

SG. I added a TODO above this function to remind me for the future deletion of this file. Please let me know if this works for you. Thanks!

@ZhenLian ZhenLian force-pushed the zhen_expose_spiffe_id branch 6 times, most recently from af83b10 to 43a0b64 Compare June 15, 2020 00:06
@ZhenLian
Copy link
Contributor Author

@dfawley This PR is ready again. Please let me know if it could be better improved. Thanks a lot for the review!

@ZhenLian ZhenLian requested a review from dfawley June 15, 2020 04:03
@@ -87,6 +88,7 @@ func (s SecurityLevel) String() string {
// This API is experimental.
type CommonAuthInfo struct {
SecurityLevel SecurityLevel
SPIFFEID *url.URL
Copy link
Member

Choose a reason for hiding this comment

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

I wouldn't consider SPIFFE to be "common" to all transport security implementations. I don't think it makes as much sense here, at least not if the only reason to move it was because this struct is already marked as experimental.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it. I put it back to TLSInfo. Since TLSInfo itself is not EXPERIMENTAL, I marked only the SPIFFEID EXPERIMENTAL. Please let me know if it works:)

internal/credentials/go110.go Outdated Show resolved Hide resolved
@dfawley dfawley assigned ZhenLian and unassigned dfawley Jun 25, 2020
@ZhenLian
Copy link
Contributor Author

@dfawley I'd like to provide some updates on this PR:
We found that the envoy RBAC assumed that the SPIFFE ID is the first URI entry, because for a valid SPIFFE certificate, there would always be exactly one URI field with spiffe scheme. We'd like to keep alignment with this, so after the change, a certificate with IDs, say "spiffe://foo/bar" and "https://foo/bar" would be considered as invalid(similar changes in C core).
For invalid certs, we'd also like to not return errors, but just to log the errors and not plumb the ID.
@jiangtaoli2016 since this includes some logic changes(although not much), can you please take a look at the latest commit first? Thank you so much!

internal/credentials/go110.go Show resolved Hide resolved
internal/credentials/go110.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.

Thanks much Zhen for quick revision!

@ZhenLian
Copy link
Contributor Author

@dfawley Hi Doug, this PR is ready for review again (sorry for the back and forth) :)

@dfawley dfawley added this to the 1.31 Release milestone Jul 8, 2020
@ZhenLian ZhenLian merged commit dd8658f into grpc:master Jul 16, 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants