feat(auth): kid-based JWT key rotation support - #60
Merged
Conversation
Add 'kid' (key ID) header to all asymmetric JWTs to enable graceful key rotation without flag-day cutoffs. The kid is computed as the first 16 hex characters of SHA-256 over the public key's DER-encoded SubjectPublicKeyInfo, making it deterministic and independent of key format. Issuance (manager): - AuthService.create_access_token() and create_refresh_token() now include kid header computed from the signing private key - ClientConfigManager._generate_domain_jwt() includes kid header for domain tokens - Adds compute_kid_from_private_pem() and compute_kid_from_public_pem() helpers Verification (dns-server/dhcp-server/ntp-server): - verify_squawk_jwt() and verify_token() support kid-based key selection - Load multiple public keys from directory (JWT_PUBLIC_KEYS_DIR) or env - Token with kid: match to loaded key by computed kid, reject if unknown (fail-closed) - Token without kid: try all loaded keys (backward compat during rotation) - Single key fallback: JWT_PUBLIC_KEY still works for non-rotating deployments Configuration: - New JWT_PUBLIC_KEYS_DIR env var on verifiers to load rotation key set - Existing JWT_PUBLIC_KEY env/file continues to work (backward compat) Tests: - Manager: test_jwt_kid_rotation.py covers kid computation, determinism, and JWT issuance - DNS: TestKidBasedKeyRotation covers kid selection, unknown kid rejection, backward compat with kid-less tokens, and fail-closed behavior - All existing tests pass (JWT signing/verification unchanged, kid is transparent) Documentation: - Add key rotation runbook to ENTERPRISE_SECURITY.md explaining overlap window and zero-downtime rotation steps - Document JWT_PUBLIC_KEYS_DIR configuration Rotation flow: distribute new public key → wait for propagation → switch manager signing key → monitor for old-key rejections → retire old key after TTL. Tokens without kid remain verifiable throughout rotation for 100% compatibility. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
🧙 Sourcery is reviewing your pull request! Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Sorry @PenguinzTech, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
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.
Adds
kid(key ID) headers to every asymmetric JWT the manager issues and multi-key support (JWT_PUBLIC_KEYS_DIR) to all four verifier surfaces (dns-server, dhcp-server, ntp-server, manager). kid = truncated SHA-256 of the public key SPKI, derived — no config. Kid match wins; kid-less tokens try all loaded keys (overlap compat); zero keys fails closed. Rotation runbook added to docs/ENTERPRISE_SECURITY.md.Tests: 69 green across manager/dns/dhcp (8 new kid tests + 5 rotation tests).
Merge order: merge this before the other auth branches (NHI/MFA/audit build on the same issuance path).
Stack note: bases on
chore/dedup-reusable-code(top of the #53–#59 chain); auto-retargets towardv2.1.xas the stack merges bottom-up.🤖 Generated with Claude Code
Summary by Sourcery
Introduce kid-based JWT key rotation across manager and all verifier services, enabling multi-key overlap and fail-closed verification behavior.
New Features:
Enhancements:
Documentation:
Tests: