-
Notifications
You must be signed in to change notification settings - Fork 183
feat(jwt): add configurable time-tolerance for clock-skew tolerance - #336
Open
sweengineeringlabs wants to merge 1 commit into
Open
feat(jwt): add configurable time-tolerance for clock-skew tolerance #336sweengineeringlabs wants to merge 1 commit into
sweengineeringlabs wants to merge 1 commit into
Conversation
Adds an optional time-tolerance field to the [jwt] section of server.toml. When set, JWT nbf/exp validation accepts tokens whose timestamps fall within the specified tolerance, accommodating deployments where the token issuer and the atticd host have unsynchronised clocks. Common case: microVM and container guests that boot without NTP have clocks that lag the host by tens of seconds. Tokens minted on the host carry nbf=now (host time), which is in atticd's future, causing HTTP 401 on every request. The tolerance is configurable rather than hardcoded so operators of public or multi-tenant caches are unaffected by default. The field is opt-in: omitting it preserves the existing behaviour (time_tolerance: None). Security note: time-tolerance widens the acceptance window symmetrically. It does not bypass exp. A token with validity=1h and time-tolerance=2m is valid for at most 62 minutes. Example server.toml: [jwt] time-tolerance = "30s"
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.
Uh oh!
There was an error while loading. Please reload this page.
Problem
from_jwtis called withtime_tolerance: None, meaning JWT verification rejects any token whosenbfclaim is even one second in the server's future. In practice, the token issuer and atticd rarely share a perfectly synchronised clock:nbf = WSL2_time; atticd running in a microVM reads the host system clock. WSL2 can drift a few seconds from the Windows host clock.RFC 7519 §4.1.5 explicitly acknowledges this:
Without a configurable leeway there is no standards-compliant way to handle this; operators are forced to either accept spurious 401s or patch the binary.
Change
Adds an optional
time-tolerancefield to the[jwt]section ofserver.toml:Threads through three files:
token/src/lib.rs—from_jwtgains anOption<std::time::Duration>parameter; mapped toVerificationOptionsinstead of hardcodedNoneserver/src/config.rs—JWTConfiggainstime_tolerance: Option<std::time::Duration>withhumantime_serde::option(already a server dependency)server/src/access/http.rs— call site passesstate.config.jwt.time_toleranceDesign decisions
Configurable, not hardcoded. A hardcoded tolerance silently changes the security posture of every deployment. Making it opt-in means the default behaviour is unchanged and operators explicitly accept the trade-off.
humantime_serdewas already a dependency of the server crate — no new deps added.Security note
time-tolerancewidens thenbfacceptance window only. It does not bypassexp. A token withvalidity = 1handtime-tolerance = 30sis accepted for at most 1h 30s. For a private single-tenant cache a value of 30–60 seconds is the right trade-off; for a public cache operators should leave it unset (the default, preserving existing behaviour).Testing
Verified that
cargo build -p attic-servercompiles cleanly with these changes.Happy to add a unit test or adjust the field name / defaults if you prefer a different approach.