mirror of
https://github.com/floci-io/floci.git
synced 2026-12-03 10:17:48 -05:00
refactor(docker): read the Docker host override from floci.docker.host-override (#10025)
The Docker host override every container Floci starts relies on was read from the Lambda section by core classes. floci.docker.host-override (env FLOCI_DOCKER_HOST_OVERRIDE) is now the key, read through EmulatorConfig.effectiveDockerHostOverride() by DockerHostResolver and TlsProxyServer. It wins when set and not blank; otherwise the former floci.services.lambda.docker-host-override still applies, giving every reader the value it gave before, and its first use logs a deprecation warning. The docs say which key wins and that the self-signed TLS certificate does not name the override.
This commit is contained in:
1 parent
2a2c51abe5
commit
5fffd9f3a8
19 files changed
+358
-31
No files matched your search
@@ -131,6 +131,7 @@ floci:
|
||||
log-max-size: "10m" # Max size per container log file before rotation
|
||||
log-max-file: "3" # Number of rotated log files to retain
|
||||
docker-host: unix:///var/run/docker.sock # Docker daemon socket (shared by Lambda, RDS, ElastiCache)
|
||||
# host-override: floci # Address containers use to reach Floci instead of the detected one (legacy: floci.services.lambda.docker-host-override)
|
||||
max-connections: 1024 # Docker client connection pool for short calls
|
||||
streaming-max-connections: 3072 # Separate pool for streams; each live Lambda container holds 2, plus 1 per extension
|
||||
pool-gauge-interval-seconds: 60 # Log Docker pool use every N seconds while a pool is busy; 0 = off
|
||||
@@ -423,6 +424,8 @@ Per-queue SQS redrive policy (`maxReceiveCount`) is configured at queue creation
|
||||
|
||||
The flat keys `floci.max-request-size` / `FLOCI_MAX_REQUEST_SIZE` and `floci.ecr-base-uri` / `FLOCI_ECR_BASE_URI` moved into sub-structures in 2.x (`floci.protocols.max-request-size` and `floci.services.lambda.ecr-base-uri`). The old names still resolve — a `FlociConfigRelocationsInterceptor` maps them onto the new keys — so existing configs and env vars keep working.
|
||||
|
||||
`floci.services.lambda.docker-host-override` / `FLOCI_SERVICES_LAMBDA_DOCKER_HOST_OVERRIDE` moved to `floci.docker.host-override` / `FLOCI_DOCKER_HOST_OVERRIDE`, since every container Floci starts uses it, not only Lambda's. The old key is still read when the new one is unset, with a deprecation warning logged once; when both are set, the new key wins.
|
||||
|
||||
## Disabling Services
|
||||
|
||||
Set `enabled: false` for any service you don't need. Disabled services return a `ServiceUnavailableException` rather than silently ignoring calls.
|
||||
|
||||
@@ -452,13 +452,15 @@ What each setting does and why it is needed:
|
||||
explicitly to bypass auto-detection:
|
||||
|
||||
```bash
|
||||
FLOCI_SERVICES_LAMBDA_DOCKER_HOST_OVERRIDE=floci
|
||||
FLOCI_DOCKER_HOST_OVERRIDE=floci
|
||||
```
|
||||
|
||||
This forces every spawned Lambda container to reach the Runtime API at the
|
||||
given host (here the `FLOCI_HOSTNAME` value), skipping Floci's
|
||||
auto-detection entirely. See the [Lambda docs](../services/lambda.md#configuration)
|
||||
for details.
|
||||
This forces every container Floci spawns to reach Floci, and Lambda
|
||||
containers its Runtime API, at the given host (here the `FLOCI_HOSTNAME`
|
||||
value), skipping Floci's auto-detection entirely. The former
|
||||
`FLOCI_SERVICES_LAMBDA_DOCKER_HOST_OVERRIDE` still works when
|
||||
`FLOCI_DOCKER_HOST_OVERRIDE` is unset, but is deprecated. See the
|
||||
[Lambda docs](../services/lambda.md#runtime-api-host-override) for details.
|
||||
|
||||
## Transient I/O retry
|
||||
|
||||
|
||||
@@ -145,6 +145,7 @@ This foundation release provides opt-in security-group filtering for EC2 Docker
|
||||
| `FLOCI_NETWORK_SECURITY_GROUP_ENFORCEMENT_ENABLED` | `false` | Opt in to filtering Docker-backed EC2 and ECS `awsvpc` traffic by attached security groups |
|
||||
| `FLOCI_NETWORK_SECURITY_GROUP_ENFORCEMENT_HELPER_IMAGE` | `floci/network-helper:local` | Linux helper image containing nftables; Floci builds the default image locally when missing |
|
||||
| `FLOCI_DOCKER_DOCKER_HOST` | `unix:///var/run/docker.sock` | Docker daemon socket path or TCP address |
|
||||
| `FLOCI_DOCKER_HOST_OVERRIDE` | _(none)_ | Explicit host/IP that containers Floci starts (Lambda's Runtime API callback included) use to reach Floci, bypassing auto-detection (e.g. rootless Podman). The self-signed TLS certificate does not name it. Replaces `FLOCI_SERVICES_LAMBDA_DOCKER_HOST_OVERRIDE` |
|
||||
| `FLOCI_DOCKER_DOCKER_CONFIG_PATH` | _(none)_ | Path to a directory containing Docker's `config.json` for registry auth |
|
||||
| `FLOCI_DOCKER_MAX_CONNECTIONS` | `1024` | Connection pool size for Floci's short Docker calls. See [Docker Configuration](docker.md#connection-pool) |
|
||||
| `FLOCI_DOCKER_STREAMING_MAX_CONNECTIONS` | `3072` | Connection pool size for streams that last a container's lifetime or a long command's run, kept apart from the main pool so they never starve create, start, stop and remove. Each live Lambda container holds two (log stream and exit watcher) plus one per extension, and each CodeBuild phase, SSM command, ECS Exec session, EKS audit follower, user data script and EMR bootstrap action one. See [Docker Configuration](docker.md#connection-pool) |
|
||||
@@ -342,7 +343,7 @@ See [Initialization Hooks](./initialization-hooks.md) for lifecycle phases and s
|
||||
| `FLOCI_SERVICES_LAMBDA_DOCKER_NETWORK` | _(none)_ | Docker network for Lambda containers (overrides `FLOCI_SERVICES_DOCKER_NETWORK`) |
|
||||
| `FLOCI_SERVICES_LAMBDA_DOCKER_FLAGS` | _(none)_ | Additional Docker flags applied to Lambda containers, such as `--env`, `--volume`, `--publish`, `--add-host`, `--dns`, `--label`, `--network`, `--user`, `--privileged`, and `--platform`. Explicit `--dns` entries replace automatic embedded DNS and public fallback resolvers. Published ports support `host:container` and `127.0.0.1:host:container` forms |
|
||||
| `FLOCI_SERVICES_LAMBDA_CONTAINER_NAME_PREFIX` | `floci` | Base name prefix for Lambda-spawned containers and code volumes (must match `[A-Za-z0-9][A-Za-z0-9_.-]*`) |
|
||||
| `FLOCI_SERVICES_LAMBDA_DOCKER_HOST_OVERRIDE` | _(none)_ | Explicit host/IP Lambda containers use to reach the Runtime API, bypassing auto-detection (e.g. rootless Podman) |
|
||||
| `FLOCI_SERVICES_LAMBDA_DOCKER_HOST_OVERRIDE` | _(none)_ | Deprecated: use `FLOCI_DOCKER_HOST_OVERRIDE`, which wins when both are set. Still honoured when that one is unset, with a deprecation warning at startup |
|
||||
| `FLOCI_SERVICES_LAMBDA_AWS_CONFIG_PATH` | _(none)_ | Host path bind-mounted read-only at `/opt/aws-config` inside Lambda containers for real credential discovery |
|
||||
| `FLOCI_SERVICES_LAMBDA_EXECUTOR` | `docker` | Execution backend for Lambda environments: `docker` (containers), `kubernetes` (pods) or `process` (local processes for `provided.*` runtimes) |
|
||||
| `FLOCI_SERVICES_LAMBDA_KUBERNETES_NAMESPACE` | `default` | Namespace Lambda pods are created in |
|
||||
|
||||
@@ -193,7 +193,7 @@ The credentials endpoint performs the following validations:
|
||||
|
||||
Kubernetes only accepts an `https` `clientConfig.url` on a `MutatingWebhookConfiguration`, together with a `caBundle` the API server trusts. Floci serves HTTP with the default `floci.tls.enabled=false`, so the webhook is skipped with a warning in that case and pods start unmutated. Set `FLOCI_TLS_ENABLED=true` to get injection; the `caBundle` is then what `GET /_floci/ca.pem` serves: Floci's local CA, after the certificates in the `floci.tls.cert-path` file when Floci serves a certificate of your own.
|
||||
|
||||
The API server also checks that the certificate names the webhook URL's host, so the URL uses a host the certificate Floci serves names. When the cluster resolves through Floci's embedded DNS (`FLOCI_SERVICES_EKS_EMBEDDED_DNS`, with the cluster on a Docker network that reaches Floci's DNS server, as it does by default with Floci in a container), that is Floci's hostname: `FLOCI_HOSTNAME`, or `localhost.floci.io`, both of which the self-signed certificate covers. Otherwise it is the host other containers reach Floci on: `host.docker.internal` when Floci runs natively, which the self-signed certificate also covers, or Floci's container IP, which it does not. When the certificate does not name that host, as with a certificate of your own issued for other names, pod identity injection is not available: the webhook is skipped with a warning naming the host, and pods start unmutated. To get it, have the API server call Floci by a name the certificate covers: with embedded DNS, set `FLOCI_HOSTNAME` to that name; without it, point `FLOCI_SERVICES_LAMBDA_DOCKER_HOST_OVERRIDE` at it. The self-signed certificate covers `FLOCI_HOSTNAME` too.
|
||||
The API server also checks that the certificate names the webhook URL's host, so the URL uses a host the certificate Floci serves names. When the cluster resolves through Floci's embedded DNS (`FLOCI_SERVICES_EKS_EMBEDDED_DNS`, with the cluster on a Docker network that reaches Floci's DNS server, as it does by default with Floci in a container), that is Floci's hostname: `FLOCI_HOSTNAME`, or `localhost.floci.io`, both of which the self-signed certificate covers. Otherwise it is the host other containers reach Floci on: `host.docker.internal` when Floci runs natively, which the self-signed certificate also covers, or Floci's container IP, which it does not. When the certificate does not name that host, as with a certificate of your own issued for other names, pod identity injection is not available: the webhook is skipped with a warning naming the host, and pods start unmutated. To get it, have the API server call Floci by a name the certificate covers: with embedded DNS, set `FLOCI_HOSTNAME` to that name; without it, point `FLOCI_DOCKER_HOST_OVERRIDE` at it. The self-signed certificate covers `FLOCI_HOSTNAME` too.
|
||||
|
||||
The webhook carries `failurePolicy: Ignore`, and Floci admits the pod unchanged on any internal error, so a webhook that cannot be registered or cannot be reached never prevents a pod from being created. Registration failures log a warning and leave the cluster running.
|
||||
|
||||
|
||||
+11
-5
@@ -799,7 +799,7 @@ Configuration resource reads and `ListFunctionsByCodeSigningConfig` return
|
||||
| `FLOCI_SERVICES_LAMBDA_DOCKER_NETWORK` | *(unset)* | Docker network to attach Lambda containers to (overrides `FLOCI_SERVICES_DOCKER_NETWORK`) |
|
||||
| `FLOCI_SERVICES_LAMBDA_DOCKER_FLAGS` | *(unset)* | Additional Docker flags applied to Lambda containers, including `--env`, `--volume`, `--publish`, `--add-host`, `--dns`, `--label`, `--network`, `--user`, `--privileged`, and `--platform`. Explicit `--dns` entries replace automatic embedded DNS and public fallback resolvers. Published ports support `host:container` and `127.0.0.1:host:container` forms |
|
||||
| `FLOCI_SERVICES_LAMBDA_EXTRA_HOSTS` | *(unset)* | Comma-separated `hostname:ip` entries added to each Lambda container's `/etc/hosts`; `ip` may be `host-gateway`, mirroring `docker run --add-host` |
|
||||
| `FLOCI_SERVICES_LAMBDA_DOCKER_HOST_OVERRIDE` | *(unset)* | Explicit host/IP that spawned Lambda containers use to reach Floci's Runtime API, bypassing auto-detection |
|
||||
| `FLOCI_SERVICES_LAMBDA_DOCKER_HOST_OVERRIDE` | *(unset)* | Deprecated: use `FLOCI_DOCKER_HOST_OVERRIDE` (see [Runtime API host override](#runtime-api-host-override)), which wins when both are set |
|
||||
| `FLOCI_SERVICES_LAMBDA_CONTAINER_NAME_PREFIX` | `floci` | Base name prefix for spawned Lambda containers and code volumes (e.g. `acme` → `acme-<function>-<id>` containers, `acme-code-<function>-<hash>` volumes; with `FLOCI_DOCKER_RESOURCE_NAMESPACE` set, the namespace follows the prefix and a short hash of it ends the volume name, e.g. `acme-<namespace>-code-<function>-<hash>-<namespace hash>`). Must be a valid Docker name segment (`[A-Za-z0-9][A-Za-z0-9_.-]*`); invalid values are ignored with a warning |
|
||||
| `FLOCI_SERVICES_LAMBDA_CODE_VOLUME_POPULATE_CONCURRENCY` | `max(2, cpus/2)` | Maximum concurrent first-time code-volume populates. See the note below |
|
||||
| `FLOCI_SERVICES_LAMBDA_EXECUTOR` | `docker` | Execution backend: `docker` (containers), `kubernetes` (pods) or `process` (local processes, see [Process executor](#process-executor)) |
|
||||
@@ -925,14 +925,20 @@ correct and needs no configuration.
|
||||
|
||||
On unusual network topologies, for example rootless Podman, auto-detection
|
||||
can pick an address the Lambda container cannot reach, and invocations fail with
|
||||
`connect ECONNREFUSED <ip>:12000`. Set `FLOCI_SERVICES_LAMBDA_DOCKER_HOST_OVERRIDE`
|
||||
to the host or IP that containers can actually reach Floci on, and Floci uses it
|
||||
verbatim instead of auto-detecting:
|
||||
`connect ECONNREFUSED <ip>:12000`. Set `FLOCI_DOCKER_HOST_OVERRIDE`
|
||||
(`floci.docker.host-override`) to the host or IP that containers can actually
|
||||
reach Floci on, and Floci uses it verbatim instead of auto-detecting:
|
||||
|
||||
```bash
|
||||
FLOCI_SERVICES_LAMBDA_DOCKER_HOST_OVERRIDE=floci
|
||||
FLOCI_DOCKER_HOST_OVERRIDE=floci
|
||||
```
|
||||
|
||||
The override applies to every container Floci starts, not only Lambda's. The
|
||||
former key `floci.services.lambda.docker-host-override`
|
||||
(`FLOCI_SERVICES_LAMBDA_DOCKER_HOST_OVERRIDE`) still works when the new one is
|
||||
unset, and Floci logs a deprecation warning the first time it uses it. When both
|
||||
are set, `FLOCI_DOCKER_HOST_OVERRIDE` wins.
|
||||
|
||||
See [Docker Configuration → Running on Podman (rootless)](../configuration/docker.md#running-on-podman-rootless)
|
||||
for a full rootless Podman walkthrough.
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.floci.aws.config;
|
||||
|
||||
import io.floci.aws.core.common.docker.DockerHostOverride;
|
||||
import io.smallrye.config.ConfigMapping;
|
||||
import io.smallrye.config.WithDefault;
|
||||
|
||||
@@ -57,6 +58,17 @@ public interface EmulatorConfig {
|
||||
.orElseGet(() -> URI.create(effectiveBaseUrl()).getAuthority());
|
||||
}
|
||||
|
||||
/**
|
||||
* The address containers Floci starts use to reach it, when one is configured: {@code
|
||||
* floci.docker.host-override}, or else the deprecated {@code
|
||||
* floci.services.lambda.docker-host-override}, whose first use logs a warning. Empty when
|
||||
* neither is set; a blank value is returned as configured, and callers treat it as unset.
|
||||
*/
|
||||
default Optional<String> effectiveDockerHostOverride() {
|
||||
return DockerHostOverride.resolve(docker().hostOverride().orElse(null),
|
||||
services().lambda().dockerHostOverride().orElse(null));
|
||||
}
|
||||
|
||||
@WithDefault("us-east-1") // partition-literal: the configurable default region
|
||||
String defaultRegion();
|
||||
|
||||
@@ -3738,6 +3750,11 @@ public interface EmulatorConfig {
|
||||
@WithDefault("1")
|
||||
long durableSweepIntervalSeconds();
|
||||
|
||||
/**
|
||||
* Deprecated: use {@code floci.docker.host-override}, which wins when both are set. Still
|
||||
* honoured when that key is unset, with a warning. Read it only through
|
||||
* {@link EmulatorConfig#effectiveDockerHostOverride()}.
|
||||
*/
|
||||
Optional<String> dockerHostOverride();
|
||||
|
||||
/**
|
||||
@@ -4753,6 +4770,18 @@ public interface EmulatorConfig {
|
||||
@WithDefault("false")
|
||||
boolean allowSshHost();
|
||||
|
||||
/**
|
||||
* The address containers Floci starts use to reach it, instead of the detected one (this
|
||||
* container's IP when Floci runs in Docker, {@code host.docker.internal} on the host). The
|
||||
* self-signed TLS certificate does not name it. Env var: {@code FLOCI_DOCKER_HOST_OVERRIDE}.
|
||||
*
|
||||
* <p>Read through {@link EmulatorConfig#effectiveDockerHostOverride()}. The former key
|
||||
* {@code floci.services.lambda.docker-host-override} (env
|
||||
* {@code FLOCI_SERVICES_LAMBDA_DOCKER_HOST_OVERRIDE}) still works when this one is unset, but
|
||||
* is deprecated.
|
||||
*/
|
||||
Optional<String> hostOverride();
|
||||
|
||||
/**
|
||||
* Size of the connection pool behind the shared Docker client. Every short Docker call
|
||||
* leases a connection from it; streams that stay open while a container or a command runs
|
||||
|
||||
@@ -123,7 +123,7 @@ public class TlsCertificateManager implements Resettable {
|
||||
* Whether the certificate Floci serves names {@code host}, exactly or under a one-label
|
||||
* wildcard, so a client that verifies the name accepts it: the managed leaf with every name it
|
||||
* learned, or a user-provided certificate as it is on disk. False with TLS off, for a host it
|
||||
* does not name, such as an IP from {@code docker-host-override} or the container-IP fallback,
|
||||
* does not name, such as an IP from {@code docker.host-override} or the container-IP fallback,
|
||||
* and when the certificate cannot be read.
|
||||
*/
|
||||
public boolean serves(String host) {
|
||||
|
||||
@@ -259,7 +259,7 @@ public class TlsProxyServer {
|
||||
} catch (IllegalArgumentException e) {
|
||||
LOG.debugv(e, "TLS proxy: cannot read the hostname from floci.base-url");
|
||||
}
|
||||
config.services().lambda().dockerHostOverride().map(TlsProxyServer::normalizeHost).ifPresent(endpointHosts::add);
|
||||
config.effectiveDockerHostOverride().map(TlsProxyServer::normalizeHost).ifPresent(endpointHosts::add);
|
||||
config.services().iot().endpointAddress().filter(address -> !address.isBlank()).ifPresent(address -> {
|
||||
try {
|
||||
String iotHost = TlsConfigSource.iotEndpointHost(address);
|
||||
|
||||
@@ -97,7 +97,7 @@ public class ContainerReachableEndpoint {
|
||||
* TLS enabled, {@code TlsProxyServer} serves https beside http on {@link EmulatorConfig#port()},
|
||||
* and every container Floci launches trusts Floci's CA through {@code NODE_EXTRA_CA_CERTS} and
|
||||
* the other bundle variables, so the https URL is reachable with no shim in the handler. A host
|
||||
* the certificate does not name, an IP from {@code docker-host-override} or the container-IP
|
||||
* the certificate does not name, an IP from {@code docker.host-override} or the container-IP
|
||||
* fallback when the embedded DNS server cannot start, would fail the handler's certificate
|
||||
* check where http works, so that URL stays http.
|
||||
*/
|
||||
@@ -108,7 +108,7 @@ public class ContainerReachableEndpoint {
|
||||
/**
|
||||
* {@link #baseUrl(boolean)} over https, when Floci serves TLS under a certificate that names its host, so
|
||||
* a client that verifies the name accepts it. Empty otherwise: with TLS off, or for a host the certificate
|
||||
* does not name, such as an IP from {@code docker-host-override}, the container-IP fallback, or a
|
||||
* does not name, such as an IP from {@code docker.host-override}, the container-IP fallback, or a
|
||||
* name a user-provided certificate was not issued for.
|
||||
*/
|
||||
public Optional<String> httpsBaseUrl(boolean useEmbeddedDns) {
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package io.floci.aws.core.common.docker;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* Which configured address containers Floci starts use to reach it.
|
||||
*
|
||||
* <p>{@code floci.docker.host-override} is the key. The former
|
||||
* {@code floci.services.lambda.docker-host-override} still works when that key is unset, and a
|
||||
* deprecation warning is logged the first time it is used. When both are set the new key wins.
|
||||
* The configuration reads both keys and asks this class which one applies, see
|
||||
* {@code EmulatorConfig.effectiveDockerHostOverride()}.
|
||||
*/
|
||||
public final class DockerHostOverride {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(DockerHostOverride.class);
|
||||
|
||||
static final String KEY = "floci.docker.host-override";
|
||||
static final String LEGACY_KEY = "floci.services.lambda.docker-host-override";
|
||||
|
||||
private static final AtomicBoolean LEGACY_KEY_WARNED = new AtomicBoolean();
|
||||
|
||||
private DockerHostOverride() {
|
||||
}
|
||||
|
||||
/**
|
||||
* The override that applies, given the value of each key (null when unset). A blank value is
|
||||
* returned as it was configured; callers treat it as unset.
|
||||
*/
|
||||
public static Optional<String> resolve(String override, String legacyOverride) {
|
||||
return resolve(override, legacyOverride, LEGACY_KEY_WARNED);
|
||||
}
|
||||
|
||||
static Optional<String> resolve(String override, String legacyOverride, AtomicBoolean legacyKeyWarned) {
|
||||
if (override != null && !override.isBlank()) {
|
||||
return Optional.of(override);
|
||||
}
|
||||
if (legacyOverride != null) {
|
||||
if (!legacyOverride.isBlank() && legacyKeyWarned.compareAndSet(false, true)) {
|
||||
LOG.warnv("{0} is deprecated and will be removed in a future release; set {1} "
|
||||
+ "(env FLOCI_DOCKER_HOST_OVERRIDE) instead", LEGACY_KEY, KEY);
|
||||
}
|
||||
return Optional.of(legacyOverride);
|
||||
}
|
||||
return Optional.ofNullable(override);
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,7 @@ public class DockerHostResolver {
|
||||
}
|
||||
|
||||
public String resolve() {
|
||||
Optional<String> override = config.services().lambda().dockerHostOverride();
|
||||
Optional<String> override = config.effectiveDockerHostOverride();
|
||||
if (override.isPresent() && !override.get().isBlank()) {
|
||||
LOG.debugv("Using configured docker host override: {0}", override.get());
|
||||
return override.get();
|
||||
@@ -95,7 +95,7 @@ public class DockerHostResolver {
|
||||
* the address {@link #resolve()} gives.
|
||||
*/
|
||||
public String resolveOn(String network) {
|
||||
Optional<String> override = config.services().lambda().dockerHostOverride();
|
||||
Optional<String> override = config.effectiveDockerHostOverride();
|
||||
if ((override.isEmpty() || override.get().isBlank()) && currentContainerNetworkResolver != null
|
||||
&& containerDetector.isRunningInContainer()) {
|
||||
Optional<String> address = currentContainerNetworkResolver.resolveContainerIpOn(network);
|
||||
|
||||
@@ -481,6 +481,12 @@ floci:
|
||||
# step with the @WithDefault on EmulatorConfig.DockerConfig.logDriverPort.
|
||||
log-driver-port: 12201
|
||||
resource-namespace: "" # FLOCI_DOCKER_RESOURCE_NAMESPACE; scopes child container/volume names
|
||||
# FLOCI_DOCKER_HOST_OVERRIDE: the address containers Floci starts use to reach it, instead of the
|
||||
# detected one (this container's IP in Docker, host.docker.internal on the host). The self-signed
|
||||
# TLS certificate does not name it. Unset by default. The former floci.services.lambda.docker-host-override
|
||||
# (FLOCI_SERVICES_LAMBDA_DOCKER_HOST_OVERRIDE) still works when this is unset, with a deprecation
|
||||
# warning; this key wins when both are set.
|
||||
# host-override: floci
|
||||
docker-config-path: ""
|
||||
# extra-labels: # Extra Docker labels applied to every Floci-created container and volume
|
||||
# - key: "com.example.project" # (FLOCI_DOCKER_EXTRA_LABELS_0__KEY / _0__VALUE; increment the index for more;
|
||||
|
||||
@@ -21,6 +21,8 @@ import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@@ -82,6 +84,8 @@ class TlsProxyServerTest {
|
||||
when(config.services()).thenReturn(mock(EmulatorConfig.ServicesConfig.class));
|
||||
when(config.services().lambda()).thenReturn(mock(EmulatorConfig.LambdaServiceConfig.class));
|
||||
when(config.services().iot()).thenReturn(mock(EmulatorConfig.IotServiceConfig.class));
|
||||
when(config.docker()).thenReturn(mock(EmulatorConfig.DockerConfig.class));
|
||||
when(config.effectiveDockerHostOverride()).thenCallRealMethod();
|
||||
when(config.tls()).thenReturn(tls);
|
||||
when(tls.enabled()).thenReturn(tlsEnabled);
|
||||
when(tls.awsHttpsPort()).thenReturn(awsHttpsPort);
|
||||
@@ -369,6 +373,51 @@ class TlsProxyServerTest {
|
||||
}
|
||||
}
|
||||
|
||||
/** The Docker host override is a name Floci serves, read from either key, the Docker key first. */
|
||||
@Test
|
||||
@Timeout(30)
|
||||
void awsHttpsPort_servesTheDockerHostOverrideFromEitherKey() throws Exception {
|
||||
assertEquals(Set.of("docker.override.test"), overridesFlociServes("docker.override.test", null));
|
||||
assertEquals(Set.of("lambda.override.test"), overridesFlociServes(null, "lambda.override.test"));
|
||||
assertEquals(Set.of("docker.override.test"),
|
||||
overridesFlociServes("docker.override.test", "lambda.override.test"));
|
||||
}
|
||||
|
||||
private Set<String> overridesFlociServes(String dockerHostOverride, String lambdaDockerHostOverride)
|
||||
throws Exception {
|
||||
httpBackend = startMarkerBackend("PLAIN");
|
||||
httpsBackend = startMarkerBackend("TLS");
|
||||
NetServer albBackend = startMarkerBackend("ALB");
|
||||
try {
|
||||
int[] ports = FreePorts.anyInterfacePorts(2);
|
||||
int awsHttpsPort = ports[1];
|
||||
EmulatorConfig config = configWith(true, ports[0], awsHttpsPort);
|
||||
when(config.docker().hostOverride()).thenReturn(Optional.ofNullable(dockerHostOverride));
|
||||
when(config.services().lambda().dockerHostOverride())
|
||||
.thenReturn(Optional.ofNullable(lambdaDockerHostOverride));
|
||||
proxy = new TlsProxyServer(vertx, config, "127.0.0.1",
|
||||
httpBackend.actualPort(), httpsBackend.actualPort());
|
||||
proxy.routeServerNames(port -> true, (port, name, allowAliases) -> port == awsHttpsPort
|
||||
? new ServerNameTarget(albBackend.actualPort(), "listener") : null);
|
||||
|
||||
Set<String> served = new HashSet<>();
|
||||
for (String name : List.of("docker.override.test", "lambda.override.test")) {
|
||||
if ("TLS".equals(roundTrip(awsHttpsPort, TlsClientHelloTest.clientHello(name).getBytes()))) {
|
||||
served.add(name);
|
||||
}
|
||||
}
|
||||
return served;
|
||||
} finally {
|
||||
proxy.stop();
|
||||
proxy = null;
|
||||
closeBackend(albBackend);
|
||||
closeBackend(httpBackend);
|
||||
closeBackend(httpsBackend);
|
||||
httpBackend = null;
|
||||
httpsBackend = null;
|
||||
}
|
||||
}
|
||||
|
||||
private NetServer startMarkerBackend(String marker) throws Exception {
|
||||
NetServer server = vertx.createNetServer();
|
||||
server.connectHandler(sock -> sock.write(marker));
|
||||
|
||||
@@ -123,7 +123,7 @@ class ContainerReachableEndpointTest {
|
||||
@Test
|
||||
void customResourceResponseUrlStaysHttpForAnIpTheCertificateDoesNotName() {
|
||||
// The container-IP fallback when the embedded DNS server cannot start, or an IP set as
|
||||
// docker-host-override: the leaf does not name it, so a handler verifying the certificate
|
||||
// docker.host-override: the leaf does not name it, so a handler verifying the certificate
|
||||
// would refuse https where http works.
|
||||
when(tls.enabled()).thenReturn(true);
|
||||
when(config.port()).thenReturn(4566);
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package io.floci.aws.core.common.docker;
|
||||
|
||||
import io.floci.aws.config.EmulatorConfig;
|
||||
import io.floci.aws.testing.ParallelLocks;
|
||||
import io.smallrye.config.EnvConfigSource;
|
||||
import io.smallrye.config.SmallRyeConfig;
|
||||
import io.smallrye.config.SmallRyeConfigBuilder;
|
||||
import io.smallrye.config.source.yaml.YamlConfigSource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.parallel.ResourceLock;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/** Both environment variables bind to their keys in the shipped configuration. */
|
||||
@ResourceLock(ParallelLocks.TLS_CONFIG)
|
||||
@ResourceLock(ParallelLocks.CONFIG_MAPPING)
|
||||
class DockerHostOverrideConfigTest {
|
||||
|
||||
@Test
|
||||
void unsetByDefault() throws IOException {
|
||||
assertEquals(Optional.empty(), config(Map.of()).effectiveDockerHostOverride());
|
||||
}
|
||||
|
||||
@Test
|
||||
void theDockerVariableSetsTheDockerKey() throws IOException {
|
||||
EmulatorConfig config = config(Map.of("FLOCI_DOCKER_HOST_OVERRIDE", "floci.docker"));
|
||||
|
||||
assertEquals(Optional.of("floci.docker"), config.docker().hostOverride());
|
||||
assertEquals(Optional.of("floci.docker"), config.effectiveDockerHostOverride());
|
||||
}
|
||||
|
||||
@Test
|
||||
void theLambdaVariableStillSetsTheOverride() throws IOException {
|
||||
EmulatorConfig config = config(Map.of("FLOCI_SERVICES_LAMBDA_DOCKER_HOST_OVERRIDE", "floci.lambda"));
|
||||
|
||||
assertEquals(Optional.empty(), config.docker().hostOverride());
|
||||
assertEquals(Optional.of("floci.lambda"), config.effectiveDockerHostOverride());
|
||||
}
|
||||
|
||||
@Test
|
||||
void theDockerVariableWinsOverTheLambdaVariable() throws IOException {
|
||||
EmulatorConfig config = config(Map.of(
|
||||
"FLOCI_DOCKER_HOST_OVERRIDE", "floci.docker",
|
||||
"FLOCI_SERVICES_LAMBDA_DOCKER_HOST_OVERRIDE", "floci.lambda"));
|
||||
|
||||
assertEquals(Optional.of("floci.docker"), config.effectiveDockerHostOverride());
|
||||
}
|
||||
|
||||
private static EmulatorConfig config(Map<String, String> env) throws IOException {
|
||||
SmallRyeConfig config = new SmallRyeConfigBuilder()
|
||||
.addDefaultInterceptors()
|
||||
.withMapping(EmulatorConfig.class)
|
||||
.withSources(new YamlConfigSource(Path.of("src/main/resources/application.yml").toUri().toURL()))
|
||||
.withSources(new EnvConfigSource(env, 300))
|
||||
.build();
|
||||
return config.getConfigMapping(EmulatorConfig.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package io.floci.aws.core.common.docker;
|
||||
|
||||
import io.floci.aws.config.EmulatorConfig;
|
||||
import io.floci.aws.testutil.LogCapture;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class DockerHostOverrideTest {
|
||||
|
||||
@Test
|
||||
void onlyTheDockerKeyIsUsedWithoutAWarning() {
|
||||
AtomicBoolean warned = new AtomicBoolean();
|
||||
List<LogRecord> records = LogCapture.captureFromThisThread(DockerHostOverride.class,
|
||||
() -> assertEquals(Optional.of("floci.docker"),
|
||||
DockerHostOverride.resolve("floci.docker", null, warned)));
|
||||
|
||||
assertTrue(records.isEmpty(), () -> "unexpected log lines: " + records);
|
||||
}
|
||||
|
||||
@Test
|
||||
void onlyTheLambdaKeyIsStillUsedAndWarnsOnce() {
|
||||
AtomicBoolean warned = new AtomicBoolean();
|
||||
List<LogRecord> records = LogCapture.captureFromThisThread(DockerHostOverride.class, () -> {
|
||||
assertEquals(Optional.of("floci.lambda"), DockerHostOverride.resolve(null, "floci.lambda", warned));
|
||||
assertEquals(Optional.of("floci.lambda"), DockerHostOverride.resolve(null, "floci.lambda", warned));
|
||||
assertEquals(Optional.of("floci.lambda"), DockerHostOverride.resolve(" ", "floci.lambda", warned));
|
||||
});
|
||||
|
||||
assertEquals(1, records.size(), () -> "expected one deprecation warning: " + records);
|
||||
assertEquals(Level.WARNING, records.getFirst().getLevel());
|
||||
String message = LogCapture.formatted(records.getFirst());
|
||||
assertThat(message, containsString("floci.services.lambda.docker-host-override is deprecated"));
|
||||
assertThat(message, containsString("floci.docker.host-override"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void theDockerKeyWinsOverTheLambdaKeyWithoutAWarning() {
|
||||
AtomicBoolean warned = new AtomicBoolean();
|
||||
List<LogRecord> records = LogCapture.captureFromThisThread(DockerHostOverride.class,
|
||||
() -> assertEquals(Optional.of("floci.docker"),
|
||||
DockerHostOverride.resolve("floci.docker", "floci.lambda", warned)));
|
||||
|
||||
assertTrue(records.isEmpty(), () -> "unexpected log lines: " + records);
|
||||
}
|
||||
|
||||
@Test
|
||||
void neitherKeyIsEmpty() {
|
||||
assertEquals(Optional.empty(), DockerHostOverride.resolve(null, null, new AtomicBoolean()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void readsBothKeysFromTheConfig() {
|
||||
assertEquals(Optional.of("floci.docker"), config("floci.docker", null).effectiveDockerHostOverride());
|
||||
assertEquals(Optional.of("floci.lambda"), config(null, "floci.lambda").effectiveDockerHostOverride());
|
||||
assertEquals(Optional.of("floci.docker"), config("floci.docker", "floci.lambda").effectiveDockerHostOverride());
|
||||
assertEquals(Optional.empty(), config(null, null).effectiveDockerHostOverride());
|
||||
}
|
||||
|
||||
private static EmulatorConfig config(String hostOverride, String lambdaDockerHostOverride) {
|
||||
EmulatorConfig config = mock(EmulatorConfig.class);
|
||||
EmulatorConfig.DockerConfig docker = mock(EmulatorConfig.DockerConfig.class);
|
||||
EmulatorConfig.ServicesConfig services = mock(EmulatorConfig.ServicesConfig.class);
|
||||
EmulatorConfig.LambdaServiceConfig lambda = mock(EmulatorConfig.LambdaServiceConfig.class);
|
||||
when(config.docker()).thenReturn(docker);
|
||||
when(config.services()).thenReturn(services);
|
||||
when(services.lambda()).thenReturn(lambda);
|
||||
when(docker.hostOverride()).thenReturn(Optional.ofNullable(hostOverride));
|
||||
when(lambda.dockerHostOverride()).thenReturn(Optional.ofNullable(lambdaDockerHostOverride));
|
||||
when(config.effectiveDockerHostOverride()).thenCallRealMethod();
|
||||
return config;
|
||||
}
|
||||
}
|
||||
@@ -13,16 +13,10 @@ class DockerHostResolverTest {
|
||||
|
||||
@Test
|
||||
void resolve_usesDetectedContainerNetworkIpWhenRunningInContainer() {
|
||||
EmulatorConfig config = mock(EmulatorConfig.class);
|
||||
EmulatorConfig config = config(null);
|
||||
ContainerDetector containerDetector = mock(ContainerDetector.class);
|
||||
CurrentContainerNetworkResolver currentContainerNetworkResolver =
|
||||
mock(CurrentContainerNetworkResolver.class);
|
||||
|
||||
EmulatorConfig.ServicesConfig services = mock(EmulatorConfig.ServicesConfig.class);
|
||||
EmulatorConfig.LambdaServiceConfig lambda = mock(EmulatorConfig.LambdaServiceConfig.class);
|
||||
when(config.services()).thenReturn(services);
|
||||
when(services.lambda()).thenReturn(lambda);
|
||||
when(lambda.dockerHostOverride()).thenReturn(Optional.empty());
|
||||
when(containerDetector.isRunningInContainer()).thenReturn(true);
|
||||
when(currentContainerNetworkResolver.resolveContainerIp()).thenReturn(Optional.of("172.24.0.2"));
|
||||
|
||||
@@ -80,13 +74,55 @@ class DockerHostResolverTest {
|
||||
currentContainerNetworkResolver).resolveOn("rds-net"));
|
||||
}
|
||||
|
||||
private static EmulatorConfig config(String dockerHostOverride) {
|
||||
@Test
|
||||
void resolve_usesTheDockerHostOverrideKey() {
|
||||
DockerHostResolver resolver = inContainerResolver(config("floci.docker", null));
|
||||
|
||||
assertEquals("floci.docker", resolver.resolve());
|
||||
assertEquals("floci.docker", resolver.resolveOn("rds-net"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolve_stillUsesTheLambdaKeyWhenTheDockerKeyIsUnset() {
|
||||
DockerHostResolver resolver = inContainerResolver(config(null, "floci.lambda"));
|
||||
|
||||
assertEquals("floci.lambda", resolver.resolve());
|
||||
assertEquals("floci.lambda", resolver.resolveOn("rds-net"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolve_prefersTheDockerKeyOverTheLambdaKey() {
|
||||
DockerHostResolver resolver = inContainerResolver(config("floci.docker", "floci.lambda"));
|
||||
|
||||
assertEquals("floci.docker", resolver.resolve());
|
||||
assertEquals("floci.docker", resolver.resolveOn("rds-net"));
|
||||
}
|
||||
|
||||
private static DockerHostResolver inContainerResolver(EmulatorConfig config) {
|
||||
ContainerDetector inContainer = mock(ContainerDetector.class);
|
||||
CurrentContainerNetworkResolver currentContainerNetworkResolver =
|
||||
mock(CurrentContainerNetworkResolver.class);
|
||||
when(inContainer.isRunningInContainer()).thenReturn(true);
|
||||
when(currentContainerNetworkResolver.resolveContainerIp()).thenReturn(Optional.of("172.24.0.2"));
|
||||
when(currentContainerNetworkResolver.resolveContainerIpOn("rds-net")).thenReturn(Optional.of("172.30.0.5"));
|
||||
return new DockerHostResolver(config, inContainer, currentContainerNetworkResolver);
|
||||
}
|
||||
|
||||
private static EmulatorConfig config(String hostOverride) {
|
||||
return config(hostOverride, null);
|
||||
}
|
||||
|
||||
private static EmulatorConfig config(String hostOverride, String lambdaDockerHostOverride) {
|
||||
EmulatorConfig config = mock(EmulatorConfig.class);
|
||||
EmulatorConfig.DockerConfig docker = mock(EmulatorConfig.DockerConfig.class);
|
||||
EmulatorConfig.ServicesConfig services = mock(EmulatorConfig.ServicesConfig.class);
|
||||
EmulatorConfig.LambdaServiceConfig lambda = mock(EmulatorConfig.LambdaServiceConfig.class);
|
||||
when(config.docker()).thenReturn(docker);
|
||||
when(config.services()).thenReturn(services);
|
||||
when(services.lambda()).thenReturn(lambda);
|
||||
when(lambda.dockerHostOverride()).thenReturn(Optional.ofNullable(dockerHostOverride));
|
||||
when(docker.hostOverride()).thenReturn(Optional.ofNullable(hostOverride));
|
||||
when(lambda.dockerHostOverride()).thenReturn(Optional.ofNullable(lambdaDockerHostOverride));
|
||||
when(config.effectiveDockerHostOverride()).thenCallRealMethod();
|
||||
return config;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -184,7 +184,7 @@ class CloudFormationCustomResourceHttpsResponseUrlIntegrationTest {
|
||||
overrides.put("quarkus.http.test-port", "4510");
|
||||
overrides.put("quarkus.http.test-ssl-port", "4511");
|
||||
overrides.put("floci.port", String.valueOf(FLOCI_PORT));
|
||||
overrides.put("floci.services.lambda.docker-host-override", "localhost");
|
||||
overrides.put("floci.docker.host-override", "localhost");
|
||||
return overrides;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,13 +8,11 @@ io.floci.aws.config.TlsCertificateManager io.floci.aws.services.acm.model.KeyAlg
|
||||
io.floci.aws.config.TlsConfigSource io.floci.aws.services.acm.CertificateGenerator
|
||||
io.floci.aws.config.TlsConfigSource io.floci.aws.services.acm.model.KeyAlgorithm
|
||||
io.floci.aws.config.TlsProxyServer services().iot()
|
||||
io.floci.aws.config.TlsProxyServer services().lambda()
|
||||
io.floci.aws.core.common.docker.ContainerBuilder io.floci.aws.services.lambda.launcher.ImageCacheService
|
||||
io.floci.aws.core.common.docker.ContainerLifecycleManager EcsServiceConfig
|
||||
io.floci.aws.core.common.docker.ContainerLifecycleManager io.floci.aws.services.lambda.launcher.ImageCacheService
|
||||
io.floci.aws.core.common.docker.ContainerLifecycleManager io.floci.aws.services.lambda.launcher.ImageCacheService.LaunchImage
|
||||
io.floci.aws.core.common.docker.ContainerLogStreamer io.floci.aws.services.cloudwatch.logs.CloudWatchLogsService
|
||||
io.floci.aws.core.common.docker.DockerHostResolver services().lambda()
|
||||
io.floci.aws.core.common.docker.LaunchedContainerAwsEnv io.floci.aws.services.iam.model.SessionCreds
|
||||
io.floci.aws.core.common.port.PortAllocator services().lambda()
|
||||
io.floci.aws.lifecycle.EmulatorInfoController io.floci.aws.services.dynamodb.backend.DynamoDbBackendSelector
|
||||
|
||||
|
Reference in new issue
Block a user