mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(macie2): add organization administration operations (#3105)
* feat(macie2): add organization administration operations * test(macie2): validate organization administration with sdk * fix(macie2): harden delegated administration routing
This commit is contained in:
1 parent
85180a4d88
commit
3927c66040
23 files changed
+566
-21
No files matched your search
+8
@@ -1,5 +1,6 @@
|
||||
package io.github.hectorvent.floci.core.common;
|
||||
|
||||
import io.github.hectorvent.floci.services.securityadmin.SecurityAdminController;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import jakarta.inject.Inject;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -74,6 +75,13 @@ class ServiceCatalogRoutingIntegrationTest {
|
||||
assertTrue(descriptor.supportsProtocol(ServiceProtocol.REST_JSON));
|
||||
}
|
||||
|
||||
@Test
|
||||
void sharedSecurityAdminRouteResolvesOnlyBySigningScope() {
|
||||
assertTrue(catalog.byResourceClass(SecurityAdminController.class).isEmpty());
|
||||
assertEquals("macie2", catalog.byCredentialScope("macie2").orElseThrow().externalKey());
|
||||
assertEquals("guardduty", catalog.byCredentialScope("guardduty").orElseThrow().externalKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
void unknownTargetsRemainUnresolved() {
|
||||
assertTrue(catalog.matchTarget("UnknownService.DoThing").isEmpty());
|
||||
|
||||
@@ -27,6 +27,12 @@ class SigV4CredentialScopeTest {
|
||||
+ " SignedHeaders=host, Signature=deadbeef"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void parsesPresignedCredentialScope() {
|
||||
assertEquals(Optional.of("macie2"), SigV4CredentialScope.serviceNameFromCredential(
|
||||
"222222222222/20260707/us-east-1/macie2/aws4_request"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void ignoresSigV4aBecauseItsCredentialOmitsTheRegion() {
|
||||
// SigV4a carries the region in X-Amz-Region-Set, so its credential is
|
||||
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
package io.github.hectorvent.floci.services.macie2;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import jakarta.inject.Inject;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
|
||||
@QuarkusTest
|
||||
class MacieOrganizationIntegrationTest {
|
||||
private static final String MANAGEMENT_ACCOUNT = "222222222222";
|
||||
private static final String ADMIN_ACCOUNT = "111111111111";
|
||||
private static final String GUARDDUTY_ACCOUNT = "333333333333";
|
||||
|
||||
@Inject
|
||||
MacieService macieService;
|
||||
|
||||
@BeforeEach
|
||||
void resetMacieState() {
|
||||
macieService.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
void delegatedAdministratorOwnsOrganizationConfiguration() {
|
||||
given().header("Authorization", auth(MANAGEMENT_ACCOUNT, "macie2"))
|
||||
.get("/admin").then().statusCode(200).body("adminAccounts", hasSize(0));
|
||||
|
||||
given().contentType("application/json").header("Authorization", auth(MANAGEMENT_ACCOUNT, "macie2"))
|
||||
.body("{\"adminAccountId\":\"" + ADMIN_ACCOUNT + "\"}")
|
||||
.post("/admin").then().statusCode(200);
|
||||
|
||||
given().header("Authorization", auth(MANAGEMENT_ACCOUNT, "macie2"))
|
||||
.get("/admin").then().statusCode(200)
|
||||
.body("adminAccounts[0].accountId", equalTo(ADMIN_ACCOUNT));
|
||||
|
||||
given().header("Authorization", auth(ADMIN_ACCOUNT, "macie2"))
|
||||
.get("/macie").then().statusCode(200).body("status", equalTo("ENABLED"));
|
||||
|
||||
given().contentType("application/json").header("Authorization", auth(MANAGEMENT_ACCOUNT, "macie2"))
|
||||
.body("{\"autoEnable\":true}")
|
||||
.patch("/admin/configuration").then().statusCode(403)
|
||||
.body("__type", equalTo("AccessDeniedException"));
|
||||
|
||||
given().contentType("application/json").header("Authorization", auth(ADMIN_ACCOUNT, "macie2"))
|
||||
.body("{\"autoEnable\":true}")
|
||||
.patch("/admin/configuration").then().statusCode(200);
|
||||
given().header("Authorization", auth(ADMIN_ACCOUNT, "macie2"))
|
||||
.get("/admin/configuration").then().statusCode(200).body("autoEnable", equalTo(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
void sharedAdminRouteKeepsGuardDutyBehavior() {
|
||||
given().header("Authorization", auth(GUARDDUTY_ACCOUNT, "guardduty"))
|
||||
.get("/admin").then().statusCode(200).body("adminAccounts", hasSize(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void presignedMacieAdminRequestUsesCredentialScope() {
|
||||
given().contentType("application/json").header("Authorization", auth(MANAGEMENT_ACCOUNT, "macie2"))
|
||||
.body("{\"adminAccountId\":\"" + ADMIN_ACCOUNT + "\"}")
|
||||
.post("/admin").then().statusCode(200);
|
||||
|
||||
given().queryParam("X-Amz-Credential",
|
||||
MANAGEMENT_ACCOUNT + "/20260101/us-east-1/macie2/aws4_request")
|
||||
.get("/admin").then().statusCode(200)
|
||||
.body("adminAccounts[0].accountId", equalTo(ADMIN_ACCOUNT));
|
||||
}
|
||||
|
||||
private static String auth(String accountId, String service) {
|
||||
return "AWS4-HMAC-SHA256 Credential=" + accountId
|
||||
+ "/20260101/us-east-1/" + service
|
||||
+ "/aws4_request, SignedHeaders=host, Signature=abc";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package io.github.hectorvent.floci.services.macie2;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.services.macie2.model.MacieState;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class MacieServiceTest {
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String MANAGEMENT_ACCOUNT = "222222222222";
|
||||
private static final String ADMIN_ACCOUNT = "111111111111";
|
||||
|
||||
private MacieService service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
service = new MacieService(AccountAwareStorageBackend.inMemory(MANAGEMENT_ACCOUNT));
|
||||
}
|
||||
|
||||
@Test
|
||||
void delegationEnablesMacieForAdministratorAccount() {
|
||||
service.enableOrganizationAdminAccount(REGION, ADMIN_ACCOUNT);
|
||||
|
||||
MacieState delegated = service.requireAdministratorSession(REGION, ADMIN_ACCOUNT);
|
||||
assertTrue(delegated.isEnabled());
|
||||
assertEquals(ADMIN_ACCOUNT, delegated.getAdminAccountId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void managementAccountCannotUpdateAdministratorConfiguration() {
|
||||
service.enableOrganizationAdminAccount(REGION, ADMIN_ACCOUNT);
|
||||
service.enableMacie(REGION);
|
||||
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.updateOrganizationConfiguration(REGION, MANAGEMENT_ACCOUNT, true));
|
||||
assertEquals("AccessDeniedException", error.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void delegatedAdministratorCanUpdateConfiguration() {
|
||||
service.enableOrganizationAdminAccount(REGION, ADMIN_ACCOUNT);
|
||||
|
||||
service.updateOrganizationConfiguration(REGION, ADMIN_ACCOUNT, true);
|
||||
|
||||
assertTrue(service.requireAdministratorSession(REGION, ADMIN_ACCOUNT).isAutoEnable());
|
||||
}
|
||||
|
||||
@Test
|
||||
void conflictingAdministratorDesignationIsRejected() {
|
||||
service.enableOrganizationAdminAccount(REGION, ADMIN_ACCOUNT);
|
||||
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.enableOrganizationAdminAccount(REGION, "333333333333"));
|
||||
assertEquals("ConflictException", error.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void clearRemovesMacieState() {
|
||||
service.enableOrganizationAdminAccount(REGION, ADMIN_ACCOUNT);
|
||||
assertTrue(service.requireAdministratorSession(REGION, ADMIN_ACCOUNT).isEnabled());
|
||||
|
||||
service.clear();
|
||||
|
||||
assertFalse(service.state(REGION).isEnabled());
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.requireAdministratorSession(REGION, ADMIN_ACCOUNT));
|
||||
assertEquals("ResourceNotFoundException", error.getErrorCode());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user