mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(guardduty): scope organization state across accounts (#3278)
* fix: scope GuardDuty state across accounts * test(guardduty): add cross-account SDK coverage
This commit is contained in:
1 parent
9d4e71f8a2
commit
ed116ae815
5 files changed
+125
-16
No files matched your search
+53
-2
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.core.storage.PersistentStorage;
|
||||
import io.github.hectorvent.floci.services.guardduty.model.AdminAccount;
|
||||
@@ -178,19 +179,29 @@ class GuardDutyServiceTest {
|
||||
AwsException error = assertThrows(
|
||||
AwsException.class, () -> service.deleteDetector(REGION, detector.getId()));
|
||||
assertEquals(GuardDutyService.DETECTOR_NOT_FOUND_MESSAGE, error.getMessage());
|
||||
assertTrue(service.listDetectorIds(REGION, null, null).items().isEmpty());
|
||||
assertTrue(service.listDetectorIds(REGION, ACCOUNT, null, null).items().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listDetectorIdsReturnsTheRegionalDetector() throws Exception {
|
||||
Detector detector = service.createDetector(REGION, ACCOUNT, request("{\"enable\":true}"));
|
||||
|
||||
GuardDutyService.Page<String> page = service.listDetectorIds(REGION, null, null);
|
||||
GuardDutyService.Page<String> page = service.listDetectorIds(REGION, ACCOUNT, null, null);
|
||||
|
||||
assertEquals(List.of(detector.getId()), page.items());
|
||||
assertNull(page.nextToken());
|
||||
}
|
||||
|
||||
@Test
|
||||
void detectorsAreScopedByAccountWithinTheSameRegion() throws Exception {
|
||||
String otherAccount = "222222222222";
|
||||
Detector first = service.createDetector(REGION, ACCOUNT, request("{\"enable\":true}"));
|
||||
Detector second = service.createDetector(REGION, otherAccount, request("{\"enable\":true}"));
|
||||
|
||||
assertEquals(List.of(first.getId()), service.listDetectorIds(REGION, ACCOUNT, null, null).items());
|
||||
assertEquals(List.of(second.getId()), service.listDetectorIds(REGION, otherAccount, null, null).items());
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeOrganizationConfigurationDefaultsToNone() throws Exception {
|
||||
Detector detector = service.createDetector(REGION, ACCOUNT, request("{\"enable\":true}"));
|
||||
@@ -262,6 +273,46 @@ class GuardDutyServiceTest {
|
||||
assertEquals("BadRequestException", badValue.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void delegatedAdministratorCreatesEnabledOrganizationMembers() throws Exception {
|
||||
String adminAccount = "111111111111";
|
||||
String managementAccount = "222222222222";
|
||||
service.enableOrganizationAdminAccount(REGION, request("{\"adminAccountId\":\"" + adminAccount + "\"}"));
|
||||
Detector adminDetector = service.createDetector(REGION, adminAccount, request("{\"enable\":true}"));
|
||||
service.createDetector(REGION, managementAccount, request("{\"enable\":true}"));
|
||||
|
||||
service.createMembers(REGION, adminDetector.getId(), request(
|
||||
"{\"accountDetails\":[{\"accountId\":\"" + managementAccount
|
||||
+ "\",\"email\":\"management@example.com\"}]}"));
|
||||
|
||||
List<MemberAccount> members = service.listMembers(REGION, adminDetector.getId(), null, null, "true").items();
|
||||
assertEquals(1, members.size());
|
||||
assertEquals(managementAccount, members.get(0).accountId());
|
||||
assertEquals("Enabled", members.get(0).relationshipStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void delegatedAdministratorIsVisibleAcrossAccountPartitions() throws Exception {
|
||||
String adminAccount = "111111111111";
|
||||
String managementAccount = "222222222222";
|
||||
AccountAwareStorageBackend<Detector> detectors = AccountAwareStorageBackend.inMemory(adminAccount);
|
||||
AccountAwareStorageBackend<AdminAccount> admins = AccountAwareStorageBackend.inMemory(adminAccount);
|
||||
AccountAwareStorageBackend<MemberAccount> members = AccountAwareStorageBackend.inMemory(adminAccount);
|
||||
admins.putForAccount(managementAccount, REGION + "::" + adminAccount,
|
||||
new AdminAccount(adminAccount, "ENABLED"));
|
||||
GuardDutyService partitioned = new GuardDutyService(detectors, admins, members);
|
||||
Detector adminDetector = partitioned.createDetector(REGION, adminAccount, request("{\"enable\":true}"));
|
||||
|
||||
partitioned.createMembers(REGION, adminDetector.getId(), request(
|
||||
"{\"accountDetails\":[{\"accountId\":\"" + managementAccount
|
||||
+ "\",\"email\":\"management@example.com\"}]}"));
|
||||
|
||||
List<MemberAccount> listed = partitioned.listMembers(
|
||||
REGION, adminDetector.getId(), null, null, "true").items();
|
||||
assertEquals(1, listed.size());
|
||||
assertEquals("Enabled", listed.get(0).relationshipStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void adminAccountLifecycle() throws Exception {
|
||||
service.enableOrganizationAdminAccount(REGION, request("{\"adminAccountId\":\"111111111111\"}"));
|
||||
|
||||
Reference in new issue
Block a user