Skip to content

feat: add HKDF key derivation infrastructure for domain-separated secret usage#192

Draft
jhaynie wants to merge 1 commit intomainfrom
task/hkdf-for-master-key
Draft

feat: add HKDF key derivation infrastructure for domain-separated secret usage#192
jhaynie wants to merge 1 commit intomainfrom
task/hkdf-for-master-key

Conversation

@jhaynie
Copy link
Copy Markdown
Member

@jhaynie jhaynie commented Mar 30, 2026

Summary

  • Add DeriveKey() using HKDF-SHA256 with versioned salt (agentuity-key-derivation-v2) and purpose-specific context strings for domain separation
  • Add NewBearerTokenV2() for v2 bearer token generation with v2.bearer-token.<payload> prefix format
  • Update ValidateToken() with automatic v1/v2 detection and dual validation for backward compatibility
  • Add DetectTokenVersion() and FormatV2Token() helpers for version-aware token handling

Context

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.goDeriveKey, DetectTokenVersion, FormatV2Token, 5 context constants
  • crypto/derive_test.go — 13 tests covering determinism, domain separation, error cases, version detection

Modified Files

  • authentication/authentication.goNewBearerTokenV2, validateTokenInner refactor
  • authentication/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.

…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
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 30, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f5f93827-a833-4045-baf9-648f06ed425d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant