Skip to content

Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.

fix(s3): resolve cross-account replication destinations and enforce destination policy (#2067)

Lisandro Pintosbc898abb523a
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0b9ff207..c8137392 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -21,6 +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.
- **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.py
index 7b105e20..41fb78e0 100644
--- a/ministack/services/s3.py
+++ b/ministack/services/s3.py
@@ -43,6 +43,7 @@ import struct
import threading
import time
import zlib
+from contextlib import contextmanager
from urllib.parse import parse_qs as _parse_qs
from urllib.parse import quote as url_quote
from urllib.parse import quote_plus as _url_quote_plus
@@ -3830,9 +3831,10 @@ def _put_object(bucket_name: str, key: str, body: bytes, headers: dict):
if pending_tags is not None:
_object_tags[(bucket_name, key, obj.get("version_id"))] = pending_tags
if obj.get("_replica"):
- dest_name, replica_version = obj["_replica"]
- _object_tags[(dest_name, key, replica_version)] = dict(pending_tags)
- _persist_version_state(dest_name, key, _buckets[dest_name])
+ dest_name, replica_version, dest_account = obj["_replica"]
+ with _in_account(dest_account):
+ _object_tags[(dest_name, key, replica_version)] = dict(pending_tags)
+ _persist_version_state(dest_name, key, _buckets[dest_name])
if canned_acl:
_object_acl[(bucket_name, key, obj.get("version_id"))] = _canned_acl_policy_xml(
canned_acl, _canonical_owner_id()
@@ -4070,8 +4072,10 @@ def _post_object(bucket_name: str, body: bytes, headers: dict):
if pending_tags is not None:
_object_tags[(bucket_name, key, version_id)] = pending_tags
if obj.get("_replica"):
- _object_tags[(obj["_replica"][0], key, obj["_replica"][1])] = dict(pending_tags)
- _persist_version_state(obj["_replica"][0], key, _buckets[obj["_replica"][0]])
+ dest_name, replica_version, dest_account = obj["_replica"]
+ with _in_account(dest_account):
+ _object_tags[(dest_name, key, replica_version)] = dict(pending_tags)
+ _persist_version_state(dest_name, key, _buckets[dest_name])
if canned_acl:
_object_acl[(bucket_name, key, version_id)] = _canned_acl_policy_xml(canned_acl, _canonical_owner_id())
@@ -4587,21 +4591,86 @@ def _preserve_null_version(bucket_name: str, key: str, versions: list, prior_obj
versions.append(_version_entry_from_record(prior_obj, "null", _read_body(bucket_name, key, prior_obj)))
-def _replication_rule_for(bucket_name: str, key: str) -> dict | None:
- """The first Enabled rule whose Prefix covers `key`, or None.
+def _replication_rule_for(bucket_name: str, key: str) -> tuple[dict | None, str]:
+ """The first Enabled rule whose filter covers `key`, plus the config Role.
- Replication runs only while the source bucket's versioning is Enabled,
- as on AWS (a Suspended bucket stops replicating; the stored config stays).
+ A rule matches when the key falls under its prefix — legacy V1 rules carry
+ ``Prefix`` directly, V2 rules carry it inside ``Filter``. Replication runs
+ only while the source bucket's versioning is Enabled, as on AWS (a
+ Suspended bucket stops replicating; the stored config stays).
"""
config = _bucket_replication.get(bucket_name)
if not config or _bucket_versioning.get(bucket_name) != "Enabled":
- return None
+ return None, ""
for rule in config.get("Rules", []):
if rule.get("Status") != "Enabled":
continue
- if key.startswith(rule.get("Prefix") or ""):
- return rule
- return None
+ prefix = rule.get("Prefix")
+ if prefix is None:
+ prefix = (rule.get("Filter") or {}).get("Prefix", "")
+ if key.startswith(prefix):
+ return rule, config.get("Role", "")
+ return None, ""
+
+
+@contextmanager
+def _in_account(account_id: str):
+ """Run the wrapped block inside *account_id*'s tenancy, then restore.
+
+ A cross-account replica lands in a bucket another account owns; pinning
+ the request account keeps every account-scoped store (objects, versions,
+ tags, annotations, on-disk files) inside the destination tenant.
+ """
+ previous = get_account_id()
+ if account_id == previous:
+ yield
+ return
+ set_request_account_id(account_id)
+ try:
+ yield
+ finally:
+ set_request_account_id(previous)
+
+
+def _replication_destination_allows(dest_account: str, dest_name: str, key: str,
+ role: str, dest: dict) -> bool:
+ """Whether the destination bucket policy grants the replication role.
+
+ Cross-account replication requires the destination owner to allow the
+ source's replication role ``s3:ReplicateObject`` on the destination
+ objects, plus ``s3:ObjectOwnerOverrideToBucketOwner`` when the rule
+ carries ``AccessControlTranslation``. A missing or denying policy stamps
+ the source FAILED, as AWS reports a replica it could not write.
+ """
+ policy = _bucket_policies.get_scoped(dest_account, None, dest_name)
+ if not policy:
+ return False
+ from ministack.core.iam_evaluator import EvalContext, evaluate_resource_policy
+
+ role_parts = role.split(":")
+ role_account = role_parts[4] if role.startswith("arn:") and len(role_parts) > 4 else ""
+ resource = f"arn:aws:s3:::{dest_name}/{key}"
+ ctx = EvalContext(
+ principal_arn=role,
+ principal_type="AssumedRole",
+ principal_account=role_account,
+ action="s3:ReplicateObject",
+ resource_arn=resource,
+ region=get_region(),
+ )
+ if evaluate_resource_policy(policy, ctx).decision != "Allow":
+ return False
+ if dest.get("AccessControlTranslation"):
+ ctx = EvalContext(
+ principal_arn=role,
+ principal_type="AssumedRole",
+ principal_account=role_account,
+ action="s3:ObjectOwnerOverrideToBucketOwner",
+ resource_arn=resource,
+ region=get_region(),
+ )
+ return evaluate_resource_policy(policy, ctx).decision == "Allow"
+ return True
def _maybe_replicate(bucket_name: str, key: str, obj: dict, data) -> None:
@@ -4615,32 +4684,46 @@ def _maybe_replicate(bucket_name: str, key: str, obj: dict, data) -> None:
entry is recorded, so a version-addressed read carries the status too.
A destination that no longer exists or is no longer versioned stamps the
source FAILED, which is how AWS reports a replica it could not write.
+ A destination owned by another account also requires the destination's
+ bucket policy to grant the replication role; otherwise AWS fails the
+ replica the same way.
"""
- rule = _replication_rule_for(bucket_name, key)
+ rule, role = _replication_rule_for(bucket_name, key)
if rule is None:
return
- dest_ref = (rule.get("Destination") or {}).get("Bucket") or ""
+ dest = rule.get("Destination") or {}
+ dest_ref = dest.get("Bucket") or ""
dest_name = dest_ref.split(":::")[-1] if ":::" in dest_ref else dest_ref
- dest_bucket = _buckets.get(dest_name)
+ source_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)
if (dest_bucket is None or dest_name == bucket_name
- or _bucket_versioning.get(dest_name) != "Enabled"):
+ or _bucket_versioning.get_scoped(dest_account, None, dest_name) != "Enabled"):
+ obj["replication_status"] = "FAILED"
+ return
+ if (dest_account != source_account and not _replication_destination_allows(
+ dest_account, dest_name, key, role, dest)):
obj["replication_status"] = "FAILED"
return
replica = copy.deepcopy(obj)
replica["replication_status"] = "REPLICA"
replica.pop("version_id", None)
- if rule.get("Destination", {}).get("StorageClass"):
- replica["storage_class"] = rule["Destination"]["StorageClass"]
+ replica.pop("_replica", None)
+ if dest.get("StorageClass"):
+ replica["storage_class"] = dest["StorageClass"]
prior = dest_bucket["objects"].get(key)
dest_bucket["objects"][key] = replica
- replica_version = _record_object_version(dest_name, key, prior, replica, data)
+ with _in_account(dest_account):
+ replica_version = _record_object_version(dest_name, key, prior, replica, data)
+ if S3_PERSIST:
+ _persist_object(dest_name, key, replica)
# The write paths store the source's tags after the version is cut; the
# pointer lets them mirror the tags onto the replica, as AWS replicates
# them. Internal bookkeeping only — never serialized onto a response.
- obj["_replica"] = (dest_name, replica_version)
- if S3_PERSIST:
- _persist_object(dest_name, key, replica)
+ obj["_replica"] = (dest_name, replica_version, dest_account)
obj["replication_status"] = "COMPLETED"
@@ -5212,10 +5295,11 @@ def _copy_object(bucket_name: str, dest_key: str, headers: dict):
if pending_dest_annotations:
_object_annotations[(bucket_name, dest_key, dest_version_id)] = pending_dest_annotations
if dest_obj.get("_replica"):
- replica_bucket, replica_version = dest_obj["_replica"]
- _object_annotations[(replica_bucket, dest_key, replica_version)] = {
- name: dict(entry, replication_status="REPLICA") for name, entry in pending_dest_annotations.items()
- }
+ replica_bucket, replica_version, replica_account = dest_obj["_replica"]
+ with _in_account(replica_account):
+ _object_annotations[(replica_bucket, dest_key, replica_version)] = {
+ name: dict(entry, replication_status="REPLICA") for name, entry in pending_dest_annotations.items()
+ }
for entry in pending_dest_annotations.values():
entry["replication_status"] = "COMPLETED"
else:
@@ -5223,8 +5307,10 @@ def _copy_object(bucket_name: str, dest_key: str, headers: dict):
if pending_dest_tags is not None:
_object_tags[(bucket_name, dest_key, dest_version_id)] = pending_dest_tags
if dest_obj.get("_replica"):
- _object_tags[(dest_obj["_replica"][0], dest_key, dest_obj["_replica"][1])] = dict(pending_dest_tags)
- _persist_version_state(dest_obj["_replica"][0], dest_key, _buckets[dest_obj["_replica"][0]])
+ replica_bucket, replica_version, replica_account = dest_obj["_replica"]
+ with _in_account(replica_account):
+ _object_tags[(replica_bucket, dest_key, replica_version)] = dict(pending_dest_tags)
+ _persist_version_state(replica_bucket, dest_key, _buckets[replica_bucket])
else:
_object_tags.pop((bucket_name, dest_key, dest_version_id), None)
@@ -5648,12 +5734,13 @@ def _put_object_annotation(bucket_name: str, key: str, body: bytes, headers: dic
# Annotations replicate onto the version's replica.
current = bucket["objects"].get(key)
if current is not None and current.get("version_id") == version_key and current.get("_replica"):
- replica_bucket, replica_version = current["_replica"]
- replica_key = (replica_bucket, key, replica_version)
- replica_annotations = dict(_object_annotations.get(replica_key) or {})
- replica_annotations[name] = dict(entry, replication_status="REPLICA")
- _object_annotations[replica_key] = replica_annotations
- _persist_version_state(replica_bucket, key, _buckets[replica_bucket])
+ replica_bucket, replica_version, replica_account = current["_replica"]
+ with _in_account(replica_account):
+ replica_key = (replica_bucket, key, replica_version)
+ replica_annotations = dict(_object_annotations.get(replica_key) or {})
+ replica_annotations[name] = dict(entry, replication_status="REPLICA")
+ _object_annotations[replica_key] = replica_annotations
+ _persist_version_state(replica_bucket, key, _buckets[replica_bucket])
entry["replication_status"] = "COMPLETED"
annotations[name] = entry
_object_annotations[store_key] = annotations
@@ -6252,23 +6339,47 @@ def _put_bucket_replication(bucket_name: str, body: bytes):
prefix_el = _find_xml_tag(rule_el, "Prefix")
if prefix_el is not None and prefix_el.text is not None:
rule["Prefix"] = prefix_el.text
+ filter_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 ""
+ }
+ 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)
+ dmr_el = _find_xml_tag(rule_el, "DeleteMarkerReplication")
+ if dmr_el is not None:
+ dmr_status = _find_xml_tag(dmr_el, "Status")
+ rule["DeleteMarkerReplication"] = {
+ "Status": dmr_status.text if dmr_status is not None and dmr_status.text else "Disabled"
+ }
dest_el = _find_xml_tag(rule_el, "Destination")
if dest_el is not None:
dest: dict = {}
bucket_el = _find_xml_tag(dest_el, "Bucket")
if bucket_el is not None and bucket_el.text:
dest["Bucket"] = bucket_el.text
- # Validate destination bucket
+ # Validate destination bucket — the name identifies one bucket
+ # whoever owns it, so the check spans accounts, as on AWS.
dest_name = bucket_el.text.split(":::")[-1] if ":::" in bucket_el.text else bucket_el.text
- dest_bucket = _ensure_bucket(dest_name)
- if dest_bucket is not None:
- dest_versioning = _bucket_versioning.get(dest_name, "")
+ dest_owner = _bucket_owner_account(dest_name)
+ if dest_owner is not None:
+ dest_versioning = _bucket_versioning.get_scoped(dest_owner, None, dest_name, "")
if dest_versioning != "Enabled":
return _error(
"InvalidRequest",
"Destination bucket must have versioning enabled.",
400,
)
+ account_el = _find_xml_tag(dest_el, "Account")
+ if account_el is not None and account_el.text:
+ dest["Account"] = account_el.text
+ act_el = _find_xml_tag(dest_el, "AccessControlTranslation")
+ if act_el is not None:
+ owner_el = _find_xml_tag(act_el, "Owner")
+ if owner_el is not None and owner_el.text:
+ dest["AccessControlTranslation"] = {"Owner": owner_el.text}
sc_el = _find_xml_tag(dest_el, "StorageClass")
if sc_el is not None and sc_el.text:
dest["StorageClass"] = sc_el.text
@@ -6302,11 +6413,26 @@ def _get_bucket_replication(bucket_name: str):
rule_el = SubElement(root, "Rule")
SubElement(rule_el, "ID").text = rule.get("ID", "")
SubElement(rule_el, "Status").text = rule.get("Status", "Enabled")
+ if "Priority" in rule:
+ SubElement(rule_el, "Priority").text = str(rule["Priority"])
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", "")
+ if "DeleteMarkerReplication" in rule:
+ dmr_el = SubElement(rule_el, "DeleteMarkerReplication")
+ SubElement(dmr_el, "Status").text = (rule["DeleteMarkerReplication"] or {}).get(
+ "Status", "Disabled")
dest = rule.get("Destination", {})
if dest:
dest_el = SubElement(rule_el, "Destination")
+ if "Account" in dest:
+ SubElement(dest_el, "Account").text = dest["Account"]
+ if "AccessControlTranslation" in dest:
+ act_el = SubElement(dest_el, "AccessControlTranslation")
+ SubElement(act_el, "Owner").text = (dest["AccessControlTranslation"] or {}).get(
+ "Owner", "")
if "Bucket" in dest:
SubElement(dest_el, "Bucket").text = dest["Bucket"]
if "StorageClass" in dest:
diff --git a/tests/test_s3.py b/tests/test_s3.py
index 150de7b9..fc235976 100644
--- a/tests/test_s3.py
+++ b/tests/test_s3.py
@@ -7547,6 +7547,152 @@ def test_annotations_replicate(s3):
assert [(a["AnnotationName"], a["ReplicationStatus"]) for a in listed] == [("a", "REPLICA")]
+def _s3_account(account_id):
+ """An S3 client whose requests run inside *account_id* (12-digit key)."""
+ import boto3 as _boto3
+ return _boto3.client(
+ "s3", endpoint_url=ENDPOINT, region_name="us-east-1",
+ aws_access_key_id=account_id, aws_secret_access_key="test",
+ )
+
+
+_SOURCE_ACCOUNT = "111111111111"
+_DEST_ACCOUNT = "999999999999"
+_REPL_ROLE = f"arn:aws:iam::{_SOURCE_ACCOUNT}:role/replication"
+
+
+def _dest_policy(dest_bucket, actions=("s3:ReplicateObject", "s3:ObjectOwnerOverrideToBucketOwner")):
+ """The destination-side grant AWS requires for cross-account replication."""
+ return json.dumps({
+ "Version": "2012-10-17",
+ "Statement": [{
+ "Sid": "AllowReplication",
+ "Effect": "Allow",
+ "Principal": {"AWS": _REPL_ROLE},
+ "Action": list(actions),
+ "Resource": f"arn:aws:s3:::{dest_bucket}/*",
+ }],
+ })
+
+
+def _cross_account_pair(slug, policy="default", dest_account=_DEST_ACCOUNT):
+ """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."""
+ 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 policy == "default":
+ dst_client.put_bucket_policy(Bucket=dst, Policy=_dest_policy(dst))
+ elif policy is not None:
+ dst_client.put_bucket_policy(Bucket=dst, Policy=policy)
+ src_client.create_bucket(Bucket=src)
+ src_client.put_bucket_versioning(Bucket=src, VersioningConfiguration={"Status": "Enabled"})
+ src_client.put_bucket_replication(
+ Bucket=src,
+ ReplicationConfiguration={
+ "Role": _REPL_ROLE,
+ "Rules": [{
+ "ID": "r1", "Status": "Enabled", "Filter": {"Prefix": ""},
+ "DeleteMarkerReplication": {"Status": "Disabled"},
+ "Destination": {
+ "Bucket": f"arn:aws:s3:::{dst}",
+ "Account": dest_account,
+ "AccessControlTranslation": {"Owner": "Destination"},
+ },
+ }],
+ },
+ )
+ return src_client, dst_client, src, dst
+
+
+def _purge_foreign(s3_client, bucket):
+ lv = s3_client.list_object_versions(Bucket=bucket)
+ for v in lv.get("Versions", []) + lv.get("DeleteMarkers", []):
+ s3_client.delete_object(Bucket=bucket, Key=v["Key"], VersionId=v["VersionId"])
+ s3_client.delete_bucket(Bucket=bucket)
+
+
+def test_s3_replication_cross_account_writes_replica(s3):
+ """A rule naming a destination in another account lands the replica there
+ once the destination policy grants the replication role, matching AWS's
+ documented cross-account requirement."""
+ src_client, dst_client, src, dst = _cross_account_pair("ok")
+ try:
+ src_client.put_object(Bucket=src, Key="telemetry/k", Body=b"payload",
+ Tagging="team=core")
+ head = src_client.head_object(Bucket=src, Key="telemetry/k")
+ assert head["ReplicationStatus"] == "COMPLETED"
+ replica = dst_client.get_object(Bucket=dst, Key="telemetry/k")
+ assert replica["ReplicationStatus"] == "REPLICA"
+ assert replica["Body"].read() == b"payload"
+ tags = dst_client.get_object_tagging(Bucket=dst, Key="telemetry/k")["TagSet"]
+ assert tags == [{"Key": "team", "Value": "core"}]
+ finally:
+ _purge_foreign(src_client, src)
+ _purge_foreign(dst_client, dst)
+
+
+def test_s3_replication_cross_account_requires_destination_policy(s3):
+ """Without a destination bucket policy granting the replication role,
+ AWS cannot write the replica — the source reports FAILED."""
+ src_client, dst_client, src, dst = _cross_account_pair("nopol", policy=None)
+ 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"
+ with pytest.raises(ClientError):
+ dst_client.head_object(Bucket=dst, Key="telemetry/k")
+ finally:
+ _purge_foreign(src_client, src)
+ _purge_foreign(dst_client, dst)
+
+
+def test_s3_replication_cross_account_requires_owner_override_grant(s3):
+ """AccessControlTranslation needs s3:ObjectOwnerOverrideToBucketOwner in
+ the destination policy; without it replication fails."""
+ partial = _dest_policy("qa-xrepl-dst-own", actions=("s3:ReplicateObject",))
+ src_client, dst_client, src, dst = _cross_account_pair("own", 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"
+ finally:
+ _purge_foreign(src_client, src)
+ _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")
+ 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"
+ finally:
+ _purge_foreign(src_client, src)
+ _purge_foreign(dst_client, dst)
+
+
+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")
+ try:
+ config = src_client.get_bucket_replication(Bucket=src)["ReplicationConfiguration"]
+ rule = config["Rules"][0]
+ dest = rule["Destination"]
+ assert dest["Account"] == _DEST_ACCOUNT
+ assert dest["AccessControlTranslation"] == {"Owner": "Destination"}
+ assert dest["Bucket"] == f"arn:aws:s3:::{dst}"
+ assert rule["Filter"] == {"Prefix": ""}
+ assert rule["DeleteMarkerReplication"] == {"Status": "Disabled"}
+ finally:
+ _purge_foreign(src_client, src)
+ _purge_foreign(dst_client, dst)
+
+
# ── Event notifications ────────────────────────────────────────────────