Skip to content

feat(ai): add zero-downtime gateway HMAC key rotation - #113

Merged
seonghobae merged 39 commits into
mainfrom
feat/ai-gateway-key-rotation
Aug 5, 2026
Merged

feat(ai): add zero-downtime gateway HMAC key rotation#113
seonghobae merged 39 commits into
mainfrom
feat/ai-gateway-key-rotation

Conversation

@seonghobae

@seonghobae seonghobae commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Buyer-visible outcome

Private web-to-AI service authentication can rotate HMAC credentials without rejecting valid in-flight requests during a bounded deployment overlap, while compromised or retired keys can still be rejected immediately.

Implemented contract

  • versioned life-os.ai-context.v2 canonical HMAC input
  • integrity-protected, case-sensitive x-life-os-context-key-id
  • one mandatory active signing/verifying key and at most one previous verification-only key
  • exact identifier selection with no trial verification across unrelated secrets
  • active-only signing in the web BFF and active-or-previous verification in AI service
  • fail-closed partial, duplicate, malformed, reused-secret, unknown, and retired key handling
  • method, exact path, workspace, actor, issuance time, and key identifier binding
  • bounded canonical Base64URL signature validation and constant-time comparison
  • credential-free 401 request failures and 503 local-verifier-configuration failures
  • every proposal and proposal-audit route migrated to the keyed context boundary
  • server-only environment contract and staged expand/switch/retire/emergency-revocation runbook

Evidence

  • unit coverage for key configuration, exact selection, overlap, retirement, replay, forgery, identifier substitution, path/method binding, clock boundaries, and canonical encoding
  • web BFF evidence that only the active key signs and browser credentials never reach AI service
  • real PostgreSQL HTTP integration evidence that a previous key succeeds during overlap, fails immediately after removal, and the active key remains available
  • AI-service statement, branch, function, and line coverage held at 100%
  • current standards review distinguishing final NIST SP 800-57 Part 1 Revision 5 from the 2025 Revision 6 Initial Public Draft, with APA 7 references to NIST, RFC 7515, RFC 8725, and OWASP guidance
  • CHANGELOG.md, capability evidence, formatting contracts, and runtime documentation updated

Merge gate

Formatting, lint, type checking, complete tests, build, Compose validation, AppGuardrail, Semgrep, Security Scan, Commercial Readiness, CodeRabbit, and every actionable human/security review thread must pass on the exact current head before squash merge.

Closes #112.

Refs #109 and #46.

Summary by CodeRabbit

  • 새 기능

    • AI Gateway 인증에 키 식별자 기반 HMAC 키 로테이션을 도입했습니다.
    • 활성 키와 이전 키를 제한적으로 중첩 지원해 무중단 교체가 가능합니다.
    • 폐기되거나 알 수 없는 키는 즉시 거부됩니다.
  • 문서

    • 키 교체, 긴급 폐기, 롤백 절차를 안내하는 운영 문서를 추가했습니다.
  • 보안

    • 인증 방식을 HMAC v2로 강화하고, 잘못된 설정은 안전하게 실패하도록 개선했습니다.

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 84d91fbb-4b80-4a47-953a-5fa69c3e57f6

📥 Commits

Reviewing files that changed from the base of the PR and between f5cb401 and a35a609.

📒 Files selected for processing (24)
  • .env.example
  • CHANGELOG.md
  • apps/ai-service/migrations/README.md
  • apps/ai-service/package.json
  • apps/ai-service/src/ai-gateway-keyring.test.ts
  • apps/ai-service/src/ai-gateway-keyring.ts
  • apps/ai-service/src/ai-http-boundary.test.ts
  • apps/ai-service/src/ai-http-boundary.ts
  • apps/ai-service/src/main.ts
  • apps/ai-service/src/no-silent-mutation.integration.test.ts
  • apps/ai-service/src/proposal-audit-http.integration.test.ts
  • apps/ai-service/src/quality-coverage.test.ts
  • apps/web/app/ai-proposal-client-core.ts
  • apps/web/app/ai-proposal-client.test.ts
  • apps/web/app/ai-proposal-client.ts
  • apps/web/app/ai-proposal-identity-stream-regression.test.ts
  • apps/web/app/ai-proposal-scope-regression.test.ts
  • apps/web/app/api/ai/proposals/routes.test.ts
  • docs/operations/ai-gateway-key-rotation.md
  • docs/research/2026-08-04-ai-gateway-key-rotation-standards.md
  • docs/superpowers/plans/2026-08-04-ai-gateway-key-rotation.md
  • docs/superpowers/specs/2026-08-04-ai-gateway-key-rotation-design.md
  • package.json
  • product/capabilities.json

📝 Walkthrough

Walkthrough

AI 게이트웨이 인증이 단일 시크릿에서 keyId 기반 v2 HMAC 키링으로 변경되었습니다. 웹 게이트웨이는 활성 키로 서명하고, AI 서비스는 활성 키 또는 이전 키를 선택해 검증합니다. 키 회전 운영 문서와 테스트도 갱신되었습니다.

Changes

AI 게이트웨이 키 로테이션

Layer / File(s) Summary
키 계약과 키링 검증
apps/ai-service/src/ai-gateway-keyring.ts, apps/ai-service/src/ai-gateway-keyring.test.ts, apps/ai-service/migrations/README.md, docs/research/..., docs/superpowers/specs/...
활성 키와 선택적 이전 키를 정의했습니다. 키 식별자와 시크릿의 형식·길이를 검증합니다. 중복, 재사용, 불완전한 설정을 거부합니다.
웹 게이트웨이 서명 흐름
apps/web/app/ai-proposal-client-core.ts, apps/web/app/ai-proposal-client.ts, apps/web/app/*test.ts, apps/web/app/api/ai/proposals/routes.test.ts
웹 게이트웨이가 활성 키를 로드합니다. life-os.ai-context.v2 서명 입력과 x-life-os-context-key-id 헤더를 생성합니다.
AI 서비스 검증과 컨트롤러 연결
apps/ai-service/src/ai-http-boundary.ts, apps/ai-service/src/main.ts, apps/ai-service/src/*test.ts
AI 서비스가 keyId로 검증 키를 선택합니다. 설정 오류는 503으로, 알 수 없거나 폐기된 키는 401로 처리합니다. 제안 및 감사 엔드포인트가 keyId를 전달합니다.
운영 절차와 릴리스 증거
docs/operations/ai-gateway-key-rotation.md, CHANGELOG.md, package.json, apps/ai-service/package.json, product/capabilities.json
키 교체·폐기 절차와 보안 표준을 문서화했습니다. 포맷 검사 대상과 capability evidence를 갱신했습니다.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant WebBFF
  participant AiService
  participant AiGatewayKeyring
  participant AiProposalController
  WebBFF->>WebBFF: 활성 키로 v2 HMAC 생성
  WebBFF->>AiService: keyId 헤더와 서명된 컨텍스트 전송
  AiService->>AiGatewayKeyring: keyId로 검증 키 선택
  AiGatewayKeyring-->>AiService: 활성 또는 이전 키 반환
  AiService->>AiProposalController: 검증된 컨텍스트 전달
  AiProposalController-->>WebBFF: 제안 또는 감사 응답 반환
Loading
✨ Finishing Touches 💡 1
⚔️ Resolve merge conflicts 💡
  • Resolve merge conflict in branch feat/ai-gateway-key-rotation
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/ai-gateway-key-rotation

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

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Comment thread .github/workflows/complete-ai-key-rotation.yml Fixed
Comment thread .github/workflows/fix-ai-key-rotation-helper.yml Fixed
Comment thread .github/workflows/run-ai-key-rotation-codemod.yml Fixed
Comment thread .github/workflows/run-ai-key-rotation-codemod.yml Fixed
@seonghobae seonghobae changed the title feat(ai): add bounded gateway key rotation foundation feat(ai): add zero-downtime gateway HMAC key rotation Aug 4, 2026
@seonghobae
seonghobae marked this pull request as ready for review August 4, 2026 23:55

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@seonghobae
seonghobae merged commit a9bd88c into main Aug 5, 2026
34 checks passed

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
⚠️ Action not completed

Pull request is closed.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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.

Add zero-downtime AI gateway context key rotation

2 participants