Skip to content

Fix StaticCredentials refresh for short-lived JWTs - #945

Merged
vgvoleg merged 2 commits into
mainfrom
fix/static-credentials-jwt-expiration
Nov 16, 2026
Merged

vgvoleg merged 2 commits into
mainfrom
fix/static-credentials-jwt-expiration

Conversation

@vgvoleg

@vgvoleg vgvoleg commented Nov 16, 2026

Copy link
Copy Markdown
Member

StaticCredentials now derives the token lifetime from the login JWT's exp claim instead of assuming 30 minutes, so short-lived tokens are refreshed before they expire.

Cap the clock-skew allowance at one tenth of the remaining lifetime so tokens shorter than 30 seconds can be cached. The shared calculation applies to synchronous and asynchronous credentials.

Fixes #943.

@codecov

codecov Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.70%. Comparing base (e231157) to head (744f1bd).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #945   +/-   ##
=======================================
  Coverage   82.70%   82.70%           
=======================================
  Files          99       99           
  Lines       12960    12965    +5     
  Branches     1266     1266           
=======================================
+ Hits        10718    10723    +5     
  Misses       1789     1789           
  Partials      453      453           
Flag Coverage Δ
integration 80.40% <100.00%> (+<0.01%) ⬆️
unit 49.34% <28.57%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
ydb/credentials.py 84.39% <100.00%> (+0.57%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain, and the change includes synchronous and asynchronous coverage for JWT-based expiration and short-lived token refresh behavior.

No open issues 🎉

What changed in this PR

This pull request updates StaticCredentials to derive token lifetime from the login JWT's exp claim, ensuring short-lived tokens are refreshed before expiration.

Changes:

  • Calculate token lifetime from the JWT expiration claim.
  • Cap clock-skew protection at one tenth of the remaining lifetime.
  • Apply the shared expiration logic to synchronous and asynchronous credentials.
  • Add coverage for short-lived token caching and refresh behavior.
  • Document the fix in the changelog.
File Description
ydb/​credentials.py Derives token lifetime from JWT expiration and adjusts shared expiration protection for short-lived tokens.
tests/​auth/​test_static_credentials.py Tests JWT-based expiration handling and synchronous short-lived token refresh behavior.
tests/​aio/​test_credentials.py Tests asynchronous caching and refresh behavior for short-lived tokens.
CHANGELOG.md Documents the short-lived token refresh fix.

Review effort: Lite

@vgvoleg
vgvoleg merged commit a1e8d26 into main Nov 16, 2026
35 checks passed
@vgvoleg
vgvoleg deleted the fix/static-credentials-jwt-expiration branch November 16, 2026 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants