jiangxt2 opened a new pull request, #14372:
URL: https://github.com/apache/gravitino/pull/14372

   ### What changes were proposed in this pull request?
   
   Derive cached token deadlines from OAuth2 response `expires_in` and JWT 
`exp`, use the earlier usable deadline, and renew on access with a lead of 
`min(30 seconds, 10% of the remaining lifetime at response receipt)`. 
Coordinate acquisition through an instance lock and replace the cache only 
after validating the complete token state.
   
   Preserve existing constructor parameters, the client credentials flow, and 
established exception categories while keeping credentials out of failure 
messages and exception context. Add focused regression coverage and document 
the resulting behavior.
   
   ### Why are the changes needed?
   
   The Python provider discards `expires_in`, renews only after JWT expiry, and 
does not coordinate concurrent acquisition. Applications can encounter failures 
near expiry or unclear behavior when expiry metadata is missing or malformed.
   
   Fixes #14339
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. On token access, the provider renews when the cached token enters its 
renewal window or has expired. It fails explicitly when neither expiry source 
is usable or accepted expiry metadata indicates an expired token. Failed 
renewal raises an SDK exception without returning the old token or replaying 
the metadata request. Callers sharing one provider can reuse a successful 
renewal; subsequent calls can retry after failure.
   
   ### How was this patch tested?
   
   Python commands run from `clients/client-python` using Python 3.10.22. 
Generate version metadata with `PYTHONPATH=. python 
scripts/generate_version.py` before running them. For OAuth IT, set 
`GRAVITINO_HOME` to an isolated built Gravitino distribution and 
`GRAVITINO_OAUTH2_SAMPLE_SERVER` to 
`datastrato/sample-authorization-server:0.3.0`. The real integration 
environment uses Gravitino 2.0.0-SNAPSHOT, Corretto 17.0.18, and authorization 
server 0.3.0.
   
   - `PYTHONPATH=. python -m unittest discover -s tests/unittests -v`: 1283 
tests passed, including expiry-source, short-lived-token, clock, failure, 
redaction, concurrency, and bounded-worker-exit regressions.
   - `DOCKER_TEST=true PYTHONPATH=. python -m unittest 
tests.integration.auth.test_oauth2_client.TestOAuth2 -v`: 5 tests passed, 
including real token acquisition, cache reuse, triggered renewal, and 
authenticated metadata access after renewal.
   - Black, Pylint, and the project's Ruff hooks passed for the changed Python 
files.
   - From the repository root, `./gradlew rat -PskipWeb=true 
-PskipDockerTests=true` passed; `git diff --check` passed.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to