mirror of
https://github.com/floci-io/floci.git
synced 2026-11-30 08:55:17 -05:00
fix(cloudtrail): isolate account buffers and partition matching (#6689)
* fix(cloudtrail): isolate account buffers and partition matching * fix(cloudtrail): honor deployment partitions and cover region deletion * refactor(cloudtrail): share account delivery test helpers
This commit is contained in:
1 parent
196ae07aa8
commit
9303ec2872
4 files changed
+244
-12
No files matched your search
+2
-1
@@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.common.RequestScopes;
|
||||
import io.github.hectorvent.floci.core.common.ServicePrincipals;
|
||||
import io.github.hectorvent.floci.services.cloudtrail.model.Trail;
|
||||
import io.github.hectorvent.floci.services.s3.S3Service;
|
||||
@@ -116,7 +117,7 @@ public class CloudTrailLogWriter {
|
||||
try {
|
||||
for (CloudTrailService.TrailKey key : cloudTrailService.trailsWithPendingRecords()) {
|
||||
try {
|
||||
flushTrailBatches(key);
|
||||
RequestScopes.runAs(key.accountId(), key.region(), () -> flushTrailBatches(key));
|
||||
} catch (RuntimeException e) {
|
||||
LOG.warnv(e, "CloudTrail log flush failed for trail {0} in {1}",
|
||||
key.trailName(), key.region());
|
||||
|
||||
+16
-6
@@ -128,7 +128,8 @@ public class CloudTrailService {
|
||||
Trail trail = findTrailOrThrow(region, trailNameOrArn);
|
||||
String key = regionKey(trail.homeRegion(), trail.name());
|
||||
withTrailLock(key, () -> store.delete(key));
|
||||
pendingRecordsByTrail.keySet().removeIf(k -> k.trailName().equals(trail.name()));
|
||||
pendingRecordsByTrail.keySet().removeIf(k -> k.trailName().equals(trail.name())
|
||||
&& k.region().equals(trail.homeRegion()) && k.accountId().equals(regionResolver.getAccountId()));
|
||||
}
|
||||
|
||||
public Trail updateTrail(String region, String trailNameOrArn,
|
||||
@@ -428,7 +429,7 @@ public class CloudTrailService {
|
||||
List<TrailKey> result = new ArrayList<>();
|
||||
for (Map.Entry<PendingTrailKey, PendingRecordBuffer> e : pendingRecordsByTrail.entrySet()) {
|
||||
for (String eventRegion : e.getValue().eventRegions()) {
|
||||
result.add(new TrailKey(e.getKey().region(), e.getKey().trailName(), eventRegion));
|
||||
result.add(new TrailKey(e.getKey().region(), e.getKey().trailName(), eventRegion, e.getKey().accountId()));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -482,10 +483,15 @@ public class CloudTrailService {
|
||||
* {@code region} is the trail's home region (used for trail store lookups).
|
||||
* {@code eventRegion} is the region where the event occurred (used for the S3 delivery path).
|
||||
* For single-region trails these are the same; for multi-region trails they differ.
|
||||
* {@code accountId} preserves the owning account for background delivery.
|
||||
*/
|
||||
public record TrailKey(String region, String trailName, String eventRegion) {}
|
||||
public record TrailKey(String region, String trailName, String eventRegion, String accountId) {
|
||||
public TrailKey(String region, String trailName, String eventRegion) {
|
||||
this(region, trailName, eventRegion, null);
|
||||
}
|
||||
}
|
||||
|
||||
private record PendingTrailKey(String region, String trailName) {}
|
||||
private record PendingTrailKey(String region, String trailName, String accountId) {}
|
||||
|
||||
private record PendingRecord(ObjectNode record, long byteCount) {}
|
||||
|
||||
@@ -612,8 +618,9 @@ public class CloudTrailService {
|
||||
}
|
||||
}
|
||||
|
||||
private static PendingTrailKey pendingTrailKey(TrailKey key) {
|
||||
return new PendingTrailKey(key.region(), key.trailName());
|
||||
private PendingTrailKey pendingTrailKey(TrailKey key) {
|
||||
return new PendingTrailKey(key.region(), key.trailName(),
|
||||
key.accountId() != null ? key.accountId() : regionResolver.getAccountId());
|
||||
}
|
||||
|
||||
// --- Helpers ---
|
||||
@@ -631,6 +638,9 @@ public class CloudTrailService {
|
||||
if (!sameRegion && !trail.isMultiRegionTrail()) {
|
||||
continue;
|
||||
}
|
||||
if (!regionResolver.partitionForRegion(region).equals(regionResolver.partitionForRegion(trail.homeRegion()))) {
|
||||
continue;
|
||||
}
|
||||
if (!entry.logging()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user