Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.
Python awsaws-emulatoraws-localaws-sdkdevtoolsdockerdynamodbec2emulatorlambdalocalstacklocalstack-alternativeministackmock-awsopen-sourcepythons3sqsterraform
fix(s3): restore the SSE-C checks and echoes still missing after #1444 (#1449)
iot-rocket0c389e32eb79
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 0155cb7b..f214fc46 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -21,6 +21,7 @@ Versioning follows [Semantic Versioning](https://semver.org/).- **CloudWatch — extended-statistic percentiles are computed instead of aliased to `Average`** — `GetMetricData` and alarm evaluation returned `Average` for any `pNN` extended statistic regardless of the percentile requested (`_stat_value` had a stub, and alarm evaluation read only `Statistic`, never `ExtendedStatistic`). Percentiles are now computed by linear interpolation over the period's samples on both paths, and a percentile alarm's `StateReason` reports the actual statistic (e.g. `p95`) instead of `Average`. Contributed by @MGSousa.- **S3 — presigned SigV4 URLs verify for virtual-hosted addressing and temporary credentials** — two bugs made valid presigned `GET`/`PUT` URLs fail `403 SignatureDoesNotMatch`: a virtual-hosted (`{bucket}.host`) URL was rewritten to path-style before the signature was recomputed, so it no longer matched the bucket-less URI the client signed; and a URL signed with STS temporary credentials was always verified against the static server secret, never the unique secret STS issued. Verification now runs against the original signed URI, and STS records each issued secret so the verifier resolves the one a credential actually signed with (long-term keys still fall back to `AWS_SECRET_ACCESS_KEY`). Tampered and wrong-secret URLs are still rejected. Reported by @mayankgupta57.- **Step Functions — `arn:aws:states:::events:putEvents` actually publishes the event** — the optimized EventBridge integration fell through to the task passthrough, so the state reported `SUCCEEDED` while nothing reached any rule target. It now calls EventBridge `PutEvents` and returns its response (`Entries` / `FailedEntryCount`). Reported by @iwasakar.+- **S3 — the SSE-C checks and echoes still missing after the #1444 restoration** — #1444 brought back most of the SSE wiring that #1439's merge resolution lost, but four call sites stayed unwired, all on paths no test pinned: `UploadPartCopy` accepted a part for an SSE-C upload without the create-time key and read an SSE-C copy source without the source key, and neither the `UploadPartCopy` nor the `CompleteMultipartUpload` response echoed the stored algorithm. All three now behave as #1439 originally wrote them. Contributed by @iot-rocket.- **Aurora DSQL — `SELECT ... FOR UPDATE` is no longer refused for its predicate** — strict mode enforced a rule Aurora DSQL does not (any more): a locking read had to be a single table with an equality on every primary key column, or it was rejected with `0A000` "locking clause such as FOR UPDATE can be applied only on tables with equality predicates on the key". The check compared the WHERE clause's column against the key name as raw SQL text, so `WHERE "id" = $1` did not match key column `id` — and every mainstream ORM (Drizzle, Prisma, TypeORM, SQLAlchemy) quotes its identifiers, so in practice every locking read from an ORM failed, with a message that blamed the user's schema. Measured against a live cluster (eu-central-1, 2026-08-18, `server_version` 16.15), DSQL restricts the lock *strength*, not the predicate: `FOR UPDATE` locks whatever the query selects — no `WHERE` clause, a non-key column, an inequality, `IN`/`OR`, a join, or a table with no primary key all succeed, as do `NOWAIT`, `SKIP LOCKED` and `OF` — while `FOR NO KEY UPDATE`, `FOR SHARE` and `FOR KEY SHARE` are refused with `0A000` "locking clauses other than FOR UPDATE/FOR KEY SHARE are not supported", inside a CTE or subquery included. The predicate rule is gone and the lock-strength rule takes its place, so the emulator stops failing correct code and starts failing the code DSQL actually fails. The new rule is token-based (`FOR SHARE` inside a string literal is text, not a clause) and needs no catalog probe, so a locking read no longer costs a round-trip before it is forwarded.- **Aurora DSQL — quoted identifiers are normalized the way the server stores them** — `ALTER TABLE ... DROP COLUMN` compared the column against the primary key case-insensitively after stripping quotes, so `DROP COLUMN "ID"` was read as key column `id` and refused, while the primary-key probe dropped the quotes from its relation name — `"myschema".t` became `myschema".t` and resolved to nothing, and a table created as `"MyTable"` case-folded to `mytable` and was not found, silently disabling the rule. Identifiers are now folded as PostgreSQL folds them (bare to lower case, quoted verbatim, `""` unescaped) and the relation is requoted part by part before the lookup, so schema-qualified and mixed-case names resolve.- **CloudFormation — `AWS::IoT::Policy` updates apply instead of rolling the stack back** — the type had a create and a delete but no update handler, so a stack update fell through to create, hit `ResourceAlreadyExistsException` on the policy it had provisioned itself, and rolled back with the document unchanged: an IoT policy could be deployed once and never edited again. A changed `PolicyDocument` is now a no-interruption update stored as a new policy version and made the default, so `Ref` keeps naming the same policy and `GetPolicy` returns the new document; a changed `PolicyName` is a replacement, creating the policy under the new name and removing the old one. Because IoT caps a policy at five versions, the update prunes the oldest non-default versions before storing a new document, as the CloudFormation handler does on AWS.diff --git a/ministack/services/s3.py b/ministack/services/s3.pyindex 4d3cca20..03471bb1 100644--- a/ministack/services/s3.py+++ b/ministack/services/s3.py@@ -5119,6 +5119,10 @@ def _upload_part_copy(bucket_name: str, dest_key: str, query_params: dict, headeif upload_id not in _multipart_uploads:return _error("NoSuchUpload", "The specified multipart upload does not exist.", 404)+ sse_part_err = _check_sse_c_part(headers, _multipart_uploads[upload_id])+ if sse_part_err is not None:+ return sse_part_err+# Split the raw header at "?" before percent-decoding, exactly as# CopyObject does: a key containing "?versionId" arrives encoded and must# stay part of the key, while a real versionId qualifier is a bare "?".@@ -5161,6 +5165,13 @@ def _upload_part_copy(bucket_name: str, dest_key: str, query_params: dict, headesrc_obj = src_bucket["objects"][src_key]src_version_id = src_obj.get("version_id")src_body = _read_body(src_bucket_name, src_key, src_obj)+ ventry = src_obj++ # An SSE-C source must be addressed with its create-time key, whichever+ # version the range is copied from.+ sse_src_err = _check_sse_c_copy_source(headers, ventry)+ if sse_src_err is not None:+ return sse_src_err# Handle x-amz-copy-source-rangecopy_range = headers.get("x-amz-copy-source-range", "")@@ -5204,7 +5215,8 @@ def _upload_part_copy(bucket_name: str, dest_key: str, query_params: dict, headeroot = Element("CopyPartResult", xmlns=S3_NS)SubElement(root, "ETag").text = etagSubElement(root, "LastModified").text = now_iso()- resp_headers = {"Content-Type": "application/xml"}+ resp_headers = {"Content-Type": "application/xml",+ **_stored_sse_headers(_multipart_uploads[upload_id])}if src_version_id:# AWS echoes the copied source version on a versioned source.resp_headers["x-amz-copy-source-version-id"] = src_version_id@@ -5339,6 +5351,7 @@ def _complete_multipart_upload()resp_headers = {"Content-Type": "application/xml"}+ resp_headers.update(_stored_sse_headers(obj))version_id = _record_object_version(bucket_name, key, prior_obj, obj, combined)if version_id:resp_headers["x-amz-version-id"] = version_iddiff --git a/tests/test_s3.py b/tests/test_s3.pyindex 475e9641..eaa1191a 100644--- a/tests/test_s3.py+++ b/tests/test_s3.py@@ -2800,6 +2800,56 @@ def test_s3_sse_c_multipart(s3):s3.get_object(Bucket=bucket, Key="m")+def test_s3_sse_c_upload_part_copy_checks_both_keys_and_echoes(s3):+ """UploadPartCopy on an SSE-C upload must present the create-time key, and+ an SSE-C copy source must be addressed with its own key; the response+ echoes the stored algorithm, as the wire shape models."""+ import uuid as _u+ bucket = f"sse-c-upc-{_u.uuid4().hex[:8]}"+ s3.create_bucket(Bucket=bucket)+ s3.put_object(Bucket=bucket, Key="src", Body=b"source-bytes", **_SSE_C_2)+ mpu = s3.create_multipart_upload(Bucket=bucket, Key="m", **_SSE_C)+ src = {"Bucket": bucket, "Key": "src"}+ src_key = {"CopySourceSSECustomerAlgorithm": "AES256",+ "CopySourceSSECustomerKey": _SSE_C_KEY2,+ "CopySourceSSECustomerKeyMD5": _SSE_C_MD5_2}+ # No part key: refused before the copy source is even read.+ with pytest.raises(ClientError) as exc:+ s3.upload_part_copy(Bucket=bucket, Key="m", UploadId=mpu["UploadId"],+ PartNumber=1, CopySource=src, **src_key)+ assert exc.value.response["ResponseMetadata"]["HTTPStatusCode"] == 400+ # Part key present, source key missing: the SSE-C source is unreadable.+ with pytest.raises(ClientError) as exc:+ s3.upload_part_copy(Bucket=bucket, Key="m", UploadId=mpu["UploadId"],+ PartNumber=1, CopySource=src, **_SSE_C)+ assert exc.value.response["ResponseMetadata"]["HTTPStatusCode"] == 400+ # Both keys: the copy succeeds and the response echoes the algorithm.+ resp = s3.upload_part_copy(Bucket=bucket, Key="m", UploadId=mpu["UploadId"],+ PartNumber=1, CopySource=src, **_SSE_C, **src_key)+ assert resp["SSECustomerAlgorithm"] == "AES256"+ assert resp["SSECustomerKeyMD5"] == _SSE_C_MD5+ parts = {"Parts": [{"ETag": resp["CopyPartResult"]["ETag"], "PartNumber": 1}]}+ s3.complete_multipart_upload(Bucket=bucket, Key="m", UploadId=mpu["UploadId"],+ MultipartUpload=parts, **_SSE_C)+ assert s3.get_object(Bucket=bucket, Key="m", **_SSE_C)["Body"].read() == b"source-bytes"+++def test_s3_sse_multipart_complete_echoes_the_algorithm(s3):+ """CompleteMultipartUpload echoes the stored SSE algorithm on its+ response, not only on later GET/HEAD."""+ import uuid as _u+ bucket = f"sse-mpu-echo-{_u.uuid4().hex[:8]}"+ s3.create_bucket(Bucket=bucket)+ mpu = s3.create_multipart_upload(Bucket=bucket, Key="m",+ ServerSideEncryption="AES256")+ part = s3.upload_part(Bucket=bucket, Key="m", UploadId=mpu["UploadId"],+ PartNumber=1, Body=b"bytes")+ resp = s3.complete_multipart_upload(+ Bucket=bucket, Key="m", UploadId=mpu["UploadId"],+ MultipartUpload={"Parts": [{"ETag": part["ETag"], "PartNumber": 1}]})+ assert resp["ServerSideEncryption"] == "AES256"++def test_s3_sse_copy_semantics(s3):"""The destination's encryption comes from the copy request, never thesource: an SSE-C source needs its key as copy-source parameters (400