feat(apigateway): trust FLOCI_TLS_EXTRA_CA_PATH for HTTP and HTTP_PROXY integrations (#8285)

This commit is contained in:
Saim Zaib authored and GitHub committed 2026-11-14 10:45:45 -04:00
1 parent fdb2d7fe44
commit b2bdb2bbe9
20 files changed
+263 -33

No files matched your search

@@ -48,6 +48,7 @@ import io.floci.aws.services.apigatewayv2.model.Route;
import io.floci.aws.services.apigatewayv2.proxy.AwsServiceIntegrationMapper;
import io.floci.aws.services.apigatewayv2.proxy.CloudMapInstanceResolver;
import io.floci.aws.services.apigatewayv2.proxy.HttpApiForwardedHeaders;
import io.floci.aws.services.apigatewayv2.proxy.HttpProxyInvoker;
import io.floci.aws.services.apigatewayv2.websocket.ConnectionInfo;
import io.floci.aws.services.apigatewayv2.websocket.WebSocketConnectionManager;
import io.floci.aws.services.elbv2.ElbV2Service;
@@ -146,6 +147,7 @@ public class ApiGatewayExecuteController {
private final AuthorizerPolicyEvaluator authorizerPolicyEvaluator;
private final CloudMapInstanceResolver cloudMapInstanceResolver;
private final AwsServiceIntegrationMapper awsServiceIntegrationMapper;
private final HttpProxyInvoker httpProxyInvoker;
@Inject
public ApiGatewayExecuteController(ApiGatewayService apiGatewayService, CognitoUserPoolAuthorizer cognitoAuthorizer,
@@ -161,7 +163,8 @@ public class ApiGatewayExecuteController {
RequestContext requestContext,
ExecuteApiSigV4Authorizer sigV4Authorizer, RestLambdaAuthorizer restLambdaAuthorizer,
AuthorizerPolicyEvaluator authorizerPolicyEvaluator,
CloudMapInstanceResolver cloudMapInstanceResolver) {
CloudMapInstanceResolver cloudMapInstanceResolver,
HttpProxyInvoker httpProxyInvoker) {
this.apiGatewayService = apiGatewayService;
this.cognitoAuthorizer = cognitoAuthorizer;
this.apiGatewayV2Service = apiGatewayV2Service;
@@ -185,6 +188,7 @@ public class ApiGatewayExecuteController {
this.restLambdaAuthorizer = restLambdaAuthorizer;
this.authorizerPolicyEvaluator = authorizerPolicyEvaluator;
this.cloudMapInstanceResolver = cloudMapInstanceResolver;
this.httpProxyInvoker = httpProxyInvoker;
}
/** Matches an ELBv2 listener ARN (ALB {@code app/} or NLB {@code net/}); group 1 = region. */
@@ -3062,9 +3066,6 @@ public class ApiGatewayExecuteController {
.type(MediaType.APPLICATION_JSON).build();
}
private final io.floci.aws.services.apigatewayv2.proxy.HttpProxyInvoker httpProxyInvoker =
new io.floci.aws.services.apigatewayv2.proxy.HttpProxyInvoker();
/** REST integrations default to AWS's 29s and may opt out of backend TLS verification. */
private static io.floci.aws.services.apigatewayv2.proxy.HttpProxyInvoker.ProxyOptions
proxyOptions(Integration integration) {
@@ -1,7 +1,11 @@
package io.floci.aws.services.apigatewayv2.proxy;
import io.floci.aws.config.ContainerCaBundle;
import io.floci.aws.config.EmulatorConfig;
import io.floci.aws.core.common.SsrfProtection;
import io.floci.aws.services.apigatewayv2.model.Integration;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.jboss.logging.Logger;
import javax.net.ssl.SSLContext;
@@ -48,6 +52,7 @@ import java.util.StringJoiner;
* <p>If the backend is unreachable or times out, returns a 502 Bad Gateway
* ProxyResult so the controller can relay a clean error to the original client.
*/
@ApplicationScoped
public class HttpProxyInvoker {
private static final Logger LOG = Logger.getLogger(HttpProxyInvoker.class);
@@ -74,14 +79,7 @@ public class HttpProxyInvoker {
public static final ProxyOptions DEFAULTS = new ProxyOptions(Duration.ofSeconds(30), false);
}
// Pin to HTTP/1.1: the default HTTP_2 setting attempts cleartext-HTTP/2 negotiation
// against http:// backends, which hangs against plain HTTP/1.1 servers (notably the
// in-JVM Vertx HttpServer used by ELBv2 listeners for HttpAlbIntegration).
private final HttpClient client = HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_1_1)
.connectTimeout(Duration.ofSeconds(10))
.followRedirects(HttpClient.Redirect.NEVER)
.build();
private final HttpClient client;
/** Built on first use: an integration opting out of TLS verification is the exception. */
private volatile HttpClient insecureClient;
@@ -276,12 +274,38 @@ public class HttpProxyInvoker {
private final HostResolver resolver;
@Inject
public HttpProxyInvoker(EmulatorConfig config) {
this(InetAddress::getAllByName, ContainerCaBundle.sslContext(config).orElse(null));
}
public HttpProxyInvoker() {
this(InetAddress::getAllByName);
}
HttpProxyInvoker(HostResolver resolver) {
this(resolver, null);
}
private HttpProxyInvoker(HostResolver resolver, SSLContext sslContext) {
this.resolver = resolver;
this.client = proxyClient(sslContext);
}
// Pin to HTTP/1.1: the default HTTP_2 setting attempts cleartext-HTTP/2 negotiation
// against http:// backends, which hangs against plain HTTP/1.1 servers (notably the
// in-JVM Vertx HttpServer used by ELBv2 listeners for HttpAlbIntegration). 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 proxyClient(SSLContext sslContext) {
HttpClient.Builder builder = HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_1_1)
.connectTimeout(Duration.ofSeconds(10))
.followRedirects(HttpClient.Redirect.NEVER);
if (sslContext != null) {
builder.sslContext(sslContext);
}
return builder.build();
}
public ProxyResult invoke(Integration integration, RequestContext ctx) {
@@ -2,6 +2,8 @@ package io.floci.aws.services.apigatewayv2.websocket;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.floci.aws.config.ContainerCaBundle;
import io.floci.aws.config.EmulatorConfig;
import io.floci.aws.core.common.SsrfProtection;
import io.floci.aws.services.apigateway.AwsServiceRouter;
import io.floci.aws.services.apigateway.VtlTemplateEngine;
@@ -16,6 +18,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.net.InetAddress;
import java.net.URI;
@@ -59,6 +62,13 @@ public class WebSocketIntegrationInvoker {
private final AddressResolver addressResolver;
@Inject
public WebSocketIntegrationInvoker(LambdaService lambdaService, AwsServiceRouter serviceRouter,
ObjectMapper objectMapper, VtlTemplateEngine vtlEngine,
EmulatorConfig config) {
this(lambdaService, serviceRouter, objectMapper, vtlEngine, InetAddress::getAllByName,
ContainerCaBundle.sslContext(config).orElse(null));
}
public WebSocketIntegrationInvoker(LambdaService lambdaService, AwsServiceRouter serviceRouter,
ObjectMapper objectMapper, VtlTemplateEngine vtlEngine) {
this(lambdaService, serviceRouter, objectMapper, vtlEngine, InetAddress::getAllByName);
@@ -67,14 +77,31 @@ public class WebSocketIntegrationInvoker {
WebSocketIntegrationInvoker(LambdaService lambdaService, AwsServiceRouter serviceRouter,
ObjectMapper objectMapper, VtlTemplateEngine vtlEngine,
AddressResolver addressResolver) {
this(lambdaService, serviceRouter, objectMapper, vtlEngine, addressResolver, null);
}
private WebSocketIntegrationInvoker(LambdaService lambdaService, AwsServiceRouter serviceRouter,
ObjectMapper objectMapper, VtlTemplateEngine vtlEngine,
AddressResolver addressResolver, SSLContext sslContext) {
this.lambdaService = lambdaService;
this.serviceRouter = serviceRouter;
this.objectMapper = objectMapper;
this.vtlEngine = vtlEngine;
this.httpClient = HttpClient.newHttpClient();
this.httpClient = backendClient(sslContext);
this.addressResolver = addressResolver;
}
// The client HTTP and HTTP_PROXY integrations reach https:// backends with. 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 backendClient(SSLContext sslContext) {
HttpClient.Builder builder = HttpClient.newBuilder();
if (sslContext != null) {
builder.sslContext(sslContext);
}
return builder.build();
}
@FunctionalInterface
interface AddressResolver {
InetAddress[] resolve(String host) throws IOException;