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

meshca: credentials/sts: PerRPCCreds Implementation #3696

Merged
merged 7 commits into from
Jul 9, 2020

Conversation

easwars
Copy link
Contributor

@easwars easwars commented Jun 18, 2020

Implementation of call credentials based on https://tools.ietf.org/html/rfc8693.

@easwars easwars requested a review from dfawley June 18, 2020 17:00
@easwars easwars added the Type: Feature New features or improvements in behavior label Jun 18, 2020
@easwars easwars added this to the 1.31 Release milestone Jun 18, 2020
// callCreds provides the implementation of call credentials based on an STS
// token exchange.
type callCreds struct {
opts Options
Copy link
Contributor

Choose a reason for hiding this comment

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

One thought is we can decouple the call creds from the sts implementation. So the call creds is a thin wrapper of the sts implementation. This way, we may be able to move sts to other library (cloud libraries?).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried doing this. The problem seems to be the following:

  • Many of our call creds implementations model themselves after the oauth2.TokenSource interface which provides a Token method to retrieve the token to use. But this method does not take a context, and therefore it would be hard/ugly for us to enforce a timeout with this approach. There is an open issue for the same: TokenSource.Token method should take in a Context golang/oauth2#262.

And based on an offline discussion with @menghanl, we decided to keep the implementation as is.

@easwars
Copy link
Contributor Author

easwars commented Jul 7, 2020

@dfawley : Ping ...

credentials/sts/sts.go Show resolved Hide resolved
credentials/sts/sts.go Show resolved Hide resolved
Comment on lines 210 to 212
// Send the request with exponential backoff and retry. Even though not
// retrying here is OK, as the connection attempt will be retried by the
// subConn, it is not very hard to perform some basic retries here.
Copy link
Member

Choose a reason for hiding this comment

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

It's not hard, but it may go against some principles of gRPC. Consider the first connection attempt in particular -- if we get an error here caused by misconfiguration, we could return that error immediately and RPCs would fail right away at startup. But if we retry and wait for 20 seconds or a minute to elapse before failing, then even fail-fast RPCs will stall for that duration, when they have no hope of succeeding. Also, the error returned is (currently) the context error and not the last encountered error, which hurts debuggability (but this can be fixed).

Yes we will churn the server connection if a transient error occurs here, but that seems like a tradeoff worth making to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I remember Muxi saying that C-core does not do any retries here. I'm hearing that we shouldn't be doing any either. Shall I go ahead and get rid of all the code doing retries and just return an error if we run into one?

Copy link
Member

Choose a reason for hiding this comment

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

I think that would be best, yes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

credentials/sts/sts.go Outdated Show resolved Hide resolved
Copy link
Contributor Author

@easwars easwars left a comment

Choose a reason for hiding this comment

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

PTAL.

credentials/sts/sts.go Show resolved Hide resolved
credentials/sts/sts.go Show resolved Hide resolved
Comment on lines 210 to 212
// Send the request with exponential backoff and retry. Even though not
// retrying here is OK, as the connection attempt will be retried by the
// subConn, it is not very hard to perform some basic retries here.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I remember Muxi saying that C-core does not do any retries here. I'm hearing that we shouldn't be doing any either. Shall I go ahead and get rid of all the code doing retries and just return an error if we run into one?

credentials/sts/sts.go Outdated Show resolved Hide resolved
@dfawley dfawley assigned easwars and unassigned dfawley Jul 7, 2020
Also, refactor the code a bit for easier and better testing.
Copy link
Contributor Author

@easwars easwars left a comment

Choose a reason for hiding this comment

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

Also, refactored the code a bit for better testability. PTAL.

credentials/sts/sts.go Show resolved Hide resolved
Comment on lines 210 to 212
// Send the request with exponential backoff and retry. Even though not
// retrying here is OK, as the connection attempt will be retried by the
// subConn, it is not very hard to perform some basic retries here.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@easwars easwars assigned dfawley and unassigned easwars Jul 8, 2020
credentials/sts/sts.go Outdated Show resolved Hide resolved
credentials/sts/sts.go Show resolved Hide resolved
credentials/sts/sts.go Show resolved Hide resolved
credentials/sts/sts.go Outdated Show resolved Hide resolved
- Unexport [Request/Response]Parameters structs.
- Hold lock for entire duration of sts request.
- Don't ignore errors on attempts to read actor token.
credentials/sts/sts.go Outdated Show resolved Hide resolved
@easwars easwars merged commit e8fb6c1 into grpc:master Jul 9, 2020
@easwars easwars deleted the sts_call_creds branch August 4, 2020 21:12
@easwars easwars changed the title credentials/sts: PerRPCCreds Implementation meshca: credentials/sts: PerRPCCreds Implementation Mar 4, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 1, 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.

3 participants