diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/S3ControlTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/S3ControlTest.java
index ba09cf4587..826cfcba03 100644
--- a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/S3ControlTest.java
+++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/S3ControlTest.java
@@ -17,6 +17,11 @@ import software.amazon.awssdk.services.s3control.model.ListTagsForResourceRespon
import software.amazon.awssdk.services.s3control.model.TagResourceRequest;
import software.amazon.awssdk.services.s3control.model.UntagResourceRequest;
import software.amazon.awssdk.services.s3control.model.S3ControlException;
+import software.amazon.awssdk.services.s3control.model.PutPublicAccessBlockRequest;
+import software.amazon.awssdk.services.s3control.model.GetPublicAccessBlockRequest;
+import software.amazon.awssdk.services.s3control.model.GetPublicAccessBlockResponse;
+import software.amazon.awssdk.services.s3control.model.DeletePublicAccessBlockRequest;
+import software.amazon.awssdk.services.s3control.model.PublicAccessBlockConfiguration;
import java.util.List;
import java.util.Map;
@@ -240,4 +245,68 @@ class S3ControlTest {
assertThat(tags).containsEntry("PlainArn", "works");
}
+
+ // --- Account-level Block Public Access (s3control Put/Get/DeletePublicAccessBlock) ---
+ // Exercised by AWS LZA's Custom::PutPublicAccessBlock custom resource during LoggingStack deploy.
+
+ @Test
+ @Order(8)
+ @DisplayName("putPublicAccessBlock: account-level config is set and read back")
+ void putAndGetAccountPublicAccessBlock() {
+ s3control.putPublicAccessBlock(PutPublicAccessBlockRequest.builder()
+ .accountId(ACCOUNT_ID)
+ .publicAccessBlockConfiguration(PublicAccessBlockConfiguration.builder()
+ .blockPublicAcls(true)
+ .ignorePublicAcls(true)
+ .blockPublicPolicy(true)
+ .restrictPublicBuckets(true)
+ .build())
+ .build());
+
+ GetPublicAccessBlockResponse resp = s3control.getPublicAccessBlock(
+ GetPublicAccessBlockRequest.builder().accountId(ACCOUNT_ID).build());
+
+ PublicAccessBlockConfiguration cfg = resp.publicAccessBlockConfiguration();
+ assertThat(cfg.blockPublicAcls()).isTrue();
+ assertThat(cfg.ignorePublicAcls()).isTrue();
+ assertThat(cfg.blockPublicPolicy()).isTrue();
+ assertThat(cfg.restrictPublicBuckets()).isTrue();
+ }
+
+ @Test
+ @Order(9)
+ @DisplayName("putPublicAccessBlock: absent flags default to false")
+ void putAccountPublicAccessBlockPartialDefaultsFalse() {
+ s3control.putPublicAccessBlock(PutPublicAccessBlockRequest.builder()
+ .accountId(ACCOUNT_ID)
+ .publicAccessBlockConfiguration(PublicAccessBlockConfiguration.builder()
+ .blockPublicAcls(true)
+ .build())
+ .build());
+
+ PublicAccessBlockConfiguration cfg = s3control.getPublicAccessBlock(
+ GetPublicAccessBlockRequest.builder().accountId(ACCOUNT_ID).build())
+ .publicAccessBlockConfiguration();
+ assertThat(cfg.blockPublicAcls()).isTrue();
+ assertThat(cfg.restrictPublicBuckets()).isFalse();
+ }
+
+ @Test
+ @Order(10)
+ @DisplayName("deletePublicAccessBlock: removes account-level config (subsequent get 404s)")
+ void deleteAccountPublicAccessBlock() {
+ s3control.putPublicAccessBlock(PutPublicAccessBlockRequest.builder()
+ .accountId(ACCOUNT_ID)
+ .publicAccessBlockConfiguration(PublicAccessBlockConfiguration.builder()
+ .blockPublicAcls(true).build())
+ .build());
+
+ s3control.deletePublicAccessBlock(DeletePublicAccessBlockRequest.builder()
+ .accountId(ACCOUNT_ID).build());
+
+ assertThatThrownBy(() -> s3control.getPublicAccessBlock(
+ GetPublicAccessBlockRequest.builder().accountId(ACCOUNT_ID).build()))
+ .isInstanceOf(S3ControlException.class)
+ .satisfies(e -> assertThat(((S3ControlException) e).statusCode()).isEqualTo(404));
+ }
}
diff --git a/docs/configuration/environment-variables.md b/docs/configuration/environment-variables.md
index d98ffec7cd..bd8378fe56 100644
--- a/docs/configuration/environment-variables.md
+++ b/docs/configuration/environment-variables.md
@@ -174,6 +174,7 @@ See [Initialization Hooks](./initialization-hooks.md) for lifecycle phases and s
|---|---|---|
| `FLOCI_SERVICES_S3_ENABLED` | `true` | Enable the S3 service |
| `FLOCI_SERVICES_S3_DEFAULT_PRESIGN_EXPIRY_SECONDS` | `3600` | Default pre-signed URL expiry when none is specified |
+| `FLOCI_SERVICES_S3_GLOBAL_BUCKET_NAMESPACE` | `false` | When `true`, bucket/object resolution spans every account's partition so a bucket created in one account is visible cross-account (a single global namespace), matching real S3's global bucket names. Off by default keeps buckets isolated per account |
### DynamoDB
diff --git a/docs/configuration/multi-account.md b/docs/configuration/multi-account.md
index b055dc3b25..49ceccb736 100644
--- a/docs/configuration/multi-account.md
+++ b/docs/configuration/multi-account.md
@@ -159,6 +159,12 @@ All services that use `StorageFactory` participate in account isolation automati
Background workers (Lambda event-source pollers, DynamoDB TTL sweeper, MSK readiness poller, OpenSearch readiness poller) iterate across all accounts internally and route writes back to the originating account. No cross-account data leaks through these async paths.
+**S3 exception — global bucket namespace.** S3 buckets are isolated per account by default like every
+other service, but real S3 bucket names are globally unique. Set
+`FLOCI_SERVICES_S3_GLOBAL_BUCKET_NAMESPACE=true` to make bucket/object resolution span every account's
+partition, so a bucket created in one account is visible cross-account — needed when a workload writes a
+bucket in one account and reads it from another (see [S3](../services/s3.md#global-bucket-namespace)).
+
## Signature Validation
Floci does not currently perform general SigV4 validation for `Authorization` headers. Only the access key ID matters for account resolution, so the secret access key can be any non-empty string.
diff --git a/docs/services/s3.md b/docs/services/s3.md
index c431bfd8d7..4d25f0e6a3 100644
--- a/docs/services/s3.md
+++ b/docs/services/s3.md
@@ -25,9 +25,12 @@
| **S3 Select** | SelectObjectContent |
| **Public Access Block** | PutPublicAccessBlock, GetPublicAccessBlock, DeletePublicAccessBlock |
| **Metrics** | PutBucketMetricsConfiguration, GetBucketMetricsConfiguration, ListBucketMetricsConfigurations, DeleteBucketMetricsConfiguration |
+| **Replication** | PutBucketReplication, GetBucketReplication, DeleteBucketReplication |
**RestoreObject** is accepted but stubbed: Floci validates the request and returns `202 Accepted`, but no restore state machine runs.
+**Replication** is configuration-only: the replication configuration is stored on the bucket and round-trips through `GetBucketReplication`, but no objects are actually replicated.
+
## Event Notifications
Browser and presigned POST uploads emit `s3:ObjectCreated:Post`, matching AWS S3. They do not emit
@@ -149,6 +152,21 @@ aws s3api select-object-content \
When `FLOCI_SERVICES_ATHENA_MOCK=true` is set, Athena queries are stubbed but floci-duck does **not** start. In that configuration, S3 Select uses the Java evaluator for CSV and JSON. Parquet queries will fail unless `FLOCI_SERVICES_DUCK_URL` points to an already-running floci-duck instance.
+## Global Bucket Namespace
+
+By default S3 buckets are isolated per account (see [Multi-Account Isolation](../configuration/multi-account.md)),
+so two accounts can each hold a bucket with the same name. Set
+`FLOCI_SERVICES_S3_GLOBAL_BUCKET_NAMESPACE=true` to make bucket and object resolution span every
+account's partition — a bucket created in one account then resolves cross-account, matching real S3
+where bucket names are globally unique. Enable this when a workload (for example an LZA log-archive or
+CDK asset bucket) is created in one account and read from another.
+
+**Why the flag exists, and what it trades away.** Floci partitions every resource by the caller's account, which is the right model for services whose names are account-scoped in AWS. S3 bucket names are not: they are unique across all accounts, a bucket lives in exactly one owning account, and whether another account may touch it is decided by policy rather than by the name being unreachable. A hard per-account partition therefore lets two accounts hold different buckets under one name — a state AWS cannot reach — and makes a legitimate cross-account call fail with `NoSuchBucket` instead of being authorized or denied on its merits. With the flag on, a caller that names another account's bucket resolves it and only IAM and bucket-policy evaluation stand between the caller and the object: AWS-faithful, but stricter than the implicit isolation Floci gives you elsewhere — **provided both `FLOCI_SERVICES_IAM_ENFORCEMENT_ENABLED` (identity-policy checks, applied before the request reaches S3) and `FLOCI_SERVICES_S3_ENFORCE_AUTH` (the S3-specific flag that gates bucket-policy evaluation itself, in `S3Service.authorizeS3Read`/`authorizeS3Write`) are also `true`**. Both default to `false`, and bucket-policy evaluation in particular is a no-op while `FLOCI_SERVICES_S3_ENFORCE_AUTH` is off — regardless of the IAM flag — so in the default configuration enabling the global namespace does not trade per-account isolation for a policy-gated boundary — it removes the only isolation Floci gives S3 for that bucket and replaces it with nothing. Mutations are written back to the bucket's owning account rather than forked into the caller's, and `ListBuckets`/`ListObjects` stay owner-scoped, so the flag never reassigns ownership or leaks a bucket inventory. It is off by default — turn it on when emulating a multi-account estate whose real behaviour depends on the global namespace, and leave it off when the per-account partition is the isolation you are relying on. Account-scoped S3 state, notably the account-level Block Public Access configuration, is never widened by this flag. Note also that retrofitting a global namespace onto state that was previously partitioned per account means that if two accounts already hold a bucket under the same name — a state real AWS can't reach, but Floci's prior per-account isolation could — resolution picks whichever account's copy the backend happens to iterate to first; this is unlikely to be reachable on a fresh LZA-driven account structure, but is worth knowing if you enable the flag on an estate with pre-existing same-name buckets.
+
+## Account-Level Block Public Access
+
+The s3control `PutPublicAccessBlock`, `GetPublicAccessBlock` and `DeletePublicAccessBlock` operations are keyed by the `x-amz-account-id` header, stored per account, and persisted like the rest of S3's state so a restart does not silently drop the control. As in AWS, the header must name the caller's own account; a mismatch returns `AccessDenied` (403). Floci keeps one deliberate exception: the configured default (management) account may act on any account, because Floci's launched Lambdas run on placeholder credentials that resolve to the management account instead of assuming a role in the target account — which is how LZA's `Custom::PutPublicAccessBlock` resource reaches this API.
+
## Not Implemented
These AWS S3 features have no handler in Floci. Calls will return an error (typically `404` or `NoSuchBucket`-style):
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 8ee566d0c1..4bc2418db8 100644
--- a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
+++ b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
@@ -934,6 +934,37 @@ public interface EmulatorConfig {
@WithDefault("3600")
int defaultPresignExpirySeconds();
+
+ /**
+ * When true, S3 bucket/object existence resolution spans every account's partition,
+ * modelling AWS's globally-unique bucket namespace (a bucket owned by one account is
+ * reachable cross-account). Listing (ListBuckets/ListObjects) stays owner-scoped.
+ * Default false preserves per-account bucket isolation.
+ *
+ *
Why this widening is deliberate, and what it costs. Floci's default
+ * is to partition every resource by the caller's account, which is the right model for
+ * services whose names are account-scoped in AWS. S3 bucket names are not: they are unique
+ * across all accounts and partitions, a bucket lives in exactly one owning account, and
+ * whether another account may touch it is decided by policy, not by the name being
+ * unreachable. Emulating that with a hard per-account partition makes two accounts able to
+ * hold different buckets under one name — a state AWS cannot reach — and makes a legitimate
+ * cross-account call (LZA's central logging bucket, a custom-resource Lambda calling back
+ * under the management account) fail with {@code NoSuchBucket} instead of being authorized
+ * or denied on its merits. This flag opts into the AWS-faithful namespace instead.
+ *
+ *
The trade-off is that account partitioning stops being a second, implicit line of
+ * defence for S3: with the flag on, a caller that names another account's bucket resolves
+ * it, and only IAM/bucket-policy evaluation stands between the caller and the object —
+ * exactly as in AWS, but stricter than Floci's default elsewhere. Mutations are written
+ * back to the bucket's owning account rather than forked into the caller's, and
+ * listing stays owner-scoped, so the flag never reassigns ownership or leaks a bucket
+ * inventory. It is off by default: turn it on when emulating a multi-account estate whose
+ * real behaviour depends on the global namespace, and leave it off when the per-account
+ * partition is the isolation you are relying on. Account-scoped S3 state — notably the
+ * account-level Block Public Access configuration — is never widened by this flag.
+ */
+ @WithDefault("false")
+ boolean globalBucketNamespace();
}
interface DynamoDbServiceConfig {
diff --git a/src/main/java/io/github/hectorvent/floci/services/s3/S3ControlController.java b/src/main/java/io/github/hectorvent/floci/services/s3/S3ControlController.java
index 945077dbf3..a418c7ad6b 100644
--- a/src/main/java/io/github/hectorvent/floci/services/s3/S3ControlController.java
+++ b/src/main/java/io/github/hectorvent/floci/services/s3/S3ControlController.java
@@ -1,15 +1,20 @@
package io.github.hectorvent.floci.services.s3;
+import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.AwsNamespaces;
+import io.github.hectorvent.floci.core.common.RequestContext;
import io.github.hectorvent.floci.core.common.XmlBuilder;
import io.github.hectorvent.floci.core.common.XmlParser;
+import jakarta.enterprise.context.ContextNotActiveException;
+import jakarta.enterprise.inject.Instance;
import jakarta.inject.Inject;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.HeaderParam;
import jakarta.ws.rs.POST;
+import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
@@ -44,10 +49,16 @@ public class S3ControlController {
private static final String AMZ_ID_2 = "x-amz-id-2";
private final S3Service s3Service;
+ private final Instance requestContextInstance;
+ private final String defaultAccountId;
@Inject
- public S3ControlController(S3Service s3Service) {
+ public S3ControlController(S3Service s3Service,
+ Instance requestContextInstance,
+ EmulatorConfig config) {
this.s3Service = s3Service;
+ this.requestContextInstance = requestContextInstance;
+ this.defaultAccountId = config.defaultAccountId();
}
/**
@@ -114,6 +125,143 @@ public class S3ControlController {
return Response.ok(xml).build();
}
+ /**
+ * PutPublicAccessBlock — sets the account-level S3 Block Public Access configuration.
+ *
+ * Account-scoped (keyed by the {@code x-amz-account-id} header), distinct from the
+ * bucket-level operation. AWS LZA's {@code Custom::PutPublicAccessBlock} custom resource
+ * calls this for every governed account during the LoggingStack deploy; without it the
+ * custom-resource Lambda reports FAILED and the stack rolls back.
+ *
+ * PUT /v20180820/configuration/publicAccessBlock
+ * Header: x-amz-account-id
+ * Body: {@code } with the four boolean flags
+ */
+ @PUT
+ @Path("/configuration/publicAccessBlock")
+ @Consumes(MediaType.WILDCARD)
+ public Response putPublicAccessBlock(
+ @HeaderParam("x-amz-account-id") String accountId,
+ String body) {
+ try {
+ requireCallerMayActOnAccount(accountId);
+ if (!"PublicAccessBlockConfiguration".equals(XmlParser.rootElementName(body))) {
+ throw new AwsException("MalformedXML",
+ "The XML you provided was not well-formed or did not validate against our published schema.",
+ 400);
+ }
+ s3Service.putAccountPublicAccessBlock(accountId, canonicalPublicAccessBlockXml(body));
+ return Response.ok().build();
+ } catch (AwsException e) {
+ return xmlErrorResponse(e);
+ }
+ }
+
+ /**
+ * GetPublicAccessBlock — returns the account-level S3 Block Public Access configuration.
+ *
+ * GET /v20180820/configuration/publicAccessBlock
+ * Header: x-amz-account-id
+ */
+ @GET
+ @Path("/configuration/publicAccessBlock")
+ public Response getPublicAccessBlock(
+ @HeaderParam("x-amz-account-id") String accountId) {
+ try {
+ requireCallerMayActOnAccount(accountId);
+ return Response.ok(s3Service.getAccountPublicAccessBlock(accountId)).build();
+ } catch (AwsException e) {
+ return xmlErrorResponse(e);
+ }
+ }
+
+ /**
+ * DeletePublicAccessBlock — removes the account-level S3 Block Public Access configuration.
+ *
+ * DELETE /v20180820/configuration/publicAccessBlock
+ * Header: x-amz-account-id
+ */
+ @DELETE
+ @Path("/configuration/publicAccessBlock")
+ public Response deletePublicAccessBlock(
+ @HeaderParam("x-amz-account-id") String accountId) {
+ try {
+ requireCallerMayActOnAccount(accountId);
+ s3Service.deleteAccountPublicAccessBlock(accountId);
+ return Response.noContent().build();
+ } catch (AwsException e) {
+ return xmlErrorResponse(e);
+ }
+ }
+
+ /**
+ * Rejects an {@code x-amz-account-id} that names an account the caller has no claim on.
+ *
+ * Block Public Access is a security control, and the header alone decides which account's
+ * configuration an operation reads, overwrites or deletes. Without this check any caller could
+ * manage any account's configuration by setting one header. AWS s3control answers
+ * {@code AccessDenied} when the header does not match the caller's own account, because there
+ * a cross-account call is made with credentials assumed into the target account, so
+ * the header and the caller always agree.
+ *
+ *
The emulator keeps one deliberate exception: the configured default (management) account
+ * may act on any account. Floci's launched Lambdas run on placeholder credentials that resolve
+ * to the management account rather than assuming a role in the target account, so LZA's
+ * {@code Custom::PutPublicAccessBlock} resource legitimately arrives as management-caller,
+ * governed-account-header. This is the same allowance {@code S3Service.mutateBucket} already
+ * makes for {@code Custom::S3PutBucketReplication}. Every other cross-account combination is
+ * denied.
+ *
+ *
A blank header is left to the service, which raises the modelled {@code InvalidRequest}.
+ */
+ private void requireCallerMayActOnAccount(String accountId) {
+ if (accountId == null || accountId.isBlank()) {
+ return;
+ }
+ String caller = callerAccountId();
+ if (accountId.equals(caller) || defaultAccountId.equals(caller)) {
+ return;
+ }
+ throw new AwsException("AccessDenied", "Access Denied", 403);
+ }
+
+ /**
+ * The caller's account as resolved by {@code AccountContextFilter}, falling back to the
+ * configured default outside a request scope — the same resolution
+ * {@code AccountAwareStorageBackend} uses to pick a storage partition.
+ */
+ private String callerAccountId() {
+ if (requestContextInstance != null) {
+ try {
+ String accountId = requestContextInstance.get().getAccountId();
+ if (accountId != null && !accountId.isBlank()) {
+ return accountId;
+ }
+ } catch (ContextNotActiveException ignored) {
+ // outside request scope — fall through to the default account
+ }
+ }
+ return defaultAccountId;
+ }
+
+ /**
+ * Normalises an incoming PublicAccessBlockConfiguration body into a canonical, namespaced
+ * document so read-back is well-formed regardless of the client's request formatting or
+ * namespace. Absent flags default to false, matching the AWS API.
+ */
+ private static String canonicalPublicAccessBlockXml(String requestXml) {
+ String xml = requestXml == null ? "" : requestXml;
+ return new XmlBuilder()
+ .raw("")
+ .start("PublicAccessBlockConfiguration", AwsNamespaces.S3_CONTROL)
+ .elem("BlockPublicAcls", XmlParser.extractFirst(xml, "BlockPublicAcls", "false"))
+ .elem("IgnorePublicAcls", XmlParser.extractFirst(xml, "IgnorePublicAcls", "false"))
+ .elem("BlockPublicPolicy", XmlParser.extractFirst(xml, "BlockPublicPolicy", "false"))
+ .elem("RestrictPublicBuckets", XmlParser.extractFirst(xml, "RestrictPublicBuckets", "false"))
+ .end("PublicAccessBlockConfiguration")
+ .build();
+ }
+
/**
* TagResource — replaces all tags on the specified S3 bucket.
*
diff --git a/src/main/java/io/github/hectorvent/floci/services/s3/S3Service.java b/src/main/java/io/github/hectorvent/floci/services/s3/S3Service.java
index a1db068fae..38b3200cfc 100644
--- a/src/main/java/io/github/hectorvent/floci/services/s3/S3Service.java
+++ b/src/main/java/io/github/hectorvent/floci/services/s3/S3Service.java
@@ -8,6 +8,7 @@ import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.XmlBuilder;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.core.common.Resettable;
+import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.iam.IamService;
@@ -33,8 +34,10 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
+import java.nio.file.AtomicMoveNotSupportedException;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.time.Instant;
@@ -91,6 +94,15 @@ public class S3Service implements Resettable, ResourceProvider {
}
private final ConcurrentHashMap> memoryMultipartStore = new ConcurrentHashMap<>();
private final ConcurrentHashMap multipartUploads = new ConcurrentHashMap<>();
+ // Account-level (S3 Control) Block Public Access config, one entry per AWS account.
+ // Distinct from the bucket-level configuration held on each Bucket. Block Public Access is a
+ // security control that LZA applies once per governed account, so it is StorageFactory-backed
+ // like every other piece of S3 state rather than held in memory: a restart must not silently
+ // drop it. Always addressed through the explicit *ForAccount overloads — the account comes
+ // from the validated x-amz-account-id header, and the account namespace here is never global
+ // (globalBucketNamespace widens bucket resolution only, never this).
+ private final AccountAwareStorageBackend accountPublicAccessBlockStore;
+ private static final String ACCOUNT_PUBLIC_ACCESS_BLOCK_KEY = "publicAccessBlock";
private final SqsService sqsService;
private final SnsService snsService;
@@ -104,6 +116,7 @@ public class S3Service implements Resettable, ResourceProvider {
private final ObjectMapper objectMapper;
private final boolean enforceAuth;
private final IamService iamService;
+ private final boolean globalBucketNamespace;
@Inject
public S3Service(StorageFactory storageFactory, EmulatorConfig config,
@@ -121,13 +134,17 @@ public class S3Service implements Resettable, ResourceProvider {
storageFactory.create("s3", "s3-objects.json",
new TypeReference