Skip to content

REST: Send x-amz-content-sha256 for SigV4 requests with a body - #4586

Merged
Fokko merged 1 commit into
apache:mainfrom
plusplusjiajia:fix-sigv4-content-sha256
Dec 3, 2026
Merged

Fokko merged 1 commit into
apache:mainfrom
plusplusjiajia:fix-sigv4-content-sha256

Conversation

@plusplusjiajia

Copy link
Copy Markdown
Member

Rationale for this change

Follow-up to #2827. The SigV4 adapter sets x-amz-content-sha256 only for requests without a body. Requests with a body (create namespace or table, commits, renames) go out without it, and REST catalogs that require the header reject them. For example, Alibaba Cloud DLF's Iceberg REST catalog answers 400 BadRequestException: no header x-amz-content-sha256, so with PyIceberg 0.12.0 every write against it fails while reads work. Iceberg Java sends the header on every request.

This PR sets the header on every request to the hex SHA256 of the body. botocore's SigV4Auth signs this header's value as the payload hash when the header is present, so the header and the signature stay consistent, as in standard SigV4 (S3 requires the same header with the same value).

This is a minimal subset of #3120. The canonical request is built exactly as before. The header uses hex, as standard SigV4 and the AWS reference implementation do, rather than the base64 value that Iceberg Java's flexible-checksum signer writes into it (discussed in #3120). The change is small, so it rebases easily onto the SigV4 extraction in #3410 / #4493 whichever lands first.

Are these changes tested?

Yes.

  • test_sigv4_sign_request_with_body now checks the exact header value, instead of only checking that it is not the empty-body hash.
  • New test_sigv4_content_sha256_header_is_the_signed_payload_hash checks, for bytes, str and empty bodies, that the header equals the payload hash botocore computes from the body and that it is the payload hash in the signed canonical request. Without the change to pyiceberg/catalog/rest/__init__.py, the bytes and str cases fail.
  • pytest tests/catalog/test_rest.py -m unit: 207 passed. prek run on the changed files (ruff, ruff-format, mypy, codespell) passes.
  • Manually, against Alibaba Cloud DLF's Iceberg REST catalog (VPC endpoint, ap-southeast-1): on main, create_namespace and create_table fail with no header x-amz-content-sha256. With this change, creating a namespace and a partitioned table, append, overwrite, delete, upsert, schema update, tags, time travel, property updates, rename and drop all succeed. Not tested against AWS Glue or S3 Tables.

Are there any user-facing changes?

SigV4-signed requests with a body now carry x-amz-content-sha256. A value set through the header.x-amz-content-sha256 catalog property is replaced by the computed hash, as it already was for requests without a body.

🤖 Generated with Claude Code

The SigV4 adapter sets x-amz-content-sha256 only for requests without a
body. Requests with a body (create namespace or table, commits, renames)
go out without it, and REST catalogs that require the header reject them.
Iceberg Java sends the header on every request.

Set it to the hex SHA256 of the body. botocore's SigV4Auth signs this
header's value as the payload hash when it is present, so the header and
the signature stay consistent, as in standard SigV4.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@Fokko Fokko left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @plusplusjiajia! Sending the payload hash on every SigV4 request matches what Java does, and the test asserting the header equals botocore's signed payload hash is a nice touch. Verified locally: 207 unit tests pass, ruff clean, and the header matches the canonical request's payload hash for bytes, str and empty bodies. 🚀

@Fokko
Fokko added this pull request to the merge queue Dec 2, 2026
@Fokko
Fokko removed this pull request from the merge queue due to a manual request Dec 2, 2026
@Fokko
Fokko added this pull request to the merge queue Dec 2, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Dec 2, 2026
@Fokko
Fokko added this pull request to the merge queue Dec 3, 2026
Merged via the queue into apache:main with commit e430f89 Dec 3, 2026
20 checks passed
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.

2 participants