feat: add HKDF key derivation infrastructure for domain-separated secret usage#192
Draft
feat: add HKDF key derivation infrastructure for domain-separated secret usage#192
Conversation
…ret usage Add DeriveKey() using HKDF-SHA256 with versioned salt and purpose-specific context strings for domain separation. Add v2 bearer token generation (NewBearerTokenV2) and dual v1/v2 validation in ValidateToken(). New files: - crypto/derive.go: DeriveKey, DetectTokenVersion, FormatV2Token, context constants - crypto/derive_test.go: comprehensive tests for derivation and version detection Modified: - authentication/authentication.go: NewBearerTokenV2, validateTokenInner refactor - authentication/authentication_test.go: v2 generation, validation, cross-version tests
Contributor
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
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
DeriveKey()using HKDF-SHA256 with versioned salt (agentuity-key-derivation-v2) and purpose-specific context strings for domain separationNewBearerTokenV2()for v2 bearer token generation withv2.bearer-token.<payload>prefix formatValidateToken()with automatic v1/v2 detection and dual validation for backward compatibilityDetectTokenVersion()andFormatV2Token()helpers for version-aware token handlingContext
This is the go-common half of a two-repo change. The corresponding ion PR migrates all usage sites to HKDF-derived keys.
The catalyst shared secret was being used directly (without derivation) for 7 distinct purposes: bearer tokens, sticky sessions, postgres internal auth, gravity JWT signing, S3 webhook tokens, ECDSA signing, and raw secret comparison. Using the same key material across different cryptographic contexts violates domain separation — a compromise in one system could affect all others.
New Files
crypto/derive.go—DeriveKey,DetectTokenVersion,FormatV2Token, 5 context constantscrypto/derive_test.go— 13 tests covering determinism, domain separation, error cases, version detectionModified Files
authentication/authentication.go—NewBearerTokenV2,validateTokenInnerrefactorauthentication/authentication_test.go— 6 new v2 tests (generation, validation, cross-version isolation)Deployment Notes
Must be deployed before the ion PR. The updated
ValidateToken()accepts both v1 and v2 tokens, so deploying this first ensures all instances can validate v2 tokens before any instance starts generating them.