Merged
Conversation
…idation Fix multiple bugs causing API keys to expire incorrectly or become unusable, even when set to infinite validity (TTL=-1).
evan-datadog
previously approved these changes
Mar 23, 2026
evan-datadog
left a comment
There was a problem hiding this comment.
Mind also fixing line 84 so it no longer uses utcnow in setup.py ?
FrancescoMarabotto
previously approved these changes
Mar 24, 2026
Use datetime.now(timezone.utc) which produces a timezone-aware datetime with correct ISO format (includes +00:00 suffix).
fefad42
Author
Done 👍 |
FrancescoMarabotto
approved these changes
Mar 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
API keys become unusable shortly after creation, even when set to infinite validity (TTL=-1). This PR fixes four interrelated bugs in API key timestamp handling.
Bugs Fixed
Bug 1: Timezone mismatch in expiration validation (
lemur/auth/service.py)Before:
fromtimestamp()returns local time but is compared againstutcnow()(UTC). On non-UTC servers, keys expire at wrong times — off by the server's timezone offset.After:
Bug 2: Wrong epoch stored for
issued_at(lemur/api_keys/views.py,cli.py)Before:
datetime.utcnow()returns UTC values, but.timestamp()interprets the naive datetime as local time, storing a wrong Unix epoch on non-UTC servers.After:
time.time()always returns the correct UTC epoch regardless of server timezone.Bug 3: CLI doesn't convert TTL to int (
lemur/api_keys/cli.py)Before:
CLI arguments are strings.
"-1" != -1(string vs int), socreate_tokenwon't remove theexpclaim from the JWT, causing the token to get the default 1-day expiration even for "infinite" keys created via CLI.After:
Bug 4: No TTL validation (
lemur/api_keys/schemas.py)TTL=0 would silently create an immediately-expired key. Added
@validates("ttl")to all API key input schemas to reject TTL=0 and TTL < -1. Only TTL=-1 (infinite) and positive integers (days) are accepted.Hardening: Disable PyJWT built-in exp verification (
lemur/auth/service.py)Added
"verify_exp": Falsetojwt.decode()options since expiration is already handled manually inlogin_required. This prevents future PyJWT behavior changes from breaking infinite API keys (which have noexpclaim in their JWT). Manualexpchecking is added for regular user tokens.Test plan