Skip to content

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

fix(cloudtrail): store and return RecursiveLogging on trails (#2261)

iot-rocketc1cc6dfed37b
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6e77b749..969254cb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,7 @@ Versioning follows [Semantic Versioning](https://semver.org/).
## [Unreleased]
### Fixed
+- **CloudTrail — `RecursiveLogging` on trails** — `CreateTrail` and `UpdateTrail` ignored `RecursiveLogging` and no trail response carried it; trails now store it (default `true`, kept by an `UpdateTrail` that leaves it out) and return it from `CreateTrail`, `UpdateTrail`, `GetTrail` and `DescribeTrails`. Contributed by @iot-rocket.
- **CloudWatch — composite alarms follow their rule** — a composite alarm stayed in `INSUFFICIENT_DATA` whatever its children did and `DeleteAlarms` removed alarms that composite alarms depend on; a composite alarm now evaluates its `AlarmRule` (`ALARM`, `OK`, `INSUFFICIENT_DATA`, `TRUE`, `FALSE`, `AND`, `OR`, `NOT`, `AT_LEAST`) when it is created or updated and whenever a child changes state, with the `StateReason`, `StateReasonData` and history items AWS writes, `PutCompositeAlarm` refuses an unknown child or a malformed rule with `ValidationError`, `DeleteAlarms` refuses an alarm a composite alarm depends on and more than one composite alarm per call, and `DescribeAlarmHistory` returns composite alarm items only for `AlarmTypes=["CompositeAlarm"]`, as AWS does. Contributed by @iot-rocket.
- **IoT — unacknowledged QoS 1 messages survive a persistent session reconnect** — a QoS 1 message the subscriber had not acknowledged was dropped when its persistent session disconnected; the session now keeps it with its packet identifier, and the resumed connection sends it again once its retransmit interval has passed (at once when it passed while the client was offline, ahead of the messages queued meanwhile), continuing the session's packet identifiers. Contributed by @iot-rocket.
- **IoT — job documents nested too deep** — `CreateJob` and `CreateJobTemplate` accepted an inline document that is not JSON, and a document nested deeper than Python's JSON parser goes answered 500 (from `documentSource`, or inline once it headed a thing's queue, after which every later `CreateJob` for that thing answered 500 too); they now refuse a document that is not JSON or nests more than 1000 levels deep with AWS's `InvalidRequestException`, and a device gets a 1000-level document compact. Contributed by @iot-rocket.
diff --git a/ministack/services/cloudtrail.py b/ministack/services/cloudtrail.py
index 5df036cf..71d21940 100644
--- a/ministack/services/cloudtrail.py
+++ b/ministack/services/cloudtrail.py
@@ -465,6 +465,7 @@ def _create_trail(body: dict):
"HasCustomEventSelectors": False,
"HasInsightSelectors": False,
"IsOrganizationTrail": body.get("IsOrganizationTrail", False),
+ "RecursiveLogging": body.get("RecursiveLogging", True),
"IsLogging": False,
}
# CreateTrail must persist KmsKeyId so DescribeTrails/GetTrail echo it; otherwise a
@@ -484,6 +485,7 @@ def _create_trail(body: dict):
"TrailARN": arn,
"LogFileValidationEnabled": trail["LogFileValidationEnabled"],
"IsOrganizationTrail": trail["IsOrganizationTrail"],
+ "RecursiveLogging": trail["RecursiveLogging"],
}
if kms:
resp["KmsKeyId"] = kms
@@ -646,6 +648,7 @@ def _update_trail(body: dict):
("CloudWatchLogsLogGroupArn", "CloudWatchLogsLogGroupArn"),
("CloudWatchLogsRoleArn", "CloudWatchLogsRoleArn"),
("IsOrganizationTrail", "IsOrganizationTrail"),
+ ("RecursiveLogging", "RecursiveLogging"),
):
if src in body:
trail[dst] = body[src]
@@ -670,6 +673,7 @@ def _update_trail(body: dict):
"CloudWatchLogsLogGroupArn": trail.get("CloudWatchLogsLogGroupArn", ""),
"CloudWatchLogsRoleArn": trail.get("CloudWatchLogsRoleArn", ""),
"IsOrganizationTrail": trail.get("IsOrganizationTrail", False),
+ "RecursiveLogging": trail.get("RecursiveLogging", True),
}
# Omit KmsKeyId when unset, matching CreateTrail and the DescribeTrails/GetTrail
# read-back: AWS omits the field when there is no CMK, and an empty "" is not a
diff --git a/tests/test_cloudtrail.py b/tests/test_cloudtrail.py
index 2f995df7..fb01ec30 100644
--- a/tests/test_cloudtrail.py
+++ b/tests/test_cloudtrail.py
@@ -124,6 +124,21 @@ def test_create_trail(ct):
assert f"/{name}" in resp["TrailARN"]
+def test_create_trail_recursive_logging_defaults_to_true(ct):
+ name = f"trail-recursive-{_uid()}"
+ assert ct.create_trail(Name=name, S3BucketName="bucket")["RecursiveLogging"] is True
+ assert ct.get_trail(Name=name)["Trail"]["RecursiveLogging"] is True
+ assert ct.describe_trails(trailNameList=[name])["trailList"][0]["RecursiveLogging"] is True
+
+
+def test_create_trail_stores_recursive_logging_false(ct):
+ name = f"trail-recursive-off-{_uid()}"
+ resp = ct.create_trail(Name=name, S3BucketName="bucket", RecursiveLogging=False)
+ assert resp["RecursiveLogging"] is False
+ assert ct.get_trail(Name=name)["Trail"]["RecursiveLogging"] is False
+ assert ct.describe_trails(trailNameList=[name])["trailList"][0]["RecursiveLogging"] is False
+
+
def test_create_trail_duplicate(ct):
name = f"trail-dup-{_uid()}"
ct.create_trail(Name=name, S3BucketName="bucket")
@@ -156,6 +171,7 @@ def test_get_trail_and_describe_trails_return_the_trail_shape(ct):
"HasCustomEventSelectors": False,
"HasInsightSelectors": False,
"IsOrganizationTrail": False,
+ "RecursiveLogging": True,
}
assert _raw_body(ct, "get_trail", Name=name)["Trail"] == expected
assert _raw_body(ct, "describe_trails", trailNameList=[name])["trailList"] == [expected]
@@ -511,6 +527,18 @@ def test_update_trail_persists_fields(ct):
assert desc["IsMultiRegionTrail"] is True
+def test_update_trail_sets_and_keeps_recursive_logging(ct):
+ name = f"trail-update-recursive-{_uid()}"
+ ct.create_trail(Name=name, S3BucketName="bucket")
+ assert ct.update_trail(Name=name, RecursiveLogging=False)["RecursiveLogging"] is False
+ assert ct.get_trail(Name=name)["Trail"]["RecursiveLogging"] is False
+ # An update that leaves the member out keeps the stored value.
+ assert ct.update_trail(Name=name, IncludeGlobalServiceEvents=False)["RecursiveLogging"] is False
+ assert ct.describe_trails(trailNameList=[name])["trailList"][0]["RecursiveLogging"] is False
+ assert ct.update_trail(Name=name, RecursiveLogging=True)["RecursiveLogging"] is True
+ assert ct.get_trail(Name=name)["Trail"]["RecursiveLogging"] is True
+
+
def test_create_trail_persists_kms_key_id(ct):
"""CreateTrail persists KmsKeyId so DescribeTrails/GetTrail echo it. Without this a
CMK-encrypted trail reads back with no KmsKeyId, so Terraform's aws_cloudtrail does