Repository navigation
rgw: Add AES-256-GCM support for RGW server-side encryption - #67246
Conversation
Config Diff Tool Output+ added: rgw_crypt_sse_algorithm (rgw.yaml.in)
The above configuration changes are found in the PR. Please update the relevant release documentation if necessary. |
9011b5a to
9727391
Compare
9727391 to
20d6fef
Compare
|
Rebase with main |
|
I have a test which is not part of this pr that benchmarks the cbc & gcm encrypt/decrypt calls. On a Xeon E5-1650 these are the results I observed (in MB/s).
Accelerator: On a newer cpu (i7-14700KF), the results are below
Accelerator: |
|
Development of this work was inspired by #67052 and Kyle Bader's draft commit mmgaggle@68cf740. Input was also provided by Clyso (David Mohen). |
Reduce per-chunk overhead by hoisting accelerator resolution and EVP context creation out of the chunk loop, replacing ct_memeq with memcmp, linearizing input before the chunk loop, and eliminating unnecessary tag copies in the ISA-L path. Also rewrites IV derivation to use cached native arithmetic instead of a per-chunk byte-at-a-time loop, and aligns the output buffer to 64 bytes for optimal SIMD stores. Signed-off-by: Matthew N. Heler <[email protected]>
The bucket name isn't globally unique ie different tenants can have the same bucket name. Using bucket_id (which is globally unique and includes tenant context) prevent cross-tenant key collisions in the HMAC-SHA256 derivation. Signed-off-by: Matthew N. Heler <[email protected]>
Move randomness from the GCM IV into key derivation. Each object now gets a 32-byte random salt stored in RGW_ATTR_CRYPT_SALT, fed into HMAC-SHA256 alongside bucket_id and object name to produce a unique per-object key. The GCM IV is a deterministic counter from the chunk position, which is safe because the key never repeats. All GCM modes (SSE-C, SSE-KMS, SSE-S3, RGW-AUTO) now go through derive_object_key() before any encrypt or decrypt operation. Rename AES_GCM_NONCE_SIZE to AES_GCM_IV_SIZE across CryptoAccel backends (isa-l, openssl, qat) to reflect what it actually is. Signed-off-by: Matthew N. Heler <[email protected]>
Benchmark for measuring AES-256-CBC and AES-256-GCM throughput with hardware acceleration. Supports multi-threaded runs across various chunk sizes. Signed-off-by: Matthew N. Heler <[email protected]>
The SLO/DLO size check was converting encrypted size to plaintext via rgw_get_aead_decrypted_size(), which overestimates for multipart objects without CRYPT_PARTS. Use the stored CRYPT_ORIGINAL_SIZE attr instead, it's exact and already in the attrs. Signed-off-by: Matthew N. Heler <[email protected]>
Add stateless helpers that project plaintext byte ranges to on-disk byte ranges for compressed and encrypted objects. fixup_range() delegates to these for range computation. Signed-off-by: Matthew N. Heler <[email protected]>
Store the plaintext and encrypted block sizes at upload time so future cls prefetch ops can compute on-disk read ranges from xattrs without instantiating a cipher. Only written for size-expanding ciphers (GCM). CBC objects have no attr — plaintext and ciphertext sizes are identical. Signed-off-by: Matthew N. Heler <[email protected]>
Move the ISA-L GCM key cache to the heap with only a pointer in TLS. Simplify the IV cursor to use hi=part_number, lo=chunk_index instead of bit-packing both into a single field. Replace manual byte-shifting in AAD encoding with boost::endian. Signed-off-by: Matthew N. Heler <[email protected]>
|
@mattbenjamin teuthology passed for the rgw:crypt suite I additionally ran a local teuthology with the rgw:verify, rgw:lifecycle and rgw:dedup with an override to set to enable gcm |
| (recommended, provides authenticated encryption). Existing encrypted objects | ||
| are always decrypted using the algorithm specified in their metadata, | ||
| regardless of this setting. | ||
| default: aes-256-cbc |
There was a problem hiding this comment.
for the V release we should consider changing this default to gcm, assuming we've ironed out any bugs uncovered by testing in U
|
Please share regular updates on this |
that showed a ton of dns failures, i guess because of networking issues in the lab at the time, so a scheduled a rerun in https://pulpito.ceph.com/cbodley-2026-05-27_17:48:36-rgw-wip-73221-distro-default-trial/ that looks much better 👍 of the 4 failures, none are regressions from this pr:
|
|
Overall review: PASS/FAIL: Package audit for Ceph Crypto Review Package: RGW Checklist git fetch --depth=1 [x]: The package does not use /tmp in an unsafe way [x]: Upstream code has been examined for obvious keywords in commit [x]: Upstream project is not abandoned. Automated Coverage/Scans [x] Trufflehog Additional Checks AI Tooling: Errors found PR: #67246 Executive SummaryThis PR adds AES-256-GCM authenticated encryption support to Ceph's RADOS Gateway (RGW) for server-side encryption (SSE-C, SSE-KMS, SSE-S3, RGW-AUTO). The implementation is generally well-designed with strong cryptographic foundations, but contains several critical security issues that must be addressed before merging. Overall Risk Level: HIGH (due to critical issues identified) Critical Security Issues1. CRITICAL: Potential IV Reuse in Multipart UploadsLocation: src/rgw/rgw_crypt.cc - iv_cursor structure and IV derivation Issue:
Vulnerability: Attack Scenario:
Recommendation:
Severity: CRITICAL - Can lead to complete cryptographic break 2. CRITICAL: Missing Constant-Time Comparison for Authentication TagsLocation: src/rgw/rgw_crypt.cc - gcm_transform() decrypt path Issue: Vulnerability: Recommendation:
Severity: CRITICAL - Timing attacks can compromise authentication 3. HIGH: Insufficient Entropy in Salt GenerationLocation: src/rgw/rgw_crypt.cc - generate_salt() Issue: Recommendation:
Severity: HIGH - Weak salts can enable key recovery attacks 4. HIGH: Key Material Not Zeroized in All Error PathsLocation: Multiple locations in src/rgw/rgw_crypt.cc Issue: Recommendation:
Severity: HIGH - Memory disclosure can leak encryption keys High-Risk Issues5. HIGH: Potential Integer Overflow in Size CalculationsLocation: src/rgw/rgw_crypt.h - Size conversion functions Issue: Recommendation:
Severity: HIGH - Can lead to buffer overflows and memory corruption 6. HIGH: Missing Validation of Part NumbersLocation: src/rgw/rgw_crypt.cc - set_part_number() and multipart handling Issue: Recommendation:
Severity: HIGH - Invalid part numbers can cause IV collisions Medium-Risk Issues7. MEDIUM: Backward Compatibility Risk with Default CBCLocation: Configuration and mode selection Issue: Recommendation:
Severity: MEDIUM - Organizational security posture issue 8. MEDIUM: Insufficient AAD (Additional Authenticated Data)Location: src/rgw/rgw_crypt.cc - encode_chunk_aad() Issue: Recommendation:
Severity: MEDIUM - Defense-in-depth issue 9. MEDIUM: Potential Timing Leak in Key DerivationLocation: src/rgw/rgw_crypt.cc - derive_object_key() and derive_part_key() Issue: Recommendation:
Severity: MEDIUM - Side-channel information disclosure Low-Risk Issues10. LOW: Missing Rate Limiting for Decryption FailuresLocation: Decryption error handling Issue: Recommendation:
Severity: LOW - Operational security issue 11. LOW: Hardcoded Chunk SizeLocation: AES_256_GCM::CHUNK_SIZE = 4096 Issue: Recommendation:
Severity: LOW - Performance/flexibility issue Positive Security AspectsThe implementation demonstrates several strong security practices:
Recommendations SummaryMust Fix Before Merge (Critical)
Should Fix Before Merge (High)
Consider for Future (Medium/Low)
Testing Recommendations
ConclusionThis PR implements a cryptographically sound design for AES-256-GCM support in Ceph RGW, but contains critical security vulnerabilities that must be addressed:
The implementation shows strong security engineering practices overall, but the identified issues require immediate attention before this code can be safely deployed in production environments. Recommendation: DO NOT MERGE until critical issues 1-4 are resolved and verified through security testing. References
Summary |
| * - If object is moved/renamed at RADOS level → wrong key → decrypt fails | ||
| * | ||
| * Key derivation formula: | ||
| * ObjectKey = HMAC-SHA256(key, salt || domain || bucket_id || object) |
There was a problem hiding this comment.
@mheler Out of curiosity, is there a specific reason why the key derivation uses a custom HMAC-SHA256 mix instead of OpenSSL's native HKDF-Expand mode (EVP_KDF_HKDF_MODE_EXPAND_ONLY)(RFC5869)?
There was a problem hiding this comment.
@ggruner Mostly pragmatic, ceph::crypto (common/ceph_crypto.h) only exposes digest + HMACSHA256/512 classes as such there is no HKDF or EVP_KDF wrapper. If I went with OpenSSL's native approach it would bypass the crypto abstraction, and additionally change the derived keys.
Add GCM as an alternative to the existing CBC cipher for SSE-C, SSE-KMS, SSE-S3, and RGW-AUTO. GCM provides authenticated encryption, meaning it detects tampering during decryption rather than silently returning corrupted data.
The new rgw_crypt_sse_algorithm config option controls which cipher is used for new uploads. The default remains aes-256-cbc for backward compatibility with older RGW versions in mixed clusters. Once all nodes are upgraded, administrators can enable aes-256-gcm for new objects. Existing CBC-encrypted objects continue to decrypt correctly regardless of this setting.
GCM encrypts in 4KB chunks, each producing 4112 bytes of ciphertext (4096 plaintext + 16-byte authentication tag). This means encrypted objects are larger than their plaintext. To preserve correct behavior:
Each object gets a random 12-byte nonce stored in RGW_ATTR_CRYPT_NONCE. This nonce serves two purposes: it's combined with chunk indices to derive unique IVs for each encrypted block, and for SSE-C it's included in the key derivation to bind ciphertext to object identity. Moving encrypted data at the RADOS level causes decryption to fail rather than silently producing garbage.
Multipart uploads derive per-part keys using HMAC(ObjectKey, part_number) and include the S3 part number in IV derivation to guarantee unique IVs across parts. S3 allows non-contiguous part numbers (uploading parts 1, 3, 5 and skipping 2, 4), but the manifest only tracks a starting part number and assumes sequential numbering. To handle this, CompleteMultipartUpload stores the actual part numbers in RGW_ATTR_CRYPT_PART_NUMS. At decryption time, part numbers are read from this attribute rather than calculated from the manifest, ensuring correct key and IV derivation regardless of which parts were uploaded. For single-part reads (GET ?partNumber=N), the attribute is excluded and the requested part number is used directly.
The implementation uses generic AEAD abstractions (is_aead_mode(), aead_plaintext_to_encrypted_size(), etc.) so that adding other authenticated ciphers like ChaCha20-Poly1305 in the future requires only implementing the cipher itself — the size handling, range request translation, and multipart machinery will work unchanged.
The CryptoAccel plugin system has been extended to support GCM, following the same pattern established for CBC. ISA-L provides hardware-accelerated encryption with thread-local key caching, falling back to OpenSSL's EVP API when unavailable. QAT stubs return false since GCM requires different session setup than CBC; a note has been added to the QAT documentation clarifying this limitation.
Two new teuthology suites and unit tests exercise the GCM support: crypt-gcm runs all standard s3tests encryption tests with GCM instead of CBC, and multisite-crypt-gcm verifies that GCM-encrypted objects replicate correctly between zones with ETag verification enabled.
LLM-assisted development: Claude was used to help design and implement this feature. All generated code was thoroughly reviewed by the author and validated through manual, unit tests and teuthology integration suites.
Co-Authored-By: Claude Opus 4.5 [email protected]
Fixes: https://tracker.ceph.com/issues/73221
Contribution Guidelines
To sign and title your commits, please refer to Submitting Patches to Ceph.
If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.
When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an
xbetween the brackets:[x]. Spaces and capitalization matter when checking off items this way.Checklist
Show available Jenkins commands
jenkins test classic perfJenkins Job | Jenkins Job Definitionjenkins test crimson perfJenkins Job | Jenkins Job Definitionjenkins test signedJenkins Job | Jenkins Job Definitionjenkins test make checkJenkins Job | Jenkins Job Definitionjenkins test make check arm64Jenkins Job | Jenkins Job Definitionjenkins test submodulesJenkins Job | Jenkins Job Definitionjenkins test dashboardJenkins Job | Jenkins Job Definitionjenkins test dashboard cephadmJenkins Job | Jenkins Job Definitionjenkins test apiJenkins Job | Jenkins Job Definitionjenkins test docsReadTheDocs | Github Workflow Definitionjenkins test ceph-volume allJenkins Jobs | Jenkins Jobs Definitionjenkins test windowsJenkins Job | Jenkins Job Definitionjenkins test rook e2eJenkins Job | Jenkins Job DefinitionYou must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.