fix(s3): emit ObjectRemoved:Delete when deleting a specific object version (#4710)

* fix(s3): emit ObjectRemoved:Delete when deleting a specific object version

DeleteObject with a versionId permanently removed the version but was
the only delete branch that never fired a notification. It now sends
ObjectRemoved:Delete carrying the deleted versionId, including when the
version is a delete marker. A versionId that matches nothing fires
nothing.

Closes #4680

* fix(s3): carry version-id in EventBridge S3 event details

The EventBridge detail for an S3 event listed the object's key, size and
etag but never its version, so the Object Deleted event for a permanent
version delete could not say which version went. Add object.version-id
whenever the object has one, as AWS does for versioned buckets.

* test(s3): disable the versioned bucket's EventBridge notification in cleanup

* fix(s3): set deletion-type on EventBridge Object Deleted events

AWS tells the two kinds of deletion apart in the EventBridge detail:
"Permanently Deleted" for an object or version that is gone, and
"Delete Marker Created" for a marker. Floci set neither, so the
permanent version delete looked the same as a marker to a rule written
for AWS. Derive it from the event name.
This commit is contained in:
Vinícius Macedo authored and GitHub committed 2026-09-30 11:34:32 -04:00
1 parent 888a718924
commit 5ee81e7006
4 files changed
+255

No files matched your search

@@ -1732,6 +1732,9 @@ public class S3Service implements Resettable, ResourceProvider {
}
}
});
if (toDelete != null) {
fireNotifications(bucketName, key, "ObjectRemoved:Delete", toDelete);
}
return toDelete;
} else {
S3Object existing = objectStore.get(objectKey(bucketName, key)).orElse(null);
@@ -4594,16 +4597,31 @@ public class S3Service implements Resettable, ResourceProvider {
objectNode.put("key", key);
objectNode.put("size", size);
objectNode.put("etag", eTag);
if (obj != null && obj.getVersionId() != null) {
objectNode.put("version-id", obj.getVersionId());
}
detail.put("request-id", UUID.randomUUID().toString());
detail.put("requester", "aws:emulator");
detail.put("source-ip-address", "127.0.0.1");
detail.put("reason", eventName);
String deletionType = eventBridgeDeletionType(eventName);
if (deletionType != null) {
detail.put("deletion-type", deletionType);
}
return objectMapper.writeValueAsString(detail);
} catch (Exception e) {
return "{}";
}
}
private static String eventBridgeDeletionType(String eventName) {
return switch (eventName) {
case "ObjectRemoved:Delete" -> "Permanently Deleted";
case "ObjectRemoved:DeleteMarkerCreated" -> "Delete Marker Created";
default -> null;
};
}
private boolean matchesEvent(String pattern, String eventName) {
String full = "s3:" + eventName;
if (pattern.endsWith("*")) {