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
prerelease2
Nahuel99003e4870ef20c
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex c8137392..1aae7509 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -21,7 +21,7 @@ Versioning follows [Semantic Versioning](https://semver.org/).- **IoT — `DescribeCertificate` reports `certificateMode`** — the field was missing from the description. It is now `SNI_ONLY` for a certificate registered with `RegisterCertificateWithoutCA` and `DEFAULT` for the others, as AWS reports it. Contributed by @iot-rocket.### Fixed-- **S3 — cross-account replication resolves the destination account and enforces the destination bucket policy** — `PutBucketReplication` dropped `Destination.Account` and `AccessControlTranslation`, and the replica write resolved the destination bucket only in the caller's account, so a destination owned by another account stamped every object `FAILED`. The destination now resolves inside the account `Destination.Account` names, the replica (object, versions, tags, annotations, on-disk files) lands in that account's scope, and a cross-account destination requires its bucket policy to grant the rule's `Role` `s3:ReplicateObject` — plus `s3:ObjectOwnerOverrideToBucketOwner` when `AccessControlTranslation` is present — or the source reports `FAILED`, as AWS documents. `PutBucketReplication`/`GetBucketReplication` now parse and round-trip `Filter`, `Priority`, `DeleteMarkerReplication`, `Destination.Account` and `AccessControlTranslation`, and the destination-versioning check at configuration time sees buckets in any account. Contributed by @pingedbrain.+- **S3 — cross-account replication** — `PutBucketReplication` dropped `Destination.Account` and `AccessControlTranslation`, and the replica write looked the destination bucket up only in the caller's account, so a destination owned by another account stamped every object `FAILED`. The destination is now found by its bucket name in any account and the replica (object, versions, tags, annotations, on-disk files) lands in the owner's scope. A cross-account destination requires its bucket policy to grant the rule's `Role` `s3:ReplicateObject`, plus `s3:ObjectOwnerOverrideToBucketOwner` when `AccessControlTranslation` is set and the destination is not `BucketOwnerEnforced`; otherwise the source reports `FAILED`. `PutBucketReplication` / `GetBucketReplication` round-trip `Filter` (`Prefix`, `Tag`, `And`), `Priority`, `DeleteMarkerReplication`, `Destination.Account` and `AccessControlTranslation`, and the destination-versioning check at configuration time sees buckets in any account. Contributed by @pingedbrain.- **RDS Data API — MySQL `generatedFields`** — `ExecuteStatement` and `BatchExecuteStatement` always answered `generatedFields: []`, so an `INSERT` into an `AUTO_INCREMENT` table gave no way to read the new id. On the MySQL engines it now holds the id the server assigned (`[{"longValue": <id>}]`), or `[]` when none was assigned; `BatchExecuteStatement` reports it in each parameter set's update result. Aurora PostgreSQL still returns `[]`: the API reference says it does not support `generatedFields` and points to `RETURNING`.- **SSM — `PutParameter` validates `Type`, reserved names and `Tags` with `Overwrite`** — three requests that AWS refuses were accepted. Creating a parameter without `Type` now fails with `ValidationException` ("A parameter type is required when you create a parameter."), and an overwrite without `Type` keeps the stored type instead of resetting it to `String`, so a `SecureString` no longer turns into plaintext. Names whose first characters (after an optional leading `/`) are `aws` or `ssm`, in any case, are refused: `/aws...` with `AccessDeniedException`, everything else with `ValidationException`, all HTTP 400. `Tags` together with `Overwrite=true` fails with `ValidationException` whether or not the parameter exists; an empty `Tags` list is accepted. Matches AWS observed in us-east-1 on 2026-10-06. Reported by @jin-gizmo.- **IoT — `https://<endpointAddress>` verifies under `USE_SSL=1`** — `DescribeEndpoint` hands out `<prefix>-ats.iot.<region>.<MINISTACK_HOST>` and `<prefix>.credentials.iot.<region>.<MINISTACK_HOST>`, which SDKs dial over HTTPS as on AWS, but the generated gateway certificate did not name them, so the handshake failed hostname verification. The certificate now carries `*.iot.<region>.<MINISTACK_HOST>` and `*.credentials.iot.<region>.<MINISTACK_HOST>` for every region, and a cached certificate without them is regenerated. Contributed by @iot-rocket.diff --git a/ministack/services/s3.py b/ministack/services/s3.pyindex 41fb78e0..ead12378 100644--- a/ministack/services/s3.py+++ b/ministack/services/s3.py@@ -4607,7 +4607,8 @@ def _replication_rule_for(bucket_name: str, key: str) -> tuple[dict | None, str]continueprefix = rule.get("Prefix")if prefix is None:- prefix = (rule.get("Filter") or {}).get("Prefix", "")+ rule_filter = rule.get("Filter") or {}+ prefix = rule_filter.get("Prefix") or (rule_filter.get("And") or {}).get("Prefix") or ""if key.startswith(prefix):return rule, config.get("Role", "")return None, ""@@ -4632,14 +4633,22 @@ def _in_account(account_id: str):set_request_account_id(previous)+def _bucket_owner_enforced(bucket: dict) -> bool:+ stored = bucket.get("_ownership_controls")+ if stored:+ return "BucketOwnerEnforced" in stored+ return not bucket.get("_ownership_controls_deleted")++def _replication_destination_allows(dest_account: str, dest_name: str, key: str,- role: str, dest: dict) -> bool:+ role: str, dest: dict, dest_bucket: dict) -> bool:"""Whether the destination bucket policy grants the replication role.Cross-account replication requires the destination owner to allow thesource's replication role ``s3:ReplicateObject`` on the destinationobjects, plus ``s3:ObjectOwnerOverrideToBucketOwner`` when the rule- carries ``AccessControlTranslation``. A missing or denying policy stamps+ carries ``AccessControlTranslation`` and the destination is not+ ``BucketOwnerEnforced``. A missing or denying policy stampsthe source FAILED, as AWS reports a replica it could not write."""policy = _bucket_policies.get_scoped(dest_account, None, dest_name)@@ -4660,7 +4669,7 @@ def _replication_destination_allows(dest_account: str, dest_name: str, key: str,)if evaluate_resource_policy(policy, ctx).decision != "Allow":return False- if dest.get("AccessControlTranslation"):+ if dest.get("AccessControlTranslation") and not _bucket_owner_enforced(dest_bucket):ctx = EvalContext(principal_arn=role,principal_type="AssumedRole",@@ -4695,16 +4704,15 @@ def _maybe_replicate(bucket_name: str, key: str, obj: dict, data) -> None:dest_ref = dest.get("Bucket") or ""dest_name = dest_ref.split(":::")[-1] if ":::" in dest_ref else dest_refsource_account = get_account_id()- # AWS resolves the destination inside the account the rule names; a rule- # without Destination.Account targets a destination the source owns.- dest_account = dest.get("Account") or source_account- dest_bucket = _buckets.get_scoped(dest_account, None, dest_name)+ # The name identifies the bucket; Destination.Account only names the owner for AccessControlTranslation.+ dest_account = _bucket_owner_account(dest_name)+ dest_bucket = _buckets.get_scoped(dest_account, None, dest_name) if dest_account else Noneif (dest_bucket is None or dest_name == bucket_nameor _bucket_versioning.get_scoped(dest_account, None, dest_name) != "Enabled"):obj["replication_status"] = "FAILED"returnif (dest_account != source_account and not _replication_destination_allows(- dest_account, dest_name, key, role, dest)):+ dest_account, dest_name, key, role, dest, dest_bucket)):obj["replication_status"] = "FAILED"return@@ -6307,6 +6315,52 @@ def _put_object_acl(bucket_name: str, key: str, body: bytes, headers: dict, quer# ---------------------------------------------------------------------------+def _replication_tag(tag_el) -> dict:+ key_el, value_el = _find_xml_tag(tag_el, "Key"), _find_xml_tag(tag_el, "Value")+ return {"Key": key_el.text if key_el is not None and key_el.text else "",+ "Value": value_el.text if value_el is not None and value_el.text else ""}+++def _parse_replication_filter(filter_el) -> dict:+ """A ReplicationRuleFilter: Prefix, Tag, or And (Prefix and Tags)."""+ out: dict = {}+ prefix_el = _find_xml_tag(filter_el, "Prefix")+ if prefix_el is not None:+ out["Prefix"] = prefix_el.text or ""+ tag_el = _find_xml_tag(filter_el, "Tag")+ if tag_el is not None:+ out["Tag"] = _replication_tag(tag_el)+ and_el = _find_xml_tag(filter_el, "And")+ if and_el is not None:+ and_op: dict = {}+ and_prefix = _find_xml_tag(and_el, "Prefix")+ if and_prefix is not None:+ and_op["Prefix"] = and_prefix.text or ""+ tags = [_replication_tag(t) for t in and_el if t.tag.split("}")[-1] == "Tag"]+ if tags:+ and_op["Tags"] = tags+ out["And"] = and_op+ return out+++def _replication_filter_xml(filter_el, rule_filter: dict) -> None:+ def _tag(parent, tag):+ tag_el = SubElement(parent, "Tag")+ SubElement(tag_el, "Key").text = tag.get("Key", "")+ SubElement(tag_el, "Value").text = tag.get("Value", "")++ if "Prefix" in rule_filter:+ SubElement(filter_el, "Prefix").text = rule_filter["Prefix"]+ if "Tag" in rule_filter:+ _tag(filter_el, rule_filter["Tag"])+ if "And" in rule_filter:+ and_el = SubElement(filter_el, "And")+ if "Prefix" in rule_filter["And"]:+ SubElement(and_el, "Prefix").text = rule_filter["And"]["Prefix"]+ for tag in rule_filter["And"].get("Tags", []):+ _tag(and_el, tag)++def _put_bucket_replication(bucket_name: str, body: bytes):bucket = _ensure_bucket(bucket_name)if bucket is None:@@ -6341,10 +6395,7 @@ def _put_bucket_replication(bucket_name: str, body: bytes):rule["Prefix"] = prefix_el.textfilter_el = _find_xml_tag(rule_el, "Filter")if filter_el is not None:- fprefix = _find_xml_tag(filter_el, "Prefix")- rule["Filter"] = {- "Prefix": fprefix.text if fprefix is not None and fprefix.text is not None else ""- }+ rule["Filter"] = _parse_replication_filter(filter_el)priority_el = _find_xml_tag(rule_el, "Priority")if priority_el is not None and priority_el.text and priority_el.text.isdigit():rule["Priority"] = int(priority_el.text)@@ -6418,8 +6469,7 @@ def _get_bucket_replication(bucket_name: str):if "Prefix" in rule:SubElement(rule_el, "Prefix").text = rule["Prefix"]if "Filter" in rule:- filter_el = SubElement(rule_el, "Filter")- SubElement(filter_el, "Prefix").text = (rule["Filter"] or {}).get("Prefix", "")+ _replication_filter_xml(SubElement(rule_el, "Filter"), rule["Filter"] or {})if "DeleteMarkerReplication" in rule:dmr_el = SubElement(rule_el, "DeleteMarkerReplication")SubElement(dmr_el, "Status").text = (rule["DeleteMarkerReplication"] or {}).get(diff --git a/tests/test_s3.py b/tests/test_s3.pyindex fc235976..d59cbab6 100644--- a/tests/test_s3.py+++ b/tests/test_s3.py@@ -7575,16 +7575,20 @@ def _dest_policy(dest_bucket, actions=("s3:ReplicateObject", "s3:ObjectOwnerOver})-def _cross_account_pair(slug, policy="default", dest_account=_DEST_ACCOUNT):+def _cross_account_pair(slug, policy="default", translate=True, ownership=None):"""Source bucket in _SOURCE_ACCOUNT, destination bucket in _DEST_ACCOUNT,- one Enabled rule naming Destination.Account. ``policy`` selects the- destination bucket policy: ``"default"`` grants the replication role,- ``None`` leaves the bucket without a policy, anything else is applied- verbatim."""+ one Enabled rule (with Account and AccessControlTranslation unless+ ``translate`` is False). ``policy`` selects the destination bucket policy:+ ``"default"`` grants the replication role, ``None`` leaves the bucket+ without a policy, anything else is applied verbatim. ``ownership`` sets+ the destination's Object Ownership."""src_client, dst_client = _s3_account(_SOURCE_ACCOUNT), _s3_account(_DEST_ACCOUNT)src, dst = f"qa-xrepl-src-{slug}", f"qa-xrepl-dst-{slug}"dst_client.create_bucket(Bucket=dst)dst_client.put_bucket_versioning(Bucket=dst, VersioningConfiguration={"Status": "Enabled"})+ if ownership:+ dst_client.put_bucket_ownership_controls(+ Bucket=dst, OwnershipControls={"Rules": [{"ObjectOwnership": ownership}]})if policy == "default":dst_client.put_bucket_policy(Bucket=dst, Policy=_dest_policy(dst))elif policy is not None:@@ -7598,11 +7602,10 @@ def _cross_account_pair(slug, policy="default", dest_account=_DEST_ACCOUNT):"Rules": [{"ID": "r1", "Status": "Enabled", "Filter": {"Prefix": ""},"DeleteMarkerReplication": {"Status": "Disabled"},- "Destination": {- "Bucket": f"arn:aws:s3:::{dst}",- "Account": dest_account,+ "Destination": {"Bucket": f"arn:aws:s3:::{dst}"} | ({+ "Account": _DEST_ACCOUNT,"AccessControlTranslation": {"Owner": "Destination"},- },+ } if translate else {}),}],},)@@ -7652,9 +7655,9 @@ def test_s3_replication_cross_account_requires_destination_policy(s3):def test_s3_replication_cross_account_requires_owner_override_grant(s3):"""AccessControlTranslation needs s3:ObjectOwnerOverrideToBucketOwner in- the destination policy; without it replication fails."""+ the destination policy unless the destination is BucketOwnerEnforced."""partial = _dest_policy("qa-xrepl-dst-own", actions=("s3:ReplicateObject",))- src_client, dst_client, src, dst = _cross_account_pair("own", policy=partial)+ src_client, dst_client, src, dst = _cross_account_pair("own", policy=partial, ownership="ObjectWriter")try:src_client.put_object(Bucket=src, Key="telemetry/k", Body=b"x")assert src_client.head_object(Bucket=src, Key="telemetry/k")["ReplicationStatus"] == "FAILED"@@ -7663,19 +7666,44 @@ def test_s3_replication_cross_account_requires_owner_override_grant(s3):_purge_foreign(dst_client, dst)-def test_s3_replication_cross_account_unknown_destination_account(s3):- """A Destination.Account that owns no such bucket resolves to nothing —- the replica cannot be written and the source reports FAILED."""- src_client, dst_client, src, dst = _cross_account_pair(- "ghost", dest_account="555555555555")+def test_s3_replication_cross_account_bucket_owner_enforced_needs_no_override_grant(s3):+ """BucketOwnerEnforced, the default, owns replicas without s3:ObjectOwnerOverrideToBucketOwner."""+ partial = _dest_policy("qa-xrepl-dst-enf", actions=("s3:ReplicateObject",))+ src_client, dst_client, src, dst = _cross_account_pair("enf", policy=partial)try:src_client.put_object(Bucket=src, Key="telemetry/k", Body=b"x")- assert src_client.head_object(Bucket=src, Key="telemetry/k")["ReplicationStatus"] == "FAILED"+ assert src_client.head_object(Bucket=src, Key="telemetry/k")["ReplicationStatus"] == "COMPLETED"+ finally:+ _purge_foreign(src_client, src)+ _purge_foreign(dst_client, dst)+++def test_s3_replication_cross_account_without_destination_account(s3):+ """The bucket name identifies the destination; Account is only for owner override."""+ src_client, dst_client, src, dst = _cross_account_pair("noacct", translate=False)+ try:+ src_client.put_object(Bucket=src, Key="telemetry/k", Body=b"x")+ assert src_client.head_object(Bucket=src, Key="telemetry/k")["ReplicationStatus"] == "COMPLETED"+ assert dst_client.head_object(Bucket=dst, Key="telemetry/k")["ReplicationStatus"] == "REPLICA"finally:_purge_foreign(src_client, src)_purge_foreign(dst_client, dst)+def test_s3_replication_filter_round_trips_tag_and_and(s3):+ src, dst = _bucket(s3, versioned=True), _bucket(s3, versioned=True)+ rules = [+ {"ID": "tag", "Priority": 1, "Status": "Enabled", "DeleteMarkerReplication": {"Status": "Disabled"},+ "Filter": {"Tag": {"Key": "k", "Value": "v"}}, "Destination": {"Bucket": f"arn:aws:s3:::{dst}"}},+ {"ID": "and", "Priority": 2, "Status": "Enabled", "DeleteMarkerReplication": {"Status": "Disabled"},+ "Filter": {"And": {"Prefix": "logs/", "Tags": [{"Key": "a", "Value": "1"}, {"Key": "b", "Value": "2"}]}},+ "Destination": {"Bucket": f"arn:aws:s3:::{dst}"}},+ ]+ s3.put_bucket_replication(Bucket=src, ReplicationConfiguration={"Role": _REPL_ROLE, "Rules": rules})+ got = s3.get_bucket_replication(Bucket=src)["ReplicationConfiguration"]["Rules"]+ assert [r["Filter"] for r in got] == [r["Filter"] for r in rules]++def test_s3_replication_config_round_trips_cross_account_fields(s3):"""GetBucketReplication answers the cross-account fields the PUT stored."""src_client, dst_client, src, dst = _cross_account_pair("cfg")