Skip to content

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

fix(iam): authorize S3 multipart uploads as s3:PutObject (#1595)

iot-rocket49dcfafc7645
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 46027612..3bc64d34 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,9 @@ Versioning follows [Semantic Versioning](https://semver.org/).
## [Unreleased]
### Added
+
+- **IAM enforcement — S3 multipart uploads authorize as `s3:PutObject`** — with `AUTH=true` a `CreateMultipartUpload` was checked as the literal action `s3:CreateMultipartUpload`, which no policy grants because it is not an IAM action; `UploadPart`, `CompleteMultipartUpload`, `AbortMultipartUpload` and `ListParts` fell to the generic object actions. Every upload above the SDK's multipart threshold was therefore denied, and `cdk deploy` failed on its first Lambda layer asset even with a correct file-publishing role. The operations now map to the actions S3 documents: the three upload steps to `s3:PutObject`, abort to `s3:AbortMultipartUpload`, the listings to `s3:ListBucketMultipartUploads` / `s3:ListMultipartUploadParts`; `?versions` is `s3:ListBucketVersions`, object-level `?tagging` / `?acl` are the object actions rather than the bucket ones, and the `DELETE` calls on the lifecycle, encryption, replication, tagging and CORS configurations authorize as the matching `Put*` action, since S3 defines no `Delete*` action for them (the table named actions such as `s3:DeleteBucketCors` that no policy can grant). Contributed by @iot-rocket.
+
- **Amazon Transcribe (`transcribe`)** is a new service emulator covering batch transcription jobs: `StartTranscriptionJob`, `GetTranscriptionJob`, `ListTranscriptionJobs` and `DeleteTranscriptionJob`, verified against botocore `transcribe-2017-10-26`. A job walks `QUEUED` → `IN_PROGRESS` → `COMPLETED` on a background task paced by `TRANSCRIBE_JOB_RUN_SECONDS` (default 2, `0` completes immediately), reads its media object from MiniStack's S3 store through an `s3://`, path-style or virtual-hosted HTTPS URI, and writes a transcript document back to S3 in the real Transcribe result format: `results.transcripts`, word-level `results.items`, `results.audio_segments`, and `results.segments` / `results.speaker_labels` when `ShowAlternatives` and `ShowSpeakerLabels` are set. `IdentifyLanguage` fills in `LanguageCode` and `IdentifiedLanguageScore` on completion while `IdentifyMultipleLanguages` reports `LanguageCodes` and leaves `LanguageCode` unset, as AWS does. `ContentRedaction` decides whether the `redacted-` copy replaces the transcript or sits beside it, and `Subtitles` writes WebVTT and SubRip files reported as `SubtitleFileUris`, redacted and renamed to match when redaction is on. Output lands at `OutputBucketName` / `OutputKey`, or in an auto-created `ministack-transcribe-output` bucket when neither is given, so the reported URIs are always fetchable. Media that cannot be read fails the job asynchronously with a `FailureReason` rather than erroring at `Start`, matching AWS, and a job left mid-flight by a restart fails on restore instead of stranding pollers. Reaching a terminal state publishes a `Transcribe Job State Change` event on the default bus, so an S3 → Lambda → Transcribe → EventBridge pipeline runs end to end locally. There is **no speech recognition**: the transcript is deterministic canned text keyed on a digest of the media URI, the same approach Bedrock Runtime takes for model output, which keeps integration tests reproducible. Streaming transcription, the call-analytics and medical job families, custom vocabularies and the tagging operations are not implemented. State is account- and region-scoped and persisted. Contributed by @ppettitau.
## [1.5.5] — 2026-09-01
diff --git a/ministack/core/iam_actions.py b/ministack/core/iam_actions.py
index 2556d1c6..2688f8e8 100644
--- a/ministack/core/iam_actions.py
+++ b/ministack/core/iam_actions.py
@@ -150,38 +150,67 @@ _S3_ACTIONS: dict[tuple[str, int], str] = {
}
# S3 query-param sub-operations
+# Sub-resource (query parameter) → IAM action, keyed by HTTP method. The values
+# are the IAM actions the Amazon S3 authorization reference lists, not the API
+# operation names: multipart uploads authorize as s3:PutObject
+# (CreateMultipartUpload, UploadPart, UploadPartCopy, CompleteMultipartUpload),
+# abort as s3:AbortMultipartUpload and the two listings under their own actions;
+# the DELETE configuration calls (lifecycle, encryption, replication, tagging,
+# CORS) authorize as the matching Put* action, because S3 defines no Delete*
+# action for them. The literal "s3:CreateMultipartUpload" matched no policy and
+# denied every upload above the SDK's multipart threshold — CDK publishes any
+# asset that size (Lambda layers) that way, so `cdk deploy` failed under
+# AUTH=true. Consulted at both the bucket and the object level.
_S3_QUERY_ACTIONS: dict[str, dict[str, str]] = {
- "tagging": {"GET": "GetBucketTagging", "PUT": "PutBucketTagging", "DELETE": "DeleteBucketTagging"},
+ "tagging": {"GET": "GetBucketTagging", "PUT": "PutBucketTagging", "DELETE": "PutBucketTagging"},
"versioning": {"GET": "GetBucketVersioning", "PUT": "PutBucketVersioning"},
"policy": {"GET": "GetBucketPolicy", "PUT": "PutBucketPolicy", "DELETE": "DeleteBucketPolicy"},
- "cors": {"GET": "GetBucketCors", "PUT": "PutBucketCors", "DELETE": "DeleteBucketCors"},
+ "cors": {"GET": "GetBucketCORS", "PUT": "PutBucketCORS", "DELETE": "PutBucketCORS"},
"lifecycle": {"GET": "GetLifecycleConfiguration", "PUT": "PutLifecycleConfiguration",
- "DELETE": "DeleteLifecycleConfiguration"},
+ "DELETE": "PutLifecycleConfiguration"},
"encryption": {"GET": "GetEncryptionConfiguration", "PUT": "PutEncryptionConfiguration",
- "DELETE": "DeleteEncryptionConfiguration"},
+ "DELETE": "PutEncryptionConfiguration"},
"notification": {"GET": "GetBucketNotification", "PUT": "PutBucketNotification"},
"acl": {"GET": "GetBucketAcl", "PUT": "PutBucketAcl"},
"website": {"GET": "GetBucketWebsite", "PUT": "PutBucketWebsite", "DELETE": "DeleteBucketWebsite"},
"logging": {"GET": "GetBucketLogging", "PUT": "PutBucketLogging"},
"replication": {"GET": "GetReplicationConfiguration", "PUT": "PutReplicationConfiguration",
- "DELETE": "DeleteReplicationConfiguration"},
+ "DELETE": "PutReplicationConfiguration"},
"location": {"GET": "GetBucketLocation"},
- "uploads": {"GET": "ListMultipartUploads", "POST": "CreateMultipartUpload"},
+ "uploads": {"GET": "ListBucketMultipartUploads", "POST": "PutObject"},
+ "uploadId": {"GET": "ListMultipartUploadParts", "PUT": "PutObject",
+ "POST": "PutObject", "DELETE": "AbortMultipartUpload"},
"restore": {"POST": "RestoreObject"},
}
+# Sub-resources that only exist at the bucket level.
+_S3_BUCKET_QUERY_ACTIONS: dict[str, dict[str, str]] = {
+ "versions": {"GET": "ListBucketVersions"},
+}
+
+# Sub-resources whose IAM action differs between the bucket and the object
+# level; these win over the shared table for an object request.
+_S3_OBJECT_QUERY_ACTIONS: dict[str, dict[str, str]] = {
+ "tagging": {"GET": "GetObjectTagging", "PUT": "PutObjectTagging",
+ "DELETE": "DeleteObjectTagging"},
+ "acl": {"GET": "GetObjectAcl", "PUT": "PutObjectAcl"},
+}
+
def _s3_action(method: str, path: str, query_params: dict) -> str | None:
parts = [p for p in path.split("/") if p]
depth = min(len(parts), 2)
- # Check sub-operation query params first (bucket-level)
+ # Sub-operation query params first: the level-specific table, then the
+ # shared one. A request for the service root has no sub-resources.
if depth >= 1:
- for qp, action_map in _S3_QUERY_ACTIONS.items():
- if qp in query_params:
- a = action_map.get(method)
- if a:
- return a
+ level_table = _S3_OBJECT_QUERY_ACTIONS if depth == 2 else _S3_BUCKET_QUERY_ACTIONS
+ for table in (level_table, _S3_QUERY_ACTIONS):
+ for qp, action_map in table.items():
+ if qp in query_params:
+ a = action_map.get(method)
+ if a:
+ return a
return _S3_ACTIONS.get((method, depth))
diff --git a/tests/test_iam_auth.py b/tests/test_iam_auth.py
index a563c451..f789611f 100644
--- a/tests/test_iam_auth.py
+++ b/tests/test_iam_auth.py
@@ -1017,6 +1017,57 @@ class TestActionExtraction:
assert extract_iam_action("unknown_svc", "GET", "/", {}, b"", {}) is None
+
+class TestS3ActionMapping:
+ """S3 authorizes by the IAM actions its documentation lists, not by API
+ operation name: every multipart operation except abort is ``s3:PutObject``."""
+
+ def _act(self, method, path, query):
+ from ministack.core.iam_actions import extract_iam_action
+ return extract_iam_action("s3", method, path, {}, b"", query)
+
+ @pytest.mark.parametrize("method,path,query,expected", [
+ ("POST", "/bucket/key", {"uploads": ""}, "s3:PutObject"), # CreateMultipartUpload
+ ("PUT", "/bucket/key", {"uploadId": "u", "partNumber": "1"}, "s3:PutObject"), # UploadPart
+ ("POST", "/bucket/key", {"uploadId": "u"}, "s3:PutObject"), # CompleteMultipartUpload
+ ("DELETE", "/bucket/key", {"uploadId": "u"}, "s3:AbortMultipartUpload"),
+ ("GET", "/bucket/key", {"uploadId": "u"}, "s3:ListMultipartUploadParts"),
+ ("GET", "/bucket", {"uploads": ""}, "s3:ListBucketMultipartUploads"),
+ ("GET", "/bucket", {"versions": ""}, "s3:ListBucketVersions"),
+ ("GET", "/bucket/key", {"tagging": ""}, "s3:GetObjectTagging"),
+ ("PUT", "/bucket/key", {"acl": ""}, "s3:PutObjectAcl"),
+ ("GET", "/bucket", {"tagging": ""}, "s3:GetBucketTagging"),
+ ("DELETE", "/bucket", {"tagging": ""}, "s3:PutBucketTagging"), # no s3:DeleteBucketTagging
+ ("DELETE", "/bucket/key", {"tagging": ""}, "s3:DeleteObjectTagging"),
+ ("GET", "/bucket", {"acl": ""}, "s3:GetBucketAcl"),
+ ("DELETE", "/bucket", {"lifecycle": ""}, "s3:PutLifecycleConfiguration"),
+ ("DELETE", "/bucket", {"encryption": ""}, "s3:PutEncryptionConfiguration"),
+ ("DELETE", "/bucket", {"replication": ""}, "s3:PutReplicationConfiguration"),
+ ("DELETE", "/bucket", {"cors": ""}, "s3:PutBucketCORS"),
+ ("DELETE", "/bucket", {"policy": ""}, "s3:DeleteBucketPolicy"), # this one exists
+ ("GET", "/bucket/key", {"versions": ""}, "s3:GetObject"), # bucket-only sub-resource
+ ("GET", "/bucket/key", {"versionId": "v1"}, "s3:GetObject"), # not s3:GetObjectVersion (known gap)
+ ("PUT", "/bucket/key", {}, "s3:PutObject"),
+ ("HEAD", "/bucket/key", {}, "s3:GetObject"),
+ ("GET", "/bucket", {}, "s3:ListBucket"),
+ ])
+ def test_operation_maps_to_documented_iam_action(self, method, path, query, expected):
+ assert self._act(method, path, query) == expected
+
+ def test_cdk_publishing_role_grant_covers_multipart(self):
+ # The CDK bootstrap file-publishing role grants s3:PutObject* and
+ # s3:Abort*; a multipart asset upload must be authorized by those.
+ stmts = parse_policy_document({"Statement": [{
+ "Effect": "Allow",
+ "Action": ["s3:GetObject*", "s3:GetBucket*", "s3:List*", "s3:PutObject*", "s3:Abort*"],
+ "Resource": ["arn:aws:s3:::cdk-assets", "arn:aws:s3:::cdk-assets/*"]}]})
+ for method, query in (("POST", {"uploads": ""}), ("PUT", {"uploadId": "u", "partNumber": "1"}),
+ ("POST", {"uploadId": "u"}), ("DELETE", {"uploadId": "u"})):
+ action = self._act(method, "/cdk-assets/asset.zip", query)
+ ctx = _ctx(action=action, resource="arn:aws:s3:::cdk-assets/asset.zip")
+ assert evaluate(ctx, [stmts]).decision == "Allow", action
+
+
# ---------------------------------------------------------------------------
# AccessDenied response formatting
# ---------------------------------------------------------------------------
@@ -1271,3 +1322,4 @@ def test_lambda_build_config_returns_a_config_not_an_error(monkeypatch):
})
assert isinstance(config, dict)
assert config["FunctionName"] == "f"
+