Skip to content

Conversation

@googlyrahman
Copy link

@googlyrahman googlyrahman commented Dec 1, 2025

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.oauth2 and gcsfs/credentials implement 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 Unauthorised at 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.

@googlyrahman googlyrahman marked this pull request as draft December 1, 2025 21:55
@googlyrahman googlyrahman marked this pull request as ready for review December 1, 2025 21:55
@googlyrahman googlyrahman marked this pull request as draft December 1, 2025 22:09
@googlyrahman googlyrahman marked this pull request as ready for review December 2, 2025 06:24
@googlyrahman googlyrahman marked this pull request as draft December 2, 2025 06:44
Comment on lines +47 to +48
env_val = os.environ.get("FETCH_RAW_TOKEN_EXPIRY", "true").lower()
should_fetch_expiry = env_val not in ("false", "0", "off", "no")
Copy link
Member

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?

Copy link
Member

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
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Do not retry refreshing Credentials created from "raw" token

2 participants