fix(eventbridgev2): name webhook hosts in the server certificate (#9581)

With TLS on, CreateEventSource and DescribeEventSource add *.c01.events-webhook.<region>.<host> to Floci's generated server certificate, so a client that verifies the certificate accepts a source's webhook URL. One wildcard covers every source of a Region. The source is stored under the service lock and the certificate is reissued outside it, as the API Gateway, Cognito and IoT custom domain operations do. A user-provided certificate is not changed. The TLS handshake test helper is shared through TlsTestSupport.
This commit is contained in:
TATSUNO “Taz” Yasuhiro authored and GitHub committed 2026-11-27 07:04:04 -04:00
1 parent dd6835a9a8
commit c67a520e4e
12 files changed
+184 -34

No files matched your search

+1 -1
View File
@@ -104,7 +104,7 @@ A wildcard SAN matches one label only, so `*.localhost.floci.io` covers `api.loc
Only a name under a local suffix is accepted: `localhost`, `localhost.floci.io`, `localhost.localstack.cloud`, `FLOCI_HOSTNAME`, the `FLOCI_BASE_URL` host, and every `FLOCI_DNS_EXTRA_SUFFIXES` entry. Any other name is refused with a warning, so a Floci certificate can never cover a public name. This only applies to the generated certificate; a user-provided one is never changed.
Names are added by the custom domain operations: API Gateway `CreateDomainName`, IoT Core `CreateDomainConfiguration` with a `domainName`, and Cognito `CreateUserPoolDomain` with a `CustomDomainConfig`. The AWS operation succeeds either way; a name outside the local suffixes, or a reissue that fails, is logged as a warning.
Names are added by the custom domain operations: API Gateway `CreateDomainName`, IoT Core `CreateDomainConfiguration` with a `domainName`, and Cognito `CreateUserPoolDomain` with a `CustomDomainConfig`. EventBridge V2 `CreateEventSource` and `DescribeEventSource` add `*.c01.events-webhook.<region>.<host>`, which covers every webhook source of that Region. The AWS operation succeeds either way; a name outside the local suffixes, or a reissue that fails, is logged as a warning.
### Containers Floci Launches
+2
View File
@@ -130,6 +130,8 @@ Floci serves event sources of the `WebhookEventsConfiguration` kind. A request w
- A source name is unique per account and Region, across event buses.
- The webhook URL is `<scheme>://<host id>.c01.events-webhook.<region>.<authority>/<token>/`. The scheme and
authority are those of Floci's base URL. A POST to it publishes an event, as described below.
With TLS on, Floci's generated certificate names the webhook hosts of a Region once a source is created or
described there. A user-provided certificate must name `*.c01.events-webhook.<region>.<host>` itself.
- Each source has a Secrets Manager secret named `events-webhook!<uuid>`, owned by `events-webhook`. It holds the
static token, the HMAC secret, or the Basic credential as `{"username":"...","password":"..."}`. A credential
the request leaves out is generated. The secret ARN is in `EventSourceDetails.WebhookDetails.SecretArn`.
@@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.floci.aws.config.EmulatorConfig;
import io.floci.aws.config.TlsCertificateManager;
import io.floci.aws.core.common.AwsArnUtils;
import io.floci.aws.core.common.AwsException;
import io.floci.aws.core.common.Digests;
@@ -46,6 +47,7 @@ import java.util.function.Function;
@ApplicationScoped
public class EventBridgeV2EventSources implements Resettable {
private static final String OWNING_SERVICE = "events-webhook";
private static final String WEBHOOK_HOST_LABELS = "c01.events-webhook.";
private static final Logger LOG = Logger.getLogger(EventBridgeV2EventSources.class);
private static final int GENERATED_SECRET_BYTES = 32;
@@ -64,22 +66,26 @@ public class EventBridgeV2EventSources implements Resettable {
private final URI baseUrl;
private final SecureRandom random = new SecureRandom();
private final WebhookDeduplication deduplication;
private final TlsCertificateManager certificateManager;
@Inject
public EventBridgeV2EventSources(StorageFactory storageFactory, SecretsManagerService secrets,
RegionResolver regionResolver, EmulatorConfig config) {
RegionResolver regionResolver, EmulatorConfig config,
TlsCertificateManager certificateManager) {
this(storageFactory.create("eventbridgev2", "eventbridgev2-event-sources.json",
new TypeReference<Map<String, EventSourceV2>>() {}),
secrets, regionResolver, Clock.systemUTC(), config.effectiveBaseUrl());
secrets, regionResolver, Clock.systemUTC(), config.effectiveBaseUrl(), certificateManager);
}
EventBridgeV2EventSources(AccountAwareStorageBackend<EventSourceV2> sources, SecretsManagerService secrets,
RegionResolver regionResolver, Clock clock, String baseUrl) {
RegionResolver regionResolver, Clock clock, String baseUrl,
TlsCertificateManager certificateManager) {
this.sources = sources;
this.secrets = secrets;
this.regionResolver = regionResolver;
this.clock = clock;
this.baseUrl = URI.create(baseUrl);
this.certificateManager = certificateManager;
this.deduplication = new WebhookDeduplication(clock);
}
@@ -377,11 +383,23 @@ public class EventBridgeV2EventSources implements Resettable {
/** The URL a source receives its events at, in the scheme of Floci's own base URL. */
String webhookUrl(EventSourceV2 source) {
return baseUrl.getScheme() + "://" + source.getWebhookHostId() + ".c01.events-webhook."
+ AwsArnUtils.parse(source.getArn()).region() + "." + baseUrl.getAuthority() + "/"
return baseUrl.getScheme() + "://" + source.getWebhookHostId() + "."
+ webhookDomain(AwsArnUtils.parse(source.getArn()).region()) + baseUrl.getAuthority() + "/"
+ source.getWebhookToken() + "/";
}
private static String webhookDomain(String region) {
return WEBHOOK_HOST_LABELS + region + ".";
}
/**
* Has the server certificate name the webhook hosts of the Region. Blocks until the HTTPS listener has
* switched certificates, so call it with no lock held.
*/
void coverWebhookHosts(String region) {
certificateManager.ensureHost("*." + webhookDomain(region) + baseUrl.getHost());
}
record LocatedSource(String accountId, EventSourceV2 source) {
}
@@ -414,11 +414,23 @@ public class EventBridgeV2Service implements Resettable {
// ──────────────────────────── Event sources ────────────────────────────
public synchronized EventSourceV2 createEventSource(JsonNode request, String region) {
public EventSourceV2 createEventSource(JsonNode request, String region) {
EventSourceV2 source = storeEventSource(request, region);
eventSources.coverWebhookHosts(region);
return source;
}
private synchronized EventSourceV2 storeEventSource(JsonNode request, String region) {
return eventSources.create(request, region, name -> buses.get(storageKey(region, name)));
}
public synchronized EventSourceV2 describeEventSource(JsonNode request, String region) {
public EventSourceV2 describeEventSource(JsonNode request, String region) {
EventSourceV2 source = findEventSource(request, region);
eventSources.coverWebhookHosts(region);
return source;
}
private synchronized EventSourceV2 findEventSource(JsonNode request, String region) {
return eventSources.describe(request, region);
}
@@ -7,15 +7,9 @@ import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.junit.jupiter.api.Test;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SNIHostName;
import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLSocket;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.URI;
import java.security.cert.X509Certificate;
import java.util.List;
import java.util.Set;
import static io.floci.aws.config.TlsTestSupport.dnsSans;
@@ -82,22 +76,8 @@ class TlsEnsureHostIntegrationTest {
handshake(true);
}
/**
* Connects by IP so the JDK has no peer host of its own and verifies the certificate against
* the SNI name; the fixture leaf carries no {@code 127.0.0.1} SAN, so nothing else can match.
*/
private X509Certificate handshake(boolean verifyIdentity) throws Exception {
try (SSLSocket socket = (SSLSocket) trustOnlyTheCa().getSocketFactory().createSocket()) {
socket.connect(new InetSocketAddress(InetAddress.getByName("127.0.0.1"), sslPort), 5000);
SSLParameters params = socket.getSSLParameters();
params.setServerNames(List.of(new SNIHostName(NEW_HOST)));
if (verifyIdentity) {
params.setEndpointIdentificationAlgorithm("HTTPS");
}
socket.setSSLParameters(params);
socket.startHandshake();
return (X509Certificate) socket.getSession().getPeerCertificates()[0];
}
return TlsTestSupport.handshake(sslPort, NEW_HOST, verifyIdentity);
}
/** A plain HTTPS client with the JDK's default hostname verifier, for the configured name. */
@@ -0,0 +1,58 @@
package io.floci.aws.config;
import io.floci.aws.testing.AwsTestClients;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.eventbridgev2.EventBridgeV2Client;
import software.amazon.awssdk.services.eventbridgev2.model.CreateEventSourceResponse;
import software.amazon.awssdk.services.eventbridgev2.model.EventSourceConfiguration;
import software.amazon.awssdk.services.eventbridgev2.model.WebhookAuthConfiguration;
import javax.net.ssl.SSLHandshakeException;
import java.net.URI;
import static io.floci.aws.config.TlsTestSupport.handshake;
import static io.restassured.RestAssured.given;
import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* A client that trusts only the local CA and verifies the host name accepts the webhook URL that
* CreateEventSource answers, with no restart in between.
*/
@QuarkusTest
@TestProfile(SelfSignedTlsProfile.class)
class TlsEventBridgeWebhookHostIntegrationTest {
private static final String ROLE = "arn:aws:iam::000000000000:role/WebhookRole";
private static final Region REGION = Region.EU_WEST_2;
@ConfigProperty(name = "quarkus.http.test-ssl-port", defaultValue = "0")
int sslPort;
@Test
void theHostOfTheWebhookUrlCreateEventSourceReturnsPassesIdentityVerification() throws Exception {
String suffix = Long.toString(System.nanoTime(), 36);
try (EventBridgeV2Client events = AwsTestClients.create(EventBridgeV2Client.builder(), "000000000000",
REGION)) {
String bus = events.createEventBus(request -> request.name("v2-tls-" + suffix)).eventBusArn();
String probe = "probe.c01.events-webhook.eu-west-2.localhost";
assertThrows(SSLHandshakeException.class, () -> handshake(sslPort, probe, true),
"precondition: the Region has no webhook host in the certificate");
CreateEventSourceResponse created = events.createEventSource(request -> request.name("hook-" + suffix)
.eventBusArn(bus)
.configuration(EventSourceConfiguration.fromWebhookEventsConfiguration(webhook -> webhook
.roleArn(ROLE).authConfiguration(WebhookAuthConfiguration.builder()
.staticTokenAuthConfiguration(token -> token.tokenHttpHeader("X-Token")
.secretValue("s3cret-token")).build()))));
String host = URI.create(created.eventSourceDetails().webhookDetails().webhookUrl()).getHost();
handshake(sslPort, host, true);
} finally {
given().when().post("/_floci/state/reset").then().statusCode(200);
}
}
}
@@ -4,7 +4,12 @@ import io.floci.aws.services.acm.CertificateGenerator;
import io.floci.aws.services.acm.model.KeyAlgorithm;
import io.floci.aws.testing.TlsTrust;
import javax.net.ssl.SNIHostName;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLSocket;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.cert.X509Certificate;
@@ -36,4 +41,22 @@ final class TlsTestSupport {
}
return names;
}
/**
* Connects by IP so the JDK has no peer host of its own and verifies the certificate against the SNI
* name. The fixture leaf carries no {@code 127.0.0.1} SAN, so nothing else can match.
*/
static X509Certificate handshake(int port, String serverName, boolean verifyIdentity) throws Exception {
try (SSLSocket socket = (SSLSocket) trustOnlyTheCa().getSocketFactory().createSocket()) {
socket.connect(new InetSocketAddress(InetAddress.getByName("127.0.0.1"), port), 5000);
SSLParameters params = socket.getSSLParameters();
params.setServerNames(List.of(new SNIHostName(serverName)));
if (verifyIdentity) {
params.setEndpointIdentificationAlgorithm("HTTPS");
}
socket.setSSLParameters(params);
socket.startHandshake();
return (X509Certificate) socket.getSession().getPeerCertificates()[0];
}
}
}
@@ -4,8 +4,10 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.dataformat.cbor.CBORFactory;
import io.floci.aws.config.TlsCertificateManager;
import io.floci.aws.testing.AwsTestClients;
import io.floci.aws.testing.RestAssuredJsonUtils;
import io.quarkus.test.InjectMock;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -35,6 +37,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.verify;
/** Webhook event sources of EventBridge V2 and the managed secrets that hold their credentials, through the SDKs. */
@QuarkusTest
@@ -43,11 +46,28 @@ class EventBridgeV2EventSourceIntegrationTest {
private static final String ROLE = "arn:aws:iam::000000000000:role/WebhookRole";
private static final ObjectMapper CBOR_MAPPER = new ObjectMapper(new CBORFactory());
@InjectMock
TlsCertificateManager certificateManager;
@BeforeAll
static void configureContentTypes() {
RestAssuredJsonUtils.configureAwsContentTypes();
}
@Test
void createEventSourceAsksTheCertificateToNameTheWebhookHostsOfTheRegion() {
String suffix = suffix();
try (EventBridgeV2Client events = events()) {
String bus = events.createEventBus(request -> request.name("v2-tls-" + suffix)).eventBusArn();
events.createEventSource(request -> request.name("hook-" + suffix).eventBusArn(bus)
.configuration(EventSourceConfiguration.fromWebhookEventsConfiguration(webhook -> webhook
.roleArn(ROLE).authConfiguration(staticToken("X-Token", "s3cret-token")))));
verify(certificateManager).ensureHost("*.c01.events-webhook.us-east-1.localhost");
}
}
@Test
void aWebhookEventSourceLivesThroughCreateDescribeUpdateAndDelete() {
String suffix = suffix();
@@ -3,6 +3,7 @@ package io.floci.aws.services.eventbridgev2;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.floci.aws.config.TlsCertificateManager;
import io.floci.aws.core.common.AwsException;
import io.floci.aws.core.common.PaginatedResult;
import io.floci.aws.core.common.RegionResolver;
@@ -54,6 +55,7 @@ class EventBridgeV2EventSourcesTest {
private static final String BASIC_AUTH = "{\"BasicHttpAuthConfiguration\":{}}";
private SecretsManagerService secrets;
private TlsCertificateManager certificateManager;
private EventBridgeV2Service service;
private TestClock clock;
private String bus;
@@ -69,8 +71,10 @@ class EventBridgeV2EventSourcesTest {
when(secrets.describeSecret(any(), any())).thenReturn(new Secret());
clock = new TestClock(NOW);
RegionResolver regionResolver = new RegionResolver(REGION, ACCOUNT);
certificateManager = mock(TlsCertificateManager.class);
EventBridgeV2EventSources eventSources = new EventBridgeV2EventSources(
AccountAwareStorageBackend.inMemory(ACCOUNT), secrets, regionResolver, clock, "http://floci.test:4566");
AccountAwareStorageBackend.inMemory(ACCOUNT), secrets, regionResolver, clock, "http://floci.test:4566",
certificateManager);
service = new EventBridgeV2Service(AccountAwareStorageBackend.inMemory(ACCOUNT),
AccountAwareStorageBackend.inMemory(ACCOUNT), regionResolver, mock(EventBridgeV2Delivery.class),
eventSources, clock, true);
@@ -95,6 +99,33 @@ class EventBridgeV2EventSourcesTest {
assertTrue(source.getWebhookHostId().startsWith("a"));
}
@Test
void createAsksTheCertificateToNameTheWebhookHostsOfTheRegion() {
service.createEventSource(create("hook", bus, STATIC_AUTH), REGION);
verify(certificateManager).ensureHost("*.c01.events-webhook.us-east-1.floci.test");
}
@Test
void refusedCreatesAskForNoCertificateName() {
assertThrows(AwsException.class, () -> service.createEventSource(
create("hook", "arn:aws:events:us-east-1:000000000000:event-bus/missing", STATIC_AUTH), REGION));
service.createEventSource(create("hook", bus, STATIC_AUTH), REGION);
assertThrows(AwsException.class, () -> service.createEventSource(
create("hook", bus, BASIC_AUTH), REGION));
verify(certificateManager, times(1)).ensureHost(any());
}
@Test
void describeAsksTheCertificateToNameTheWebhookHostsOfTheRegion() {
EventSourceV2 source = service.createEventSource(create("hook", bus, STATIC_AUTH), REGION);
service.describeEventSource(json("{\"EventSourceArn\":\"" + source.getArn() + "\"}"), REGION);
verify(certificateManager, times(2)).ensureHost("*.c01.events-webhook.us-east-1.floci.test");
}
@Test
void createKeepsTheSecretOutOfTheStoredConfiguration() {
EventSourceV2 source = service.createEventSource(create("hook", bus,
@@ -369,7 +400,8 @@ class EventBridgeV2EventSourcesTest {
IllegalStateException failure = new IllegalStateException("disk full");
doThrow(failure).when(failing).put(any(), any());
EventBridgeV2EventSources eventSources = new EventBridgeV2EventSources(failing, secrets,
new RegionResolver(REGION, ACCOUNT), clock, "http://floci.test:4566");
new RegionResolver(REGION, ACCOUNT), clock, "http://floci.test:4566",
certificateManager);
EventBusV2 existing = new EventBusV2();
existing.setArn(bus);
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import io.floci.aws.config.TlsCertificateManager;
import io.floci.aws.core.common.AwsException;
import io.floci.aws.core.common.PaginatedResult;
import io.floci.aws.core.common.RegionResolver;
@@ -64,7 +65,7 @@ class EventBridgeV2ServiceTest {
Clock clock = Clock.fixed(NOW, ZoneOffset.UTC);
EventBridgeV2EventSources eventSources = new EventBridgeV2EventSources(
AccountAwareStorageBackend.inMemory(ACCOUNT), mock(SecretsManagerService.class), regionResolver, clock,
"http://floci.test:4566");
"http://floci.test:4566", mock(TlsCertificateManager.class));
service = new EventBridgeV2Service(AccountAwareStorageBackend.inMemory(ACCOUNT),
AccountAwareStorageBackend.inMemory(ACCOUNT), regionResolver, delivery, eventSources, clock, true);
}
@@ -2,6 +2,7 @@ package io.floci.aws.services.eventbridgev2;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.floci.aws.config.TlsCertificateManager;
import io.floci.aws.core.common.AwsException;
import io.floci.aws.core.common.RegionResolver;
import io.floci.aws.core.storage.AccountAwareStorageBackend;
@@ -86,7 +87,8 @@ class EventBridgeV2WebhooksTest {
clock = new ManualClock(Instant.parse("2026-11-25T06:00:00.123Z"));
RegionResolver regionResolver = new RegionResolver(REGION, ACCOUNT);
sources = new EventBridgeV2EventSources(
AccountAwareStorageBackend.inMemory(ACCOUNT), secrets, regionResolver, clock, "http://floci.test:4566");
AccountAwareStorageBackend.inMemory(ACCOUNT), secrets, regionResolver, clock, "http://floci.test:4566",
mock(TlsCertificateManager.class));
service = new EventBridgeV2Service(AccountAwareStorageBackend.inMemory(ACCOUNT),
AccountAwareStorageBackend.inMemory(ACCOUNT), regionResolver, delivery, sources, clock, true);
webhooks = new EventBridgeV2Webhooks(service, sources, secrets, clock);
@@ -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.floci.aws.config.EmulatorConfig;
import io.floci.aws.config.TlsCertificateManager;
import io.floci.aws.core.common.RegionResolver;
import io.floci.aws.core.storage.AccountAwareStorageBackend;
import io.floci.aws.core.storage.StorageFactory;
@@ -49,7 +50,8 @@ final class WebhookSourceFixture {
secrets = new SecretsManagerService(factory, config, regionResolver, null, MAPPER, null);
clock = new ManualClock(NOW);
EventBridgeV2EventSources sources = new EventBridgeV2EventSources(
AccountAwareStorageBackend.inMemory(ACCOUNT), secrets, regionResolver, clock, "http://floci.test:4566");
AccountAwareStorageBackend.inMemory(ACCOUNT), secrets, regionResolver, clock, "http://floci.test:4566",
mock(TlsCertificateManager.class));
service = new EventBridgeV2Service(AccountAwareStorageBackend.inMemory(ACCOUNT),
AccountAwareStorageBackend.inMemory(ACCOUNT), regionResolver, delivery, sources, clock, true);
webhooks = new EventBridgeV2Webhooks(service, sources, secrets, clock);