mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(sns): trust FLOCI_TLS_EXTRA_CA_PATH for HTTPS subscriptions (#8063)
* feat(sns): trust FLOCI_TLS_EXTRA_CA_PATH for HTTPS subscriptions SnsService built its delivery HttpClient without an SSLContext, so an HTTPS subscription whose endpoint has a certificate from a private CA never got the SubscriptionConfirmation or any notification. Floci only logged "Failed to reach SNS endpoint". The @Inject constructor now passes ContainerCaBundle.sslContext(config) down to the constructor that builds the client, as EventBridgeInvoker does. The SubscriptionConfirmation and notification delivery share that one client. It stays pinned to HTTP/1.1, and hostname verification stays on. The other constructors build the client as before. Closes #8033 * test: share the /hook HTTPS endpoint between the extra CA delivery tests LocalHttpsServer.hook starts a localhost HTTPS server that passes each request to /hook to a callback and answers 200, and hookUrl gives its URL. EventBridgeInvokerApiDestinationTest and the new SNS test use them instead of each writing the endpoint out.
This commit is contained in:
1 parent
14bcb85bcb
commit
35bdfdcb3f
6 files changed
+178
-28
No files matched your search
@@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.floci.aws.config.ContainerCaBundle;
|
||||
import io.floci.aws.config.EmulatorConfig;
|
||||
import io.floci.aws.core.common.AwsArnUtils;
|
||||
import io.floci.aws.core.common.AwsException;
|
||||
@@ -43,6 +44,7 @@ import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.net.InetAddress;
|
||||
@@ -215,7 +217,8 @@ public class SnsService implements Resettable, ResourceProvider {
|
||||
firehoseService,
|
||||
config.effectiveBaseUrl(),
|
||||
objectMapper,
|
||||
messageSigner
|
||||
messageSigner,
|
||||
ContainerCaBundle.sslContext(config).orElse(null)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -336,6 +339,22 @@ public class SnsService implements Resettable, ResourceProvider {
|
||||
RegionResolver regionResolver, SqsService sqsService,
|
||||
LambdaService lambdaService, FirehoseService firehoseService,
|
||||
String baseUrl, ObjectMapper objectMapper, SnsMessageSigner messageSigner) {
|
||||
this(topicStore, subscriptionStore, platformAppStore, platformEndpointStore, smsStore,
|
||||
smsAttributesStore, smsSandboxStore, regionResolver, sqsService, lambdaService,
|
||||
firehoseService, baseUrl, objectMapper, messageSigner, null);
|
||||
}
|
||||
|
||||
private SnsService(StorageBackend<String, Topic> topicStore,
|
||||
StorageBackend<String, Subscription> subscriptionStore,
|
||||
StorageBackend<String, PlatformApplication> platformAppStore,
|
||||
StorageBackend<String, PlatformEndpoint> platformEndpointStore,
|
||||
StorageBackend<String, SentSms> smsStore,
|
||||
StorageBackend<String, Map<String, String>> smsAttributesStore,
|
||||
StorageBackend<String, SmsSandboxPhoneNumber> smsSandboxStore,
|
||||
RegionResolver regionResolver, SqsService sqsService,
|
||||
LambdaService lambdaService, FirehoseService firehoseService,
|
||||
String baseUrl, ObjectMapper objectMapper, SnsMessageSigner messageSigner,
|
||||
SSLContext sslContext) {
|
||||
this.topicStore = topicStore;
|
||||
this.subscriptionStore = subscriptionStore;
|
||||
this.platformAppStore = platformAppStore;
|
||||
@@ -349,14 +368,23 @@ public class SnsService implements Resettable, ResourceProvider {
|
||||
this.firehoseService = firehoseService;
|
||||
this.baseUrl = baseUrl;
|
||||
this.objectMapper = objectMapper;
|
||||
// Pin to HTTP/1.1 like AWS SNS: the default HTTP_2 sends an h2c upgrade to http:// endpoints.
|
||||
this.httpClient = HttpClient.newBuilder()
|
||||
.version(HttpClient.Version.HTTP_1_1)
|
||||
.connectTimeout(Duration.ofSeconds(5))
|
||||
.build();
|
||||
this.httpClient = deliveryClient(sslContext);
|
||||
this.messageSigner = messageSigner;
|
||||
}
|
||||
|
||||
// The client HTTP and HTTPS subscriptions are posted to. Pin to HTTP/1.1 like AWS SNS: the default
|
||||
// HTTP_2 sends an h2c upgrade to http:// endpoints. sslContext, when given, adds the extra CAs in
|
||||
// floci.tls.extra-ca-path, and Floci's CA when TLS is on, to the JVM's roots
|
||||
private static HttpClient deliveryClient(SSLContext sslContext) {
|
||||
HttpClient.Builder builder = HttpClient.newBuilder()
|
||||
.version(HttpClient.Version.HTTP_1_1)
|
||||
.connectTimeout(Duration.ofSeconds(5));
|
||||
if (sslContext != null) {
|
||||
builder.sslContext(sslContext);
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
pushCapture.clear();
|
||||
fifoDeduplicationCache.clear();
|
||||
|
||||
Reference in new issue
Block a user