-
Notifications
You must be signed in to change notification settings - Fork 164
Explicitly set the expiry time for raw token, and avoid retrying if it expires #716
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
base: main
Are you sure you want to change the base?
Conversation
| env_val = os.environ.get("FETCH_RAW_TOKEN_EXPIRY", "true").lower() | ||
| should_fetch_expiry = env_val not in ("false", "0", "off", "no") |
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.
Why would we NOT attempt to refresh expired or expiring tokens?
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.
OK, maybe I understand following your description in the PR. This would need careful documentation in the RTD prose pages.
| self.credentials.refresh(req) | ||
| except gauth.exceptions.RefreshError as error: | ||
| # There may be scenarios where this error is raised from the client side due | ||
| # to missing dependencies, especially when the client doesn't know how to refresh |
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.
Do we need to add to our dependencies? That would be better.
|
Please ping when you want me to look again |
|
/gcbrun |
|
/gcbrun(112238b) |
1 similar comment
|
/gcbrun(112238b) |
|
/gcbrun |
2 similar comments
|
/gcbrun |
|
/gcbrun |
Fixes #674
More detail about the solution can be found here - #674 (comment)
Important Note:
Short-lived raw tokens (with a lifespan of less than 5 minutes ) will not work. This is because both
google.oauth2andgcsfs/credentialsimplement a safety buffer to preemptively refresh tokens before they actually expire.google.oauth2: Uses a refresh buffer of 3 minutes 45 seconds, and consider them invalid if it's expiry is less than 3 minutes 45 seconds away.gcsfs: Uses a refresh buffer of 5 minutes, and consider it expired if expiry is less than 5 minutes far away.If a token's lifespan is shorter than these buffers, the libraries consider it effectively expired immediately. While standard credentials handle this by refreshing automatically, raw tokens cannot be refreshed, resulting in an authentication failure.
We could effectively pad the token expiry by 5 minutes to cancel out the buffer and let the token work until it completely expires. However, this will not fix the retry raw token issue: at the very edge of expiry, we might get a
401 Unauthorisedat any file using that credential, it would be hard to tell if that error is due to a raw token dying (fatal) or a general credential refresh (retriable), so keeping the buffer is actually the safer option.