plusplusjiajia opened a new pull request, #4586:
URL: https://github.com/apache/iceberg-python/pull/4586

   # 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](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to