feat: S3 envelope encryption for data-at-rest protection#459
Closed
feat: S3 envelope encryption for data-at-rest protection#459
Conversation
Implement envelope encryption (AES-256-GCM) for all S3-stored data including user files, session messages, and attachments. Each object gets a unique DEK wrapped by both user KEK (derived from API key) and admin KEK (derived from master key), enabling per-project key rotation without re-encrypting data. Key changes: - Add crypto package with HKDF key derivation and AES-256-GCM envelope encryption - Modify S3 upload/download paths in both Go API and Python Core to encrypt/decrypt - Auth middleware derives user KEK from API key and injects into gin context - Replace presigned URL downloads with API-proxied streaming (server-side decryption) - Update TS/PY SDKs to use new API proxy download instead of presigned URLs - Backward compatible: unencrypted legacy objects still readable Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
d2e24dd to
5805c1c
Compare
Contributor
Author
Code reviewFound 3 issues:
Acontext/src/server/api/go/internal/modules/handler/session.go Lines 575 to 593 in 5805c1c
Acontext/src/server/api/go/internal/infra/blob/s3.go Lines 216 to 256 in 5805c1c
Acontext/src/server/api/go/internal/modules/service/agent_skills.go Lines 567 to 575 in 5805c1c Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
- Add project ownership check in DownloadSessionAsset to prevent unauthorized access to other projects' S3 objects via arbitrary s3_key - Skip content-addressed dedup when encryption is enabled to avoid cross-user DEK conflicts (different users need different wrapped DEKs) - Restore presigned URL path for binary files when encryption is disabled, only proxy through API server when encryption requires server-side decrypt Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
Author
|
Superseded by new PR from fix/encryption-review-issues branch (includes merge with latest dev + admin config fix) |
Merged
99 tasks
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.
Why we need this PR?
Protect sensitive data stored in S3 (user files, session messages, attachments) with envelope encryption. Direct S3 bucket access only exposes ciphertext; decryption requires either a user's project API key or the admin master key.
Describe your solution
Implement AES-256-GCM envelope encryption with a two-tier key hierarchy:
enc-algometadata = passthrough)Implementation Tasks
internal/infra/crypto/) with HKDF, AES-256-GCM wrap/unwrapencryption.master_keyandencryption.enabledImpact Areas
Checklist
devbranch.🤖 Generated with Claude Code