diff --git a/README.md b/README.md
index 8d3e21c12d..51b6d45b81 100644
--- a/README.md
+++ b/README.md
@@ -238,7 +238,7 @@ Floci supports local emulation for application services, data services, eventing
| Data, analytics, and AI | Athena, Glue, Lake Formation, EMR, EMR Serverless, Redshift, Firehose, Managed Service for Apache Flink, OpenSearch, S3 Tables, S3 Vectors, Textract, Transcribe, Comprehend, Rekognition, Translate, Bedrock Runtime, Bedrock AgentCore |
| Databases and caching | RDS, RDS Data API, Neptune, DocumentDB, MemoryDB, ElastiCache |
| Messaging and transfer | SES, Kinesis, MSK, Amazon MQ, Transfer Family, IoT Core, Amazon Connect |
-| Security and governance | AWS Network Firewall, AWS RAM, Service Quotas, WAF v2, GuardDuty, CloudTrail, CloudFront, Resource Groups Tagging API, Resource Explorer 2, CloudHSM v2, Organizations, IAM Identity Center (SSO Admin), Control Tower, Service Catalog |
+| Security and governance | AWS Network Firewall, AWS RAM, Service Quotas, WAF v2, GuardDuty, CloudTrail, CloudFront, Resource Groups Tagging API, Resource Explorer 2, CloudHSM v2, Organizations, IAM Identity Center (SSO Admin), Amazon Macie, Control Tower, Service Catalog |
| Cost and billing | Pricing, Cost Explorer, Cost and Usage Reports, BCM Data Exports |
| Resilience, backup, and config | AWS FIS, AWS Backup, AWS Config, AppConfig, AppConfigData, CloudFormation, Cloud Control API |
diff --git a/compatibility-tests/sdk-test-java/pom.xml b/compatibility-tests/sdk-test-java/pom.xml
index f37f5303f1..5c3ad5f071 100644
--- a/compatibility-tests/sdk-test-java/pom.xml
+++ b/compatibility-tests/sdk-test-java/pom.xml
@@ -239,6 +239,11 @@
software.amazon.awssdk
ssoadmin
+
+
+ software.amazon.awssdk
+ macie2
+
software.amazon.awssdk
diff --git a/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java b/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java
index 21d8a89f32..f7efd0dbda 100644
--- a/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java
+++ b/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java
@@ -31,6 +31,7 @@ import software.amazon.awssdk.services.guardduty.GuardDutyClient;
import software.amazon.awssdk.services.fis.FisClient;
import software.amazon.awssdk.services.organizations.OrganizationsClient;
import software.amazon.awssdk.services.ssoadmin.SsoAdminClient;
+import software.amazon.awssdk.services.macie2.Macie2Client;
import software.amazon.awssdk.services.rum.RumClient;
import software.amazon.awssdk.services.resourceexplorer2.ResourceExplorer2Client;
import software.amazon.awssdk.services.s3.S3AsyncClient;
@@ -284,6 +285,18 @@ public final class TestFixtures {
.build();
}
+ public static Macie2Client macie2Client() {
+ return macie2Client("test");
+ }
+
+ public static Macie2Client macie2Client(String accountId) {
+ return Macie2Client.builder()
+ .endpointOverride(ENDPOINT)
+ .region(REGION)
+ .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create(accountId, "test")))
+ .build();
+ }
+
public static SsmClient ssmClient() {
return SsmClient.builder()
.endpointOverride(ENDPOINT)
diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/MacieOrganizationAdministrationTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/MacieOrganizationAdministrationTest.java
new file mode 100644
index 0000000000..234a487b1a
--- /dev/null
+++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/MacieOrganizationAdministrationTest.java
@@ -0,0 +1,38 @@
+package com.floci.test;
+
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+import software.amazon.awssdk.services.macie2.Macie2Client;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assumptions.assumeFalse;
+
+@DisplayName("Macie organization administration")
+class MacieOrganizationAdministrationTest {
+ private static final String MANAGEMENT_ACCOUNT = "222222222222";
+ private static final String ADMIN_ACCOUNT = "111111111111";
+
+ @Test
+ @DisplayName("uses AWS SDK models for delegated administration and organization configuration")
+ void organizationAdministrationUsesAwsSdk() {
+ assumeFalse(TestFixtures.isRealAws(), "Avoids changing Macie organization settings in real AWS");
+
+ try (Macie2Client management = TestFixtures.macie2Client(MANAGEMENT_ACCOUNT);
+ Macie2Client administrator = TestFixtures.macie2Client(ADMIN_ACCOUNT)) {
+ assertThat(management.listOrganizationAdminAccounts(request -> {}).adminAccounts()).isEmpty();
+
+ management.enableOrganizationAdminAccount(request -> request.adminAccountId(ADMIN_ACCOUNT));
+
+ assertThat(management.listOrganizationAdminAccounts(request -> {}).adminAccounts())
+ .anySatisfy(account -> {
+ assertThat(account.accountId()).isEqualTo(ADMIN_ACCOUNT);
+ assertThat(account.statusAsString()).isEqualTo("ENABLED");
+ });
+
+ assertThat(administrator.getMacieSession(request -> {}).statusAsString()).isEqualTo("ENABLED");
+ administrator.updateOrganizationConfiguration(request -> request.autoEnable(true));
+
+ assertThat(administrator.describeOrganizationConfiguration(request -> {}).autoEnable()).isTrue();
+ }
+ }
+}
diff --git a/docs/services/index.md b/docs/services/index.md
index f59d3d6e55..d2e1ffb685 100644
--- a/docs/services/index.md
+++ b/docs/services/index.md
@@ -45,6 +45,7 @@ Operation counts are exact. For dispatch-table services (Query and JSON 1.1) eac
| [CloudWatch RUM](rum.md) | `/appmonitor`, `/appmonitor/{name}`, `/appmonitors` | REST JSON | 5 |
| [GuardDuty](guardduty.md) | `/detector`, `/detector/{detectorId}`, `/detector/{detectorId}/admin`, `/admin/*`, `/tags/*` | REST JSON | 13 |
| [IAM Identity Center (SSO Admin)](ssoadmin.md) | `POST /` + `X-Amz-Target: SWBExternalService.*` | JSON 1.1 | 13 |
+| [Amazon Macie](macie2.md) | `/admin`, `/macie`, `/admin/configuration` | REST JSON | 6 |
| [Amazon Connect](connect.md) | `/instance`, `/instance/{instanceId}/*`, `/tags/*` | REST JSON | 15 |
| [ElastiCache](elasticache.md) | `POST /` with `Action=` param + TCP proxy | Query + RESP | 8 |
| [MemoryDB](memorydb.md) | `POST /` + `X-Amz-Target: AmazonMemoryDB.*` + TCP proxy | JSON 1.1 + RESP | 7 |
diff --git a/docs/services/macie2.md b/docs/services/macie2.md
new file mode 100644
index 0000000000..8715c8530a
--- /dev/null
+++ b/docs/services/macie2.md
@@ -0,0 +1,24 @@
+# Amazon Macie
+
+Floci implements the REST JSON organization surfaces used to configure Macie locally.
+
+## Supported Actions
+
+
+| Action | Description |
+| --- | --- |
+| `EnableOrganizationAdminAccount` | Designates the delegated Macie administrator account. |
+| `GetMacieSession` | Returns the current account Macie session. |
+| `EnableMacie` | Enables Macie for the current account. |
+| `UpdateOrganizationConfiguration` | Updates organization auto-enable settings as the delegated administrator. |
+| `DescribeOrganizationConfiguration` | Reads organization auto-enable settings as the delegated administrator. |
+| `ListOrganizationAdminAccounts` | Lists the delegated Macie administrator for the organization. |
+
+
+Delegation is visible in both the management-account and delegated-account request scopes. Designating the delegated administrator enables Macie for that account in the Region, matching AWS Organizations integration behavior.
+
+`GetMacieSession` returns `ResourceNotFoundException` before Macie is enabled. Enabling an already enabled session or attempting incompatible administrator state returns `ConflictException`. Request validation and missing-resource behavior use the modeled `ValidationException` and `ResourceNotFoundException` responses.
+
+AWS also models provider-side `InternalServerException`, `ServiceQuotaExceededException`, and `ThrottlingException`; these are not injected artificially.
+
+See the [Amazon Macie API Reference](https://docs.aws.amazon.com/macie/latest/APIReference/Welcome.html).
diff --git a/mkdocs.yml b/mkdocs.yml
index 5b8637a68f..0d4c88bea9 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -120,6 +120,7 @@ nav:
- STS: services/sts.md
- Organizations: services/organizations.md
- IAM Identity Center (SSO Admin): services/ssoadmin.md
+ - Amazon Macie: services/macie2.md
- Control Tower: services/controltower.md
- AWS Service Catalog: services/service-catalog.md
- ElastiCache: services/elasticache.md
diff --git a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
index b1afd11ce9..afb1085032 100644
--- a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
+++ b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
@@ -710,6 +710,7 @@ public interface EmulatorConfig {
NetworkFirewallServiceConfig networkfirewall();
ServiceCatalogServiceConfig servicecatalog();
SsoAdminServiceConfig ssoadmin();
+ Macie2ServiceConfig macie2();
ServiceQuotasServiceConfig servicequotas();
RamServiceConfig ram();
ControlTowerServiceConfig controltower();
@@ -738,6 +739,11 @@ public interface EmulatorConfig {
boolean enabled();
}
+ interface Macie2ServiceConfig {
+ @WithDefault("true")
+ boolean enabled();
+ }
+
interface ApsServiceConfig {
@WithDefault("true")
boolean enabled();
diff --git a/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java b/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java
index 8f17688253..dfcc2d1156 100644
--- a/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java
+++ b/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java
@@ -32,6 +32,7 @@ import io.github.hectorvent.floci.services.ses.SesController;
import io.github.hectorvent.floci.services.appsync.AppSyncController;
import io.github.hectorvent.floci.services.rdsdata.RdsDataController;
import io.github.hectorvent.floci.services.guardduty.GuardDutyController;
+import io.github.hectorvent.floci.services.macie2.MacieController;
import io.github.hectorvent.floci.services.aps.ApsController;
import io.github.hectorvent.floci.services.controltower.ControlTowerControlController;
import io.github.hectorvent.floci.services.controltower.ControlTowerController;
@@ -408,6 +409,9 @@ public class ResolvedServiceCatalog {
null, null, 5000L, null, ServiceProtocol.JSON,
protocols(ServiceProtocol.JSON),
Set.of("SWBExternalService."), Set.of("sso"), Set.of(), Set.of()),
+ descriptor("macie2", "macie2", config.services().macie2().enabled(), true,
+ "macie2", config.storage().mode(), 5000L, null, ServiceProtocol.REST_JSON,
+ protocols(ServiceProtocol.REST_JSON), Set.of(), Set.of("macie2"), Set.of(), Set.of(MacieController.class)),
descriptor("autoscaling", "autoscaling", config.services().autoscaling().enabled(), true,
"autoscaling", config.storage().mode(), 5000L, AwsNamespaces.AUTOSCALING, ServiceProtocol.QUERY,
protocols(ServiceProtocol.QUERY),
diff --git a/src/main/java/io/github/hectorvent/floci/core/common/ServiceEnabledFilter.java b/src/main/java/io/github/hectorvent/floci/core/common/ServiceEnabledFilter.java
index d700d12876..b5ad940c1a 100644
--- a/src/main/java/io/github/hectorvent/floci/core/common/ServiceEnabledFilter.java
+++ b/src/main/java/io/github/hectorvent/floci/core/common/ServiceEnabledFilter.java
@@ -59,6 +59,8 @@ public class ServiceEnabledFilter implements ContainerRequestFilter {
}
return SigV4CredentialScope.serviceName(ctx.getHeaderString("Authorization"))
+ .or(() -> SigV4CredentialScope.serviceNameFromCredential(
+ ctx.getUriInfo().getQueryParameters().getFirst("X-Amz-Credential")))
.flatMap(catalog::byCredentialScope)
.map(descriptor -> new ResolvedRequest(
descriptor.externalKey(), protocolFor(claim, descriptor)))
diff --git a/src/main/java/io/github/hectorvent/floci/core/common/SigV4CredentialScope.java b/src/main/java/io/github/hectorvent/floci/core/common/SigV4CredentialScope.java
index 1dce84d5dc..5bafdd8768 100644
--- a/src/main/java/io/github/hectorvent/floci/core/common/SigV4CredentialScope.java
+++ b/src/main/java/io/github/hectorvent/floci/core/common/SigV4CredentialScope.java
@@ -26,4 +26,11 @@ public final class SigV4CredentialScope {
}
return Optional.empty();
}
+
+ public static Optional serviceNameFromCredential(String credential) {
+ if (credential == null) {
+ return Optional.empty();
+ }
+ return serviceName("Credential=" + credential);
+ }
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/guardduty/GuardDutyController.java b/src/main/java/io/github/hectorvent/floci/services/guardduty/GuardDutyController.java
index 8619267244..7f0243f3d8 100644
--- a/src/main/java/io/github/hectorvent/floci/services/guardduty/GuardDutyController.java
+++ b/src/main/java/io/github/hectorvent/floci/services/guardduty/GuardDutyController.java
@@ -6,7 +6,6 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
-import io.github.hectorvent.floci.services.guardduty.model.AdminAccount;
import io.github.hectorvent.floci.services.guardduty.model.MemberAccount;
import io.github.hectorvent.floci.services.guardduty.model.Detector;
import io.github.hectorvent.floci.services.guardduty.model.DetectorFeature;
@@ -216,23 +215,4 @@ public class GuardDutyController {
service.disableOrganizationAdminAccount(regionResolver.resolveRegion(headers), parse(body));
return Response.ok(objectMapper.createObjectNode()).build();
}
-
- @GET
- @Path("/admin")
- public Response listOrganizationAdminAccounts(
- @Context HttpHeaders headers,
- @QueryParam("maxResults") String maxResults,
- @QueryParam("nextToken") String nextToken) {
- GuardDutyService.Page page = service.listOrganizationAdminAccounts(
- regionResolver.resolveRegion(headers), maxResults, nextToken);
- ObjectNode response = objectMapper.createObjectNode();
- ArrayNode accounts = response.putArray("adminAccounts");
- for (AdminAccount account : page.items()) {
- accounts.add(objectMapper.valueToTree(account));
- }
- if (page.nextToken() != null) {
- response.put("nextToken", page.nextToken());
- }
- return Response.ok(response).build();
- }
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/macie2/MacieController.java b/src/main/java/io/github/hectorvent/floci/services/macie2/MacieController.java
new file mode 100644
index 0000000000..711dd8b495
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/macie2/MacieController.java
@@ -0,0 +1,89 @@
+package io.github.hectorvent.floci.services.macie2;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.github.hectorvent.floci.core.common.JsonErrorResponseUtils;
+import io.github.hectorvent.floci.core.common.RegionResolver;
+import io.github.hectorvent.floci.services.macie2.model.MacieState;
+import jakarta.inject.Inject;
+import jakarta.ws.rs.Consumes;
+import jakarta.ws.rs.GET;
+import jakarta.ws.rs.PATCH;
+import jakarta.ws.rs.POST;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.WebApplicationException;
+import jakarta.ws.rs.core.Context;
+import jakarta.ws.rs.core.HttpHeaders;
+import jakarta.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.Response;
+
+@Path("/")
+@Produces(MediaType.APPLICATION_JSON)
+@Consumes(MediaType.APPLICATION_JSON)
+public class MacieController {
+ private final MacieService macieService;
+ private final RegionResolver regionResolver;
+ private final ObjectMapper objectMapper;
+
+ @Inject
+ public MacieController(MacieService macieService, RegionResolver regionResolver, ObjectMapper objectMapper) {
+ this.macieService = macieService;
+ this.regionResolver = regionResolver;
+ this.objectMapper = objectMapper;
+ }
+
+ public Response listAdminInternal(String region) {
+ MacieState state = macieService.state(region);
+ var response = objectMapper.createObjectNode();
+ var accounts = response.putArray("adminAccounts");
+ if (state.getAdminAccountId() != null) {
+ accounts.addObject().put("accountId", state.getAdminAccountId()).put("status", "ENABLED");
+ }
+ return Response.ok(response).build();
+ }
+
+ @POST @Path("/admin")
+ public Response enableOrganizationAdminAccount(@Context HttpHeaders headers, String body) {
+ macieService.enableOrganizationAdminAccount(region(headers), readTree(body).path("adminAccountId").asText(null));
+ return empty();
+ }
+
+ @GET @Path("/macie")
+ public Response getMacieSession(@Context HttpHeaders headers) {
+ macieService.requireSession(region(headers));
+ var response = objectMapper.createObjectNode();
+ response.put("status", "ENABLED");
+ response.put("serviceRole", "arn:aws:iam::" + regionResolver.getAccountId() + ":role/aws-service-role/macie.amazonaws.com/AWSServiceRoleForAmazonMacie");
+ return Response.ok(response).build();
+ }
+
+ @POST @Path("/macie")
+ public Response enableMacie(@Context HttpHeaders headers, String body) {
+ macieService.enableMacie(region(headers));
+ return empty();
+ }
+
+ @PATCH @Path("/admin/configuration")
+ public Response updateOrganizationConfiguration(@Context HttpHeaders headers, String body) {
+ JsonNode request = readTree(body);
+ if (!request.has("autoEnable") || !request.get("autoEnable").isBoolean()) {
+ throw new io.github.hectorvent.floci.core.common.AwsException("ValidationException", "autoEnable is required.", 400);
+ }
+ macieService.updateOrganizationConfiguration(
+ region(headers), regionResolver.getAccountId(), request.path("autoEnable").asBoolean());
+ return empty();
+ }
+
+ @GET @Path("/admin/configuration")
+ public Response describeOrganizationConfiguration(@Context HttpHeaders headers) {
+ MacieState state = macieService.requireAdministratorSession(region(headers), regionResolver.getAccountId());
+ var response = objectMapper.createObjectNode();
+ response.put("autoEnable", state.isAutoEnable());
+ return Response.ok(response).build();
+ }
+
+ private String region(HttpHeaders headers) { return regionResolver.resolveRegion(headers); }
+ private Response empty() { return Response.ok(objectMapper.createObjectNode()).build(); }
+ private JsonNode readTree(String body) { try { return objectMapper.readTree(body == null || body.isBlank() ? "{}" : body); } catch (Exception e) { throw new WebApplicationException(JsonErrorResponseUtils.createSerializationErrorResponse()); } }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/services/macie2/MacieService.java b/src/main/java/io/github/hectorvent/floci/services/macie2/MacieService.java
new file mode 100644
index 0000000000..37386ae3b3
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/macie2/MacieService.java
@@ -0,0 +1,108 @@
+package io.github.hectorvent.floci.services.macie2;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.Resettable;
+import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
+import io.github.hectorvent.floci.core.storage.StorageFactory;
+import io.github.hectorvent.floci.services.macie2.model.MacieState;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+
+import java.util.Map;
+
+@ApplicationScoped
+public class MacieService implements Resettable {
+ private final AccountAwareStorageBackend states;
+
+ @Inject
+ public MacieService(StorageFactory storageFactory) {
+ this(storageFactory.create("macie2", "macie2-state.json",
+ new TypeReference