Skip to content

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

fix(eventbridge): keep KmsKeyIdentifier on archives (#2307)

Kacper Harabasze49a1ac98e99
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 340e4a87..a45a0cad 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,6 +20,7 @@ Versioning follows [Semantic Versioning](https://semver.org/).
- **Auth — more calls are authorized under `AUTH=true`** — RDS Data calls are authorized as `rds-data:<operation>` on the cluster its `resourceArn` names, S3 Control `ListTagsForResource`, `TagResource` and `UntagResource` as `s3:<operation>` on the bucket, and SES v2 calls as `ses:<operation>` on the resource the path or create body names (`*` otherwise), each with AWS's 403 denial (`AccessDeniedException`, S3 Control `AccessDenied`) naming the action and resource. S3 bucket and identity policies now see `s3:x-amz-server-side-encryption` (a part and the completion take their `CreateMultipartUpload`'s), `s3:x-amz-acl`, `s3:x-amz-grant-*` and, on `GetObject` and `HeadObject`, `s3:ExistingObjectTag/<key>`. S3 Tables and Glue Iceberg REST calls at `/iceberg` are authorized for the catalog that serves them, whatever service they are signed for: on a table bucket as the `s3tables` actions AWS lists for the operation (`loadTable` needs `GetTableMetadataLocation`, then `GetTableData`) on the bucket or table (`table/*` for one that does not exist), on the Glue catalog as the route's `glue` action on the catalog, then the database, then the table, and `transactions/commit` as `updateTable` on each table it changes; a denial answers 403 in the Iceberg error shape naming the action and resource ("Access Denied" for a later S3 Tables action, no body for `HEAD`), a `{prefix}` that is neither a table bucket ARN nor `<account>:s3tablescatalog/<bucket>` answers 400 `bad_request`, and a call that names a key is served from its own region only. Contributed by @iot-rocket.
- **IoT — MQTT over WebSocket follows the signer's IAM policies under `AUTH=true`** — a session signed with an IAM user or STS key could connect under any client id and publish, subscribe and receive anywhere; its CONNECT, will, PUBLISH, SUBSCRIBE and deliveries now need `iot:Connect`, `iot:Publish` (and `iot:RetainPublish`), `iot:Subscribe` and `iot:Receive` on the client, topic and topic filter ARNs, with a certificate session's refusals. The handshake (and an `AWS_IAM` WebSocket `$connect`) has its signature, date and session token verified: IoT answers 403 `Forbidden` and expects the token after the signed part of the URL, API Gateway names the canonical string it expected, and the session runs in the signer's account. Contributed by @iot-rocket.
- **Cognito — user pool feature plans** — `CreateUserPool`, `UpdateUserPool` and `AWS::Cognito::UserPool` ignored `UserPoolTier`; a pool now stores and describes its tier (`ESSENTIALS` by default, `PLUS` when created with threat protection on), keeps it when an update omits it, and refuses threat protection on `ESSENTIALS` and password history on `LITE` with `FeatureUnavailableInTierException` or, on a tier change, `TierChangeNotAllowedException`. Contributed by @iot-rocket.
+- **EventBridge — archive KMS keys** — `CreateArchive` and `UpdateArchive` dropped `KmsKeyIdentifier`, so `DescribeArchive` never returned it and Terraform re-planned `kms_key_identifier` on every run; the key is now stored and returned, an update that omits it keeps it, and an empty identifier on update clears it. Contributed by @kharabasz.
### Fixed
- **Auth — unverifiable credentials under `AUTH=true`** — a request naming an IAM user's key in a SigV2 header, another SigV4 algorithm (`AWS4-HMAC-SHA512`), a header without `Credential=` or a query `X-Amz-Credential` the signature does not cover was served as that user; it now answers `IncompleteSignature` (S3: `InvalidRequest`), and SigV2 header and presigned signatures are verified. A request that maps to no IAM action (SES v2, RDS Data, S3 Control, X-Ray) is authenticated and answers the service's credential error (`InvalidSignatureException` 403 from SES v2 and RDS Data, `SignatureDoesNotMatch` 403 from S3 Control), and an SES v2 call selected by `X-Amz-Target` on a path without `/v2/email` is authorized as the operation it performs. A SigV4 header or presigned query that names no access key ran as the account root; it now answers `IncompleteSignature` naming every missing part (Lambda: `MissingAuthenticationTokenException` for a part left out), and an empty key the unknown-key error. Contributed by @iot-rocket.
diff --git a/ministack/services/eventbridge.py b/ministack/services/eventbridge.py
index e7f426e0..34da55ad 100644
--- a/ministack/services/eventbridge.py
+++ b/ministack/services/eventbridge.py
@@ -3020,6 +3020,10 @@ def _create_archive(data):
"EventCount": 0,
"SizeBytes": 0,
}
+ # Unlike event buses, an empty identifier is not stored: an archive with no
+ # customer managed key has no KmsKeyIdentifier in DescribeArchive.
+ if data.get("KmsKeyIdentifier"):
+ _archives[name]["KmsKeyIdentifier"] = data["KmsKeyIdentifier"]
return json_response({"ArchiveArn": arn, "State": "ENABLED", "CreationTime": _archives[name]["CreationTime"]})
@@ -3057,6 +3061,12 @@ def _update_archive(data):
archive["EventPattern"] = ep
if "RetentionDays" in data:
archive["RetentionDays"] = int(data["RetentionDays"])
+ if "KmsKeyIdentifier" in data:
+ # An empty identifier clears the stored key.
+ if data["KmsKeyIdentifier"]:
+ archive["KmsKeyIdentifier"] = data["KmsKeyIdentifier"]
+ else:
+ archive.pop("KmsKeyIdentifier", None)
archive["LastUpdatedTime"] = _now_ts()
return json_response({
diff --git a/tests/test_eventbridge.py b/tests/test_eventbridge.py
index a5e7b31f..632a4ad4 100644
--- a/tests/test_eventbridge.py
+++ b/tests/test_eventbridge.py
@@ -1247,6 +1247,36 @@ def test_eventbridge_update_archive(eb):
eb.delete_archive(ArchiveName=name)
+def test_eventbridge_archive_kms_key_identifier(eb):
+ bus_arn = eb.describe_event_bus(Name="default")["Arn"]
+ key_prefix = bus_arn.split(":event-bus/")[0].replace(":events:", ":kms:")
+ key = f"{key_prefix}:key/archive-key"
+ other = f"{key_prefix}:key/other-key"
+ plain = f"plain-archive-{_uuid_mod.uuid4().hex[:8]}"
+ name = f"kms-archive-{_uuid_mod.uuid4().hex[:8]}"
+ eb.create_archive(ArchiveName=plain, EventSourceArn=bus_arn)
+ try:
+ assert "KmsKeyIdentifier" not in eb.describe_archive(ArchiveName=plain)
+
+ eb.create_archive(ArchiveName=name, EventSourceArn=bus_arn, KmsKeyIdentifier=key)
+ assert eb.describe_archive(ArchiveName=name)["KmsKeyIdentifier"] == key
+
+ eb.update_archive(ArchiveName=name, Description="no key in request")
+ assert eb.describe_archive(ArchiveName=name)["KmsKeyIdentifier"] == key
+
+ eb.update_archive(ArchiveName=name, KmsKeyIdentifier=other)
+ assert eb.describe_archive(ArchiveName=name)["KmsKeyIdentifier"] == other
+
+ eb.update_archive(ArchiveName=name, KmsKeyIdentifier="")
+ assert "KmsKeyIdentifier" not in eb.describe_archive(ArchiveName=name)
+ finally:
+ for archive in (plain, name):
+ try:
+ eb.delete_archive(ArchiveName=archive)
+ except ClientError:
+ pass
+
+
def test_eventbridge_put_remove_permission(eb):
import uuid as _uuid
@@ -5770,3 +5800,4 @@ def test_eventbridge_api_destination_dynamic_http_parameters_use_original_event(
)["Targets"][0]["HttpParameters"] == http_parameters
finally:
server.shutdown()
+