This is an automated email from the ASF dual-hosted git repository.
Xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git
The following commit(s) were added to refs/heads/main by this push:
new adc816420a feat(services/s3): verify S3 Express writes with CRC32C
(#9267)
adc816420a is described below
commit adc816420af2b8b162a12d338238dce3b09d87a8
Author: Xuanwo <[email protected]>
AuthorDate: Fri Nov 27 20:19:39 2026 +0800
feat(services/s3): verify S3 Express writes with CRC32C (#9267)
* feat(services/s3): verify S3 Express writes with CRC32C
Advertise per-write checksums for session-signed directory buckets. Use
CRC32C for single PUT and full-object multipart verification, and reject other
checksum algorithms and presigned checksum intents.
* docs: describe S3 Express CRC32C writes in the capability catalog
---
core/services/s3/src/backend.rs | 50 ++++++++++++++++++++++++++++++++---
core/services/s3/src/core.rs | 9 +++++++
core/services/s3/src/docs.md | 15 ++++++++---
core/tests/behavior/async_write.rs | 30 ++++++++++++++++-----
dev/src/generate/capabilities_docs.rs | 8 ++++--
website/data/capabilities.json | 2 +-
6 files changed, 96 insertions(+), 18 deletions(-)
diff --git a/core/services/s3/src/backend.rs b/core/services/s3/src/backend.rs
index 802515621e..d10eb9b5cd 100644
--- a/core/services/s3/src/backend.rs
+++ b/core/services/s3/src/backend.rs
@@ -1236,9 +1236,10 @@ impl S3Builder {
// S3 CreateMultipartUpload does not support MD5 checksum_algorithm;
// only single-shot PutObject supports Content-MD5.
let s3_write_can_multi = !matches!(checksum_algorithm,
Some(ChecksumAlgorithm::Md5));
- // RustFS and Swift s3api verify each upload request independently.
- let s3_can_checksum = !is_s3_express
- && matches!(
+ let s3_can_checksum = if is_s3_express {
+ scheme == S3_SCHEME && !config.skip_signature
+ } else {
+ matches!(
scheme,
S3_SCHEME
| crate::CEPH_RGW_SCHEME
@@ -1247,7 +1248,8 @@ impl S3Builder {
| crate::RUSTFS_SCHEME
| crate::SEAWEEDFS_SCHEME
| crate::SWIFT_S3API_SCHEME
- );
+ )
+ };
let mut capability = Capability {
stat: true,
@@ -1659,6 +1661,12 @@ impl Service for S3Backend {
PresignOperation::Write(v) => {
let checksum = match v.checksum() {
None => None,
+ Some(_) if self.core.signer_spec.is_express => {
+ return Err(Error::new(
+ ErrorKind::Unsupported,
+ "S3 Express presigned writes do not support
checksum intents",
+ ));
+ }
Some(_) if self.core.info.scheme() == crate::RUSTFS_SCHEME
=> {
return Err(Error::new(
ErrorKind::Unsupported,
@@ -4407,6 +4415,8 @@ mod tests {
.expect("S3 Express backend must build");
let capability = backend.capability();
+ assert!(capability.write_with_checksum);
+ assert!(!capability.read_with_checksum);
assert!(!capability.stat_with_version);
assert!(!capability.read_with_version);
assert!(!capability.write_with_content_encoding);
@@ -4421,6 +4431,38 @@ mod tests {
assert!(!capability.list_with_deleted);
}
+ #[tokio::test]
+ async fn test_s3_express_rejects_unverified_checksum_writes() {
+ let transport =
S3ExpressMockTransport::new(CreateSessionOutcome::Success);
+ let op = s3_express_operator(transport.clone());
+
+ for intent in [
+ WriteChecksum::Algo(ChecksumAlgo::Crc64Nvme),
+ WriteChecksum::Expected(Checksum::new(ChecksumAlgo::Crc64Nvme, [0;
8])),
+ ] {
+ let error = op
+ .writer_with("target")
+ .checksum(intent)
+ .await
+ .expect_err("directory bucket writers must reject CRC64NVME");
+ assert_eq!(error.kind(), ErrorKind::Unsupported);
+ }
+
+ let error = op
+ .presign_write_options(
+ "target",
+ Duration::from_secs(60),
+ options::WriteOptions {
+ checksum: Some(Checksum::new(ChecksumAlgo::Crc32c, [0;
4]).into()),
+ ..Default::default()
+ },
+ )
+ .await
+ .expect_err("directory bucket presigns must reject checksum
intents");
+ assert_eq!(error.kind(), ErrorKind::Unsupported);
+ assert!(transport.requests().is_empty());
+ }
+
#[test]
fn test_invalid_aws_directory_bucket_configuration_is_rejected() {
let builder = S3Builder::default().bucket("example--usw2-az1--x-s3");
diff --git a/core/services/s3/src/core.rs b/core/services/s3/src/core.rs
index e12cf70838..41722d2075 100644
--- a/core/services/s3/src/core.rs
+++ b/core/services/s3/src/core.rs
@@ -282,6 +282,15 @@ impl S3Core {
&self,
requested: Option<ChecksumAlgo>,
) -> Result<ChecksumAlgorithm> {
+ if self.signer_spec.is_express {
+ return match requested {
+ None | Some(ChecksumAlgo::Crc32c) =>
Ok(ChecksumAlgorithm::Crc32c),
+ Some(algo) => Err(Error::new(
+ ErrorKind::Unsupported,
+ format!("S3 Express does not support a full-object
{algo:?} checksum"),
+ )),
+ };
+ }
match (self.info.scheme(), requested) {
(_, Some(ChecksumAlgo::Crc32c)) | (crate::CEPH_RGW_SCHEME, None)
=> {
Ok(ChecksumAlgorithm::Crc32c)
diff --git a/core/services/s3/src/docs.md b/core/services/s3/src/docs.md
index 6f21b099c6..1f768d8434 100644
--- a/core/services/s3/src/docs.md
+++ b/core/services/s3/src/docs.md
@@ -63,10 +63,17 @@ On general-purpose AWS S3 buckets, use
[`opendal_core::WriteChecksum::Any`] or
CRC-64/NVME checksum. Explicit algorithm and expected checksum requests
support CRC-32C and CRC-64/NVME. The write returns the confirmed checksum in
[`opendal_core::Metadata::checksum`] for both a single PUT and multipart
upload.
-Append and S3 Express One Zone reject per-write checksum intents. The
-MinIO, SeaweedFS, and Ceph RADOS Gateway presets also accept write checksum
-intents. See each preset's documentation for its supported algorithms and
-server behavior.
+
+On S3 Express One Zone directory buckets, signed writes use full-object
+CRC-32C for `Any` and `Fast`. Explicit algorithm and expected checksum requests
+also support CRC-32C. The write returns the confirmed checksum for both a
+single PUT and multipart upload. Directory buckets reject other requested
+algorithms with [`opendal_core::ErrorKind::Unsupported`].
+
+OpenDAL returns `Unsupported` for checksum intents on append writes and on
+S3 Express presigned writes. The MinIO, SeaweedFS, and Ceph RADOS Gateway
+presets also accept write checksum intents. See each preset's documentation
+for its supported algorithms and server behavior.
A per-write intent takes precedence over
[`crate::S3Config::checksum_algorithm`]
for HTTP checksum headers. The configured algorithm still disables native
writer
diff --git a/core/tests/behavior/async_write.rs
b/core/tests/behavior/async_write.rs
index d219e1b753..2f763b4a0f 100644
--- a/core/tests/behavior/async_write.rs
+++ b/core/tests/behavior/async_write.rs
@@ -1416,8 +1416,24 @@ fn s3_crc_checksum(algo: ChecksumAlgo, content: &[u8])
-> Checksum {
}
}
-fn s3_crc_checksums(content: &[u8]) -> [Checksum; 2] {
- [ChecksumAlgo::Crc32c, ChecksumAlgo::Crc64Nvme].map(|algo|
s3_crc_checksum(algo, content))
+fn s3_default_write_checksum(op: &Operator) -> ChecksumAlgo {
+ let info = op.info();
+ if info.scheme() == "s3"
+ && info.name().ends_with("--x-s3")
+ && !info.capability().stat_with_version
+ {
+ ChecksumAlgo::Crc32c
+ } else {
+ ChecksumAlgo::Crc64Nvme
+ }
+}
+
+fn s3_crc_checksums(op: &Operator, content: &[u8]) -> Vec<Checksum> {
+ let mut checksums = vec![s3_crc_checksum(ChecksumAlgo::Crc32c, content)];
+ if s3_default_write_checksum(op) == ChecksumAlgo::Crc64Nvme {
+ checksums.push(s3_crc_checksum(ChecksumAlgo::Crc64Nvme, content));
+ }
+ checksums
}
/// Return a checksum of the same algorithm and length that does not match.
@@ -1481,7 +1497,7 @@ pub async fn test_write_with_any_checksum(op: Operator)
-> Result<()> {
pub async fn test_write_with_checksum(op: Operator) -> Result<()> {
let (_, content, _) = TEST_FIXTURE.new_file(op.clone());
- for checksum in s3_crc_checksums(&content) {
+ for checksum in s3_crc_checksums(&op, &content) {
let path = TEST_FIXTURE.new_file_path();
let meta = op
.write_with(&path, content.clone())
@@ -1564,7 +1580,7 @@ async fn test_minio_write_without_crc64nvme_receipt(op:
Operator) -> Result<()>
pub async fn test_write_with_checksum_mismatch(op: Operator) -> Result<()> {
let (_, content, _) = TEST_FIXTURE.new_file(op.clone());
- for checksum in s3_crc_checksums(&content) {
+ for checksum in s3_crc_checksums(&op, &content) {
let (op, attempts) = observe_s3_checksum_write(&op,
ServiceOperation("PutObject"));
let path = TEST_FIXTURE.new_file_path();
let err = op
@@ -1682,7 +1698,7 @@ async fn test_s3_writer_with_checksum_intent(
pub async fn test_writer_with_checksum_multipart(op: Operator) -> Result<()> {
let (chunk, content) = multipart_checksum_content(&op);
- for checksum in s3_crc_checksums(&content) {
+ for checksum in s3_crc_checksums(&op, &content) {
let path = TEST_FIXTURE.new_file_path();
let mut writer = op
.writer_with(&path)
@@ -1719,7 +1735,7 @@ pub async fn test_writer_with_any_checksum_multipart(op:
Operator) -> Result<()>
let meta = writer.close().await?;
assert_eq!(
meta.checksum(),
- Some(s3_crc_checksum(ChecksumAlgo::Crc64Nvme, &content))
+ Some(s3_crc_checksum(s3_default_write_checksum(&op), &content))
);
assert_eq!(op.read(&path).await?.to_bytes(), Bytes::from(content));
Ok(())
@@ -1729,7 +1745,7 @@ pub async fn test_writer_with_any_checksum_multipart(op:
Operator) -> Result<()>
pub async fn test_writer_with_checksum_multipart_mismatch(op: Operator) ->
Result<()> {
let (chunk, content) = multipart_checksum_content(&op);
- for checksum in s3_crc_checksums(&content) {
+ for checksum in s3_crc_checksums(&op, &content) {
let (op, attempts) =
observe_s3_checksum_write(&op,
ServiceOperation("CompleteMultipartUpload"));
let path = TEST_FIXTURE.new_file_path();
diff --git a/dev/src/generate/capabilities_docs.rs
b/dev/src/generate/capabilities_docs.rs
index 9e498122d4..46df72343f 100644
--- a/dev/src/generate/capabilities_docs.rs
+++ b/dev/src/generate/capabilities_docs.rs
@@ -734,7 +734,10 @@ fn describe_bool_condition(expr: &Expr, rel_path: &str) ->
Result<String> {
);
}
if ident == "s3_can_checksum" {
- return Ok("Standard S3 buckets (not S3 Express One
Zone)".to_string());
+ return Ok(
+ "General-purpose S3 buckets, or signed non-append
CRC32C writes to S3 Express One Zone directory buckets"
+ .to_string(),
+ );
}
if let Some(rest) = ident.strip_prefix("has_") {
return Ok(format!("Requires `{rest}`"));
@@ -1173,7 +1176,8 @@ mod tests {
assert_eq!(
s3.native.get("write_with_checksum"),
Some(&NativeBoolDoc::Conditional(
- "Standard S3 buckets (not S3 Express One Zone)".to_string()
+ "General-purpose S3 buckets, or signed non-append CRC32C
writes to S3 Express One Zone directory buckets"
+ .to_string()
))
);
for scheme in [
diff --git a/website/data/capabilities.json b/website/data/capabilities.json
index bcaf309987..e0288fee79 100644
--- a/website/data/capabilities.json
+++ b/website/data/capabilities.json
@@ -3789,7 +3789,7 @@
"write_can_empty": true,
"write_can_multi": "When `checksum_algorithm` is not `md5`",
"write_with_cache_control": true,
- "write_with_checksum": "Standard S3 buckets (not S3 Express One Zone)",
+ "write_with_checksum": "General-purpose S3 buckets, or signed
non-append CRC32C writes to S3 Express One Zone directory buckets",
"write_with_content_disposition": true,
"write_with_content_encoding": "Standard S3 buckets (not S3 Express
One Zone)",
"write_with_content_language": true,