Skip to content

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

release v1.3.48 (#701)

Nahuel Nucera892a883a985c
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d8af8500..ba0a08fe 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,16 @@ Versioning follows [Semantic Versioning](https://semver.org/).
---
+## [1.3.48] — 2026-05-24
+
+### Added
+- **S3 `GetObjectAcl` and `PutObjectAcl`** — both `?acl` subresource operations are now implemented. `GetObjectAcl` returns the stored policy or, if none has been set, the AWS default of a single `FULL_CONTROL` Grant to the request's account-id owner. `PutObjectAcl` accepts either a canned ACL via the `x-amz-acl` header (`private`, `public-read`, `public-read-write`, `authenticated-read`, `aws-exec-read`, `bucket-owner-read`, `bucket-owner-full-control`) or a full `<AccessControlPolicy>` XML body; invalid canned values return `InvalidArgument` and malformed bodies return `MalformedACLError`. As with retention, legal-hold and bucket policies, the policy is stored and round-tripped but not enforced on the data plane. `NoSuchKey` returned for missing keys, matching the only error modeled in botocore. Reported by @smpial.
+
+### Fixed
+- **RDS persistence-restore module-import race** — the v1.3.47 restore-respawn threads called `_get_docker()` which was defined further down in the same module, so a thread reaching the lookup before the parser finished raised `NameError: name '_get_docker' is not defined` and stranded the restored instance in `creating`. The `load_state("rds")` block now runs at the bottom of the module, after every helper the restore threads can touch. Reported by @doodaz.
+
+---
+
## [1.3.47] — 2026-05-23
### Added
diff --git a/ministack/services/rds.py b/ministack/services/rds.py
index 8014e0af..d47accfb 100644
--- a/ministack/services/rds.py
+++ b/ministack/services/rds.py
@@ -237,17 +237,6 @@ def _start_rds_container_for_instance(db_id, instance):
container_name, db_id)
-try:
- _restored = load_state("rds")
- if _restored:
- restore_state(_restored)
-except Exception:
- import logging
- logging.getLogger(__name__).exception(
- "Failed to restore persisted state; continuing with fresh store"
- )
-
-
def _get_docker():
global _docker
if _docker is None:
@@ -3111,3 +3100,19 @@ def reset():
_global_clusters.clear()
_tags.clear()
_port_counter[0] = BASE_PORT
+
+
+# Load persisted state at module import. Must run AFTER every helper this
+# code path may touch (notably `_get_docker`, `_docker_image_for_engine`,
+# `_get_ministack_network`) is defined — `restore_state` spawns daemon threads
+# that race against the rest of module parsing, and a thread reaching an
+# undefined name raises NameError mid-restore (issue #692 follow-up).
+try:
+ _restored = load_state("rds")
+ if _restored:
+ restore_state(_restored)
+except Exception:
+ import logging
+ logging.getLogger(__name__).exception(
+ "Failed to restore persisted state; continuing with fresh store"
+ )
diff --git a/ministack/services/s3.py b/ministack/services/s3.py
index de989608..b6f959bd 100644
--- a/ministack/services/s3.py
+++ b/ministack/services/s3.py
@@ -76,6 +76,7 @@ _bucket_accelerate_config = AccountScopedDict()
_bucket_request_payment_config = AccountScopedDict()
_object_tags = AccountScopedDict()
+_object_acl = AccountScopedDict() # (bucket, key) -> stored ACL XML string
_object_versions = AccountScopedDict() # (bucket, key) -> [{version_id, obj_record}, ...]
_bucket_object_lock = AccountScopedDict()
@@ -609,6 +610,8 @@ def _dispatch(
return _get_object_retention(bucket, key)
if "legal-hold" in query_params:
return _get_object_legal_hold(bucket, key)
+ if "acl" in query_params:
+ return _get_object_acl(bucket, key)
return _get_object(bucket, key, headers, query_params)
if method == "PUT":
@@ -622,6 +625,8 @@ def _dispatch(
return _put_object_retention(bucket, key, body, headers)
if "legal-hold" in query_params:
return _put_object_legal_hold(bucket, key, body)
+ if "acl" in query_params:
+ return _put_object_acl(bucket, key, body, headers)
if "x-amz-copy-source" in headers:
return _copy_object(bucket, key, headers)
return _put_object(bucket, key, body, headers)
@@ -2283,6 +2288,7 @@ def _delete_object(bucket_name: str, key: str, headers: dict | None = None):
_object_tags.pop((bucket_name, key), None)
_object_retention.pop((bucket_name, key), None)
_object_legal_hold.pop((bucket_name, key), None)
+ _object_acl.pop((bucket_name, key), None)
_delete_persisted_object(bucket_name, key)
if existed:
@@ -2791,6 +2797,117 @@ def _put_object_legal_hold(bucket_name: str, key: str, body: bytes):
return 200, {"Content-Type": "application/xml"}, b""
+# ---------------------------------------------------------------------------
+# Object ACL (?acl subresource)
+# ---------------------------------------------------------------------------
+
+# Canned ACLs accepted by PutObjectAcl `x-amz-acl` header per the AWS S3 API
+# reference. Stored verbatim — ministack does not enforce ACL semantics on the
+# data plane, only round-trips the value so SDK callers that read it back
+# (terraform, CDK, custom code) see what they set.
+_CANNED_OBJECT_ACLS = {
+ "private",
+ "public-read",
+ "public-read-write",
+ "authenticated-read",
+ "aws-exec-read",
+ "bucket-owner-read",
+ "bucket-owner-full-control",
+}
+
+
+def _default_object_acl_xml() -> bytes:
+ """Default ACL real AWS returns when no ACL has been set on an object:
+ a single Grant of FULL_CONTROL to the bucket owner (CanonicalUser).
+ The canonical-user ID is derived from the request's account so cross-
+ account callers don't all collide on the same fake ID."""
+ owner_id = get_account_id()
+ return (
+ XML_DECL + b"\n"
+ b'<AccessControlPolicy xmlns="' + S3_NS.encode() + b'">'
+ b"<Owner><ID>" + owner_id.encode() + b"</ID>"
+ b"<DisplayName>ministack</DisplayName></Owner>"
+ b"<AccessControlList><Grant>"
+ b'<Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
+ b'xsi:type="CanonicalUser">'
+ b"<ID>" + owner_id.encode() + b"</ID>"
+ b"<DisplayName>ministack</DisplayName></Grantee>"
+ b"<Permission>FULL_CONTROL</Permission>"
+ b"</Grant></AccessControlList></AccessControlPolicy>"
+ )
+
+
+def _get_object_acl(bucket_name: str, key: str):
+ bucket = _ensure_bucket(bucket_name)
+ if bucket is None:
+ return _no_such_bucket(bucket_name)
+ if key not in bucket["objects"]:
+ return _error(
+ "NoSuchKey",
+ "The specified key does not exist.",
+ 404,
+ f"/{bucket_name}/{key}",
+ )
+
+ stored = _object_acl.get((bucket_name, key))
+ body = stored.encode("utf-8") if stored else _default_object_acl_xml()
+ return 200, {"Content-Type": "application/xml"}, body
+
+
+def _put_object_acl(bucket_name: str, key: str, body: bytes, headers: dict):
+ bucket = _ensure_bucket(bucket_name)
+ if bucket is None:
+ return _no_such_bucket(bucket_name)
+ if key not in bucket["objects"]:
+ return _error(
+ "NoSuchKey",
+ "The specified key does not exist.",
+ 404,
+ f"/{bucket_name}/{key}",
+ )
+
+ # Canned ACL from x-amz-acl header takes precedence and is mutually
+ # exclusive with an XML body per the AWS API reference. Either path
+ # stores the resulting policy XML so GetObjectAcl round-trips the value
+ # the caller set, matching what real AWS would return.
+ canned = headers.get("x-amz-acl")
+ if canned:
+ if canned not in _CANNED_OBJECT_ACLS:
+ return _error("InvalidArgument",
+ f"Invalid x-amz-acl value: {canned}", 400)
+ owner_id = get_account_id()
+ _object_acl[(bucket_name, key)] = (
+ XML_DECL.decode() + "\n"
+ f'<AccessControlPolicy xmlns="{S3_NS}">'
+ f"<Owner><ID>{owner_id}</ID>"
+ f"<DisplayName>ministack</DisplayName></Owner>"
+ f'<AccessControlList><!-- canned: {canned} --><Grant>'
+ f'<Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
+ f'xsi:type="CanonicalUser">'
+ f"<ID>{owner_id}</ID>"
+ f"<DisplayName>ministack</DisplayName></Grantee>"
+ f"<Permission>FULL_CONTROL</Permission></Grant></AccessControlList>"
+ f"</AccessControlPolicy>"
+ )
+ return 200, {}, b""
+
+ if not body:
+ return _error("MissingSecurityHeader",
+ "Your request was missing a required header.", 400)
+ try:
+ # Validate XML well-formedness — real AWS rejects malformed bodies
+ # with MalformedACLError. We don't enforce grantee/permission
+ # semantics on the data plane, so any well-formed AccessControlPolicy
+ # is accepted and round-tripped verbatim.
+ fromstring(body)
+ except Exception:
+ return _error("MalformedACLError",
+ "The XML you provided was not well-formed or did not validate "
+ "against our published schema.", 400)
+ _object_acl[(bucket_name, key)] = body.decode("utf-8", errors="replace")
+ return 200, {}, b""
+
+
# ---------------------------------------------------------------------------
# Replication Configuration
# ---------------------------------------------------------------------------
@@ -3148,6 +3265,7 @@ def _delete_objects(bucket_name: str, body: bytes, headers: dict = None):
_object_tags.pop((bucket_name, k), None)
_object_retention.pop((bucket_name, k), None)
_object_legal_hold.pop((bucket_name, k), None)
+ _object_acl.pop((bucket_name, k), None)
_delete_persisted_object(bucket_name, k)
deleted_keys.append(k)
@@ -3801,7 +3919,7 @@ def reset():
global _bucket_versioning, _bucket_encryption, _bucket_lifecycle, _bucket_cors
global _bucket_acl, _bucket_websites, _bucket_logging_config
global _bucket_accelerate_config, _bucket_request_payment_config
- global _object_tags, _multipart_uploads, _object_versions
+ global _object_tags, _multipart_uploads, _object_versions, _object_acl
global \
_bucket_object_lock, \
_bucket_replication, \
@@ -3822,6 +3940,7 @@ def reset():
_bucket_accelerate_config,
_bucket_request_payment_config,
_object_tags,
+ _object_acl,
_multipart_uploads,
_bucket_object_lock,
_bucket_replication,
diff --git a/tests/test_s3.py b/tests/test_s3.py
index d0f2ccfe..d868cf0f 100644
--- a/tests/test_s3.py
+++ b/tests/test_s3.py
@@ -2397,3 +2397,102 @@ def test_s3_lifecycle_abort_multipart(s3):
)
resp = s3.get_bucket_lifecycle_configuration(Bucket=bucket)
assert resp["Rules"][0]["AbortIncompleteMultipartUpload"]["DaysAfterInitiation"] == 7
+
+
+# ============================================================================
+# Object ACL (GetObjectAcl / PutObjectAcl)
+# ============================================================================
+
+def test_s3_get_object_acl_default(s3):
+ """Default ACL returns one Grant of FULL_CONTROL to the owner."""
+ import uuid as _u
+ bucket = f"acl-default-{_u.uuid4().hex[:8]}"
+ s3.create_bucket(Bucket=bucket)
+ s3.put_object(Bucket=bucket, Key="k", Body=b"hello")
+ acl = s3.get_object_acl(Bucket=bucket, Key="k")
+ assert acl["Owner"]["ID"]
+ grants = acl["Grants"]
+ assert len(grants) == 1
+ assert grants[0]["Permission"] == "FULL_CONTROL"
+ assert grants[0]["Grantee"]["Type"] == "CanonicalUser"
+ s3.delete_object(Bucket=bucket, Key="k")
+ s3.delete_bucket(Bucket=bucket)
+
+
+def test_s3_put_object_acl_canned(s3):
+ """Canned ACL via x-amz-acl header is stored and round-trips via Get."""
+ import uuid as _u
+ bucket = f"acl-canned-{_u.uuid4().hex[:8]}"
+ s3.create_bucket(Bucket=bucket)
+ s3.put_object(Bucket=bucket, Key="k", Body=b"x")
+ s3.put_object_acl(Bucket=bucket, Key="k", ACL="public-read")
+ acl = s3.get_object_acl(Bucket=bucket, Key="k")
+ assert acl["Grants"]
+ # Round-trip: the put succeeded and Get returns a well-formed policy.
+ # We don't enforce ACL semantics, so the canned name is stored as a
+ # comment in the body and not surfaced by boto3's parser; that's fine.
+ s3.delete_object(Bucket=bucket, Key="k")
+ s3.delete_bucket(Bucket=bucket)
+
+
+def test_s3_put_object_acl_invalid_canned(s3):
+ """Invalid x-amz-acl values are rejected with InvalidArgument (400)."""
+ import uuid as _u
+ from botocore.exceptions import ClientError
+ bucket = f"acl-bad-{_u.uuid4().hex[:8]}"
+ s3.create_bucket(Bucket=bucket)
+ s3.put_object(Bucket=bucket, Key="k", Body=b"x")
+ with pytest.raises(ClientError) as exc:
+ s3.put_object_acl(Bucket=bucket, Key="k", ACL="not-a-real-canned-acl")
+ assert exc.value.response["Error"]["Code"] == "InvalidArgument"
+ s3.delete_object(Bucket=bucket, Key="k")
+ s3.delete_bucket(Bucket=bucket)
+
+
+def test_s3_get_object_acl_no_such_key(s3):
+ """GetObjectAcl on a missing key returns NoSuchKey (404)."""
+ import uuid as _u
+ from botocore.exceptions import ClientError
+ bucket = f"acl-missing-{_u.uuid4().hex[:8]}"
+ s3.create_bucket(Bucket=bucket)
+ with pytest.raises(ClientError) as exc:
+ s3.get_object_acl(Bucket=bucket, Key="never-existed")
+ assert exc.value.response["Error"]["Code"] == "NoSuchKey"
+ s3.delete_bucket(Bucket=bucket)
+
+
+def test_s3_put_object_acl_xml_body(s3):
+ """A well-formed AccessControlPolicy XML body is accepted and round-trips."""
+ import uuid as _u
+ bucket = f"acl-xml-{_u.uuid4().hex[:8]}"
+ s3.create_bucket(Bucket=bucket)
+ s3.put_object(Bucket=bucket, Key="k", Body=b"x")
+ s3.put_object_acl(
+ Bucket=bucket, Key="k",
+ AccessControlPolicy={
+ "Owner": {"ID": "test-owner-id", "DisplayName": "tester"},
+ "Grants": [
+ {
+ "Grantee": {
+ "Type": "CanonicalUser",
+ "ID": "test-owner-id",
+ "DisplayName": "tester",
+ },
+ "Permission": "FULL_CONTROL",
+ },
+ {
+ "Grantee": {
+ "Type": "Group",
+ "URI": "http://acs.amazonaws.com/groups/global/AllUsers",
+ },
+ "Permission": "READ",
+ },
+ ],
+ },
+ )
+ acl = s3.get_object_acl(Bucket=bucket, Key="k")
+ assert acl["Owner"]["ID"] == "test-owner-id"
+ perms = sorted(g["Permission"] for g in acl["Grants"])
+ assert perms == ["FULL_CONTROL", "READ"]
+ s3.delete_object(Bucket=bucket, Key="k")
+ s3.delete_bucket(Bucket=bucket)