mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 14:10:49 -05:00
* feat(lambda): GetAccountSettings with usage-derived account limits Adds the Lambda GetAccountSettings operation. AccountUsage (total code size and function count) is derived from the caller's stored $LATEST functions in the region; AccountLimit reports the configured regional concurrency limit and its unreserved share after per-function reserved concurrency. * fix(lambda): widen the default Runtime API port pool to 12000-12499 One Runtime API port is held for the lifetime of each running Lambda container, so the width of the range is a hard ceiling on concurrent Lambda executions. The old default of 9200-9299 gave 100, which a multi-account AWS Landing Zone Accelerator deployment exhausts: it fans out several custom-resource Lambdas per account and can want well over a hundred at once. Exhaustion did not announce itself as a capacity limit either. The custom resource reported FAILED and CloudFormation rolled the stack back, so an operator saw an apparently unrelated CloudFormation error with no hint that a port pool was the cause. 12000 rather than a widened 9200 because the old range's tail collides with ports floci and its sidecars already use: 9200 is OpenSearch's own REST port, 9400-9499 is the OpenSearch host-binding pool, 9092 is Kafka and 9644 Redpanda's admin port. Both application.yml and the @WithDefault annotation are updated. application.yml is a config source, not a set of defaults, so a value set there wins over the annotation; changing only the annotation would have been a silent no-op (issue #2225). The new test asserts the two agree, so they cannot drift apart again. Refs #2206 * fix(lambda): make the Runtime API port-pool exhaustion error self-describing The old message did not name the pool, its width, or the property that widens it. It also rarely reaches an operator directly: the Lambda failure surfaces as a custom resource reporting FAILED and CloudFormation rolling the stack back, so this text is buried in floci's own log alongside a CloudFormation error that looks unrelated. The message now carries its own diagnosis — which pool ran dry, how many ports it had, that one port is held per running container so this is the concurrent-execution ceiling, and the two properties that widen it. Previously the only way to learn those knobs existed was to find this class in the source. Refs #2206 * feat(lambda): add ListFunctionsByCodeSigningConfig Net-new endpoint, GET /2020-04-22/code-signing-configs/{arn}/functions, always returns an empty FunctionArns list since this codebase has no CodeSigningConfig management (no Create/PutFunctionCodeSigningConfig), so no function can ever actually have one attached. Implemented as its own controller class with its own class-level @Path("/2020-04-22") rather than folding it into the existing LambdaCodeSigningController (/2020-06-30): a JAX-RS class-level @Path is load-bearing for route-matching priority, and stripping it to share one class across two API-version prefixes causes both endpoints to fall through to a more general catch-all route elsewhere in the app. * fix(lambda): scope code storage, publish-version counters, and S3 sync-reload to the owning account CodeStore resolved extracted code to baseDir/<functionName> with no account segment, so two accounts' same-named functions in one region shared a single on-disk directory and overwrote each other's package -- while codeObjectKey already wrote the same package to an account-prefixed S3 key. Cross-account invoke resolves a function by the ARN's own account, so a collision here silently serves one account's code under the other's ARN. The PublishVersion counter was keyed region+"::"+functionName and the delete path removed that same unscoped key; both now key on the owning account, via the shared ownerAccount() helper the S3 key already used. onS3ObjectUpdated runs on the CDI event thread with no RequestContext, so its ambient scan only ever saw the default account's partition and its save wrote back into that partition. It now lists across every account (keeping the region and $LATEST filters) and saves into the function's own account. listAll(), whose only caller is the startup concurrency rehydration, is broadened the same way so a restart no longer drops non-default accounts' reserved concurrency. Recovered from 613db7bd1, re-derived onto upstream's current shape: CodeStore's methods are re-signed rather than overloaded (the unscoped forms had no remaining consumer), and the sync-reload uses a new region-filtered listAllAccounts() instead of widening listAll() at that call site. * fix(lambda): carry persisted version counters across the account-scoped key change The counter map is persisted precisely so a restart cannot re-issue a version number that already names a snapshot. Re-keying it on the owning account made every pre-existing entry unreachable, so the next PublishVersion on an upgraded deployment would have started again at 1 and overwritten the live :1 snapshot. The counter now adopts and clears the pre-account key on a miss, and deleting a function clears both forms. Also covers the widened listAll(): the reserved-concurrency pool is per region and shared across accounts, so the startup rehydration that feeds it has to see every account or a restart silently frees capacity that steady-state PutFunctionConcurrency had already accounted for. * fix(lambda): validate CodeSigningConfigArn on ListFunctionsByCodeSigningConfig The handler took @PathParam("codeSigningConfigArn") and never read it, so any input — including "not-an-arn" — got a 200 with an empty FunctionArns array. It also dropped the modeled Marker/MaxItems query parameters. Botocore models InvalidParameterValueException (400) and ResourceNotFoundException (404) for this operation, and carries a pattern on the CodeSigningConfigArn shape: arn:(aws[a-zA-Z-]*)?:lambda:[a-z]{2}((-gov)|(-iso(b?)))?-[a-z]+-\d{1} :\d{12}:code-signing-config:csc-[a-z0-9]{17} (max 200 chars). That pattern is now applied verbatim, whole-string. The 404 for a well-formed ARN is a derivation, not an observation against real AWS: ResourceNotFoundException is modeled for this operation, the only resource the path parameter can name is a code-signing config, and Floci implements no CreateCodeSigningConfig / PutFunctionCodeSigningConfig — therefore every well-formed ARN necessarily names a config that does not exist. The previous always-empty 200 asserted the opposite (config exists, has no functions), which is the stronger and false claim. Validation order matches AWS: ARN shape, then MaxItems range (botocore MaxListItems: min 1, max 10000), then resource resolution — so a bad MaxItems is reported as such instead of being masked by the not-found. Marker is accepted and stateless: the result set is always empty, so no NextMarker is ever emitted. The pre-existing test asserted the 200-empty behaviour using an ARN whose csc- suffix was 9 characters, which the model's pattern rejects; it is replaced by six cases covering the two error classes and both MaxItems bounds. docs/services/lambda.md's two "always empty" claims are corrected to match. * docs(lambda): derive the operation count from the routed operations The branch adds two operations (GetAccountSettings and ListFunctionsByCodeSigningConfig) but bumped docs/services/index.md by one, 30 -> 31. Rather than hand-correcting to 32, the count was re-derived from the routes, because 30 could not be reconstructed from anything in the tree. index.md's own preamble states the rule for REST services: "the count reflects distinct AWS SDK operations, collapsing routes where one JAX-RS handler fans out via query-string or header markers". Counting JAX-RS methods across the Lambda controllers on upstream/main gives: LambdaController 24 LambdaConcurrencyController 3 LambdaEventInvokeController 5 LambdaLayerController 5 LambdaTagController 3 LambdaUrlController 4 -- 44 Two collapses applied. LambdaCodeSigningController's /2020-06-30 route and LambdaController's /2015-03-31 route are the same SDK operation (GetFunctionCodeSigningConfig) and count once. LambdaUrlInvocationController (5) and the lambda-package ApiGatewayController (5) are data-plane proxies with {proxy: .*} catch-alls, not Lambda SDK operations, so they are excluded. 44 + GetAccountSettings + ListFunctionsByCodeSigningConfig = 46. Corroboration that 44 is the real base and 30 is drift: docs/services/lambda.md's Supported Operations table lists 34 rows on upstream/main and omits exactly the 5 layer and 5 event-invoke operations — 34 + 10 = 44. Those 10 missing table rows are pre-existing and left alone here; only the count is in scope. * fix(lambda): match the current CodeSigningConfigArn pattern for isolated partitions The inlined regex predated the model's (eusc-)? prefix and widened -iso(b?) alternation, so a well-formed ARN in aws-iso-e/iso-f or the European sovereign cloud was rejected as malformed instead of reaching the modeled 404. * fix(lambda): validate FunctionName length, Role ARN, and Handler on config paths botocore models FunctionName up to 256 chars with dots allowed in the name segment; LambdaArnUtils rejected dots and never bounded length. Also close the gap where UpdateFunctionConfiguration accepted a malformed Role ARN or a whitespace-containing/oversized Handler and stored it verbatim. * fix(lambda): close leaked directory-listing streams and block dot-segment traversal in CodeStore Files.walk/Files.list returned streams that were never closed, leaking file descriptors and making delete() flaky on platforms that refuse to remove an open file. Separately, sanitizeName replaced disallowed characters but let a segment consisting entirely of dots (".", "..") pass through untouched, so an account or function name of exactly ".." resolved outside baseDir via Path.resolve instead of being rejected. * fix(lambda): reclaim pre-account-scoped code directories on delete and update A function created before code storage was account-scoped left its extracted code at <codePath>/<functionName>. DeleteFunction only ever targeted the new <codePath>/<accountId>/<functionName> path, and UpdateFunctionCode re-extracted to the new path without touching the old one, so the legacy directory (and its disk usage) lingered indefinitely after either operation. CodeStore now also clears the legacy path on delete, and re-extraction reclaims it on success. * fix(lambda): reject an explicit null Handler on UpdateFunctionConfiguration validateHandler treated null as "clear the handler", matching how Description is handled, but null is not a string at all -- and unlike Description, Handler names the file AWS invokes. A request with "Handler": null silently cleared it instead of failing with a 400, which would have broken every subsequent invocation of the function instead of the one bad request that caused it. * fix(lambda): do not reclaim a legacy code directory another account's function still uses The pre-account-scoped layout gave every account's same-named function the exact same on-disk directory. CodeStore.delete() and code re-extraction both reclaimed that legacy directory unconditionally once a function migrated to the account-scoped path, so a delete or code update in one account could destroy the legacy directory while another account's never-migrated $LATEST still served invocations from it -- its next cold start would then fail with a missing code directory. CodeStore.delete() no longer touches the legacy path at all; only LambdaService calls deleteLegacy() explicitly, after checking every account's $LATEST functions (via the existing cross-account listAllAccounts) for one still pointing its codeLocalPath at that directory. * fix(lambda): check published versions, not just $LATEST, before reclaiming a legacy code directory publishVersion snapshots codeLocalPath verbatim (required so a version-qualified invoke doesn't launch a container with no code, #1987), so a version published while $LATEST was still on the pre-account-scoped legacy path keeps that directory alive on its own after $LATEST migrates. The unused-check only scanned $LATEST records via listAllAccounts(region), so a later delete or code update reclaimed the directory out from under that published version's own future invokes. Switched to functionStore.listAll(), which has no $LATEST or region filter, matching the fact that the legacy path itself carries neither. * fix(lambda): close a publish-vs-legacy-cleanup race on the code directory publishVersion read codeLocalPath and persisted a snapshot of it with no synchronization against extractZipCodeBytes's/deleteFunction's decision to reclaim the pre-account-scoped legacy code directory (added inbede98fc1andf3837be32). A version could be published in the narrow window between that decision (finding no live reference) and the actual delete, persisting a snapshot whose codeLocalPath names a directory that is about to be removed -- its own future invocation would then fail with "Code directory not found". publishVersion and the reclaim call in extractZipCodeBytes now both take the same per-function lock deleteFunction already used for this. Proven with a test that holds the lock externally and asserts publishVersion blocks until it is released, rather than relying on timing to catch the race in the act.
244 lines
11 KiB
Markdown
244 lines
11 KiB
Markdown
# Docker Configuration
|
|
|
|
Floci spawns real Docker containers for services that need them: Lambda, RDS, ElastiCache, OpenSearch, MSK, and ECS. All of these share the same Docker client configuration, controlled under `floci.docker`.
|
|
|
|
## Docker Daemon Socket
|
|
|
|
By default Floci connects to the local Docker daemon via the Unix socket. Override it with `docker-host` when needed (e.g. a remote Docker host or a non-standard socket path):
|
|
|
|
```yaml
|
|
floci:
|
|
docker:
|
|
docker-host: unix:///var/run/docker.sock
|
|
```
|
|
|
|
**Running natively on Windows** (not inside WSL or a container): Windows has no equivalent of `/var/run/docker.sock`, so when `docker-host` is left at its default and `DOCKER_HOST` isn't set, Floci automatically falls back to Docker Desktop's named pipe (`npipe:////./pipe/docker_engine`) instead. An explicit `docker-host` or `DOCKER_HOST` always takes priority over this fallback.
|
|
|
|
Environment variable: `FLOCI_DOCKER_DOCKER_HOST`
|
|
|
|
When running Floci inside Docker Compose, mount the host socket:
|
|
|
|
```yaml
|
|
services:
|
|
floci:
|
|
volumes:
|
|
- /var/run/docker.sock:/var/run/docker.sock
|
|
```
|
|
|
|
## Private Registry Authentication
|
|
|
|
Any service that pulls a container image from a private registry (Lambda image functions, custom OpenSearch images, private Postgres images, etc.) needs Docker credentials. Two approaches are supported and can be combined.
|
|
|
|
### Mount the host Docker config
|
|
|
|
Reuses existing `docker login` sessions and credential helpers from the host machine. Mount the host `~/.docker` directory and point Floci at it:
|
|
|
|
```yaml
|
|
services:
|
|
floci:
|
|
volumes:
|
|
- /var/run/docker.sock:/var/run/docker.sock
|
|
- ~/.docker:/root/.docker:ro
|
|
environment:
|
|
FLOCI_DOCKER_DOCKER_CONFIG_PATH: /root/.docker
|
|
```
|
|
|
|
Or in `application.yml`:
|
|
|
|
```yaml
|
|
floci:
|
|
docker:
|
|
docker-config-path: /root/.docker
|
|
```
|
|
|
|
This works with any credential helper configured on the host (`docker-credential-desktop`, `ecr-credential-helper`, etc.) as long as the helper binary is also available inside the Floci container.
|
|
|
|
### Explicit per-registry credentials
|
|
|
|
For CI environments or air-gapped setups where mounting the host filesystem is not practical:
|
|
|
|
```yaml
|
|
services:
|
|
floci:
|
|
environment:
|
|
FLOCI_DOCKER_REGISTRY_CREDENTIALS_0__SERVER: myregistry.example.com
|
|
FLOCI_DOCKER_REGISTRY_CREDENTIALS_0__USERNAME: myuser
|
|
FLOCI_DOCKER_REGISTRY_CREDENTIALS_0__PASSWORD: mypassword
|
|
# Add more registries by incrementing the index:
|
|
# FLOCI_DOCKER_REGISTRY_CREDENTIALS_1__SERVER: other.registry.io
|
|
# FLOCI_DOCKER_REGISTRY_CREDENTIALS_1__USERNAME: ...
|
|
# FLOCI_DOCKER_REGISTRY_CREDENTIALS_1__PASSWORD: ...
|
|
```
|
|
|
|
Or in `application.yml`:
|
|
|
|
```yaml
|
|
floci:
|
|
docker:
|
|
registry-credentials:
|
|
- server: myregistry.example.com
|
|
username: myuser
|
|
password: mypassword
|
|
- server: other.registry.io
|
|
username: otheruser
|
|
password: otherpassword
|
|
```
|
|
|
|
The `server` field must match the registry hostname exactly as it appears in the image URI (e.g. `myregistry.example.com` for `myregistry.example.com/repo:tag`). Docker Hub images (e.g. `ubuntu:22.04`) have an empty hostname and are not matched by any explicit credential entry — use the Docker config mount approach for Docker Hub authentication.
|
|
|
|
### Precedence
|
|
|
|
Explicit credentials take precedence for registries they cover. For everything else, Floci falls back to the Docker config file (if `docker-config-path` is set) and then to an anonymous pull.
|
|
|
|
## Container Log Settings
|
|
|
|
Configure log rotation for all containers spawned by Floci:
|
|
|
|
```yaml
|
|
floci:
|
|
docker:
|
|
log-max-size: "10m" # Max size per log file before rotation (Docker json-file format)
|
|
log-max-file: "3" # Number of rotated log files to retain per container
|
|
```
|
|
|
|
## Container Labels
|
|
|
|
Every container and volume Floci creates carries three reserved labels for discovery and cleanup:
|
|
|
|
| Label | Value | Purpose |
|
|
|---|---|---|
|
|
| `floci` | `true` | Umbrella across all Floci emulators — `docker ps --filter label=floci=true` |
|
|
| `floci_emulator` | `floci-aws` | Per-emulator discriminator |
|
|
| `floci_namespace` | *(the configured namespace)* | Only present when `resource-namespace` is set |
|
|
|
|
Add your own labels with `extra-labels` — they are applied to every container **and** volume Floci creates (Lambda functions and code volumes, RDS databases, ElastiCache, OpenSearch, MSK, ECS, ...):
|
|
|
|
```yaml
|
|
floci:
|
|
docker:
|
|
extra-labels:
|
|
- key: "com.example.project"
|
|
value: my-project
|
|
- key: environment
|
|
value: dev
|
|
```
|
|
|
|
Or via environment variables (indexed entries, like `registry-credentials`):
|
|
|
|
```yaml
|
|
services:
|
|
floci:
|
|
environment:
|
|
FLOCI_DOCKER_EXTRA_LABELS_0__KEY: "com.example.project"
|
|
FLOCI_DOCKER_EXTRA_LABELS_0__VALUE: my-project
|
|
FLOCI_DOCKER_EXTRA_LABELS_1__KEY: environment
|
|
FLOCI_DOCKER_EXTRA_LABELS_1__VALUE: dev
|
|
```
|
|
|
|
Extra labels are a list of key/value entries rather than a map so that label keys containing dots, colons, or uppercase characters survive the environment-variable naming convention.
|
|
|
|
!!! note
|
|
Entries using one of the reserved keys (`floci`, `floci_emulator`, `floci_namespace`) are ignored with a warning — user configuration can never break Floci's own container discovery and volume pruning.
|
|
|
|
### Resource Identity Labels
|
|
|
|
A container backing an emulated AWS resource also carries labels tying it back to that resource, additive to the labels above:
|
|
|
|
| Label | Value | Purpose |
|
|
|---|---|---|
|
|
| `io.floci` | `aws` | Cloud provider, for multi-cloud discovery when several Floci-like emulators share a host |
|
|
| `io.floci.service` | e.g. `rds` | The AWS service the container backs |
|
|
| `io.floci.resource-id` | e.g. `orders-db-primary` | The resource's identifier (DB instance identifier, cluster name, function name, ...) |
|
|
| `io.floci.account` | the resolved account id | The AWS account the resource belongs to |
|
|
| `io.floci.region` | the resolved region | The AWS region the resource belongs to |
|
|
|
|
This makes `docker ps --filter label=io.floci.resource-id=orders-db-primary` resolve a specific emulated resource to its backing container directly, without inferring it from names or creation order. Applied to RDS, DocDB, ElastiCache (Redis/Valkey and Memcached), MemoryDB, Neptune, MSK, OpenSearch, ECS, EKS, AmazonMQ, MWAA, Kinesis Data Analytics (Flink), Batch, CodeBuild, Lambda, and EC2. ECR's backing registry container carries every label except `io.floci.resource-id`, since it is a shared singleton with no single resource identifier.
|
|
|
|
## Docker Network
|
|
|
|
Containers spawned by Floci (Lambda, RDS, ElastiCache, OpenSearch, MSK, ECS) need to be on the same Docker network to communicate with each other and with Floci itself.
|
|
|
|
When Floci itself runs inside Docker and no network is configured, it automatically detects the current container's Docker network and uses it for spawned containers. You only need to set this manually when you want to force a specific network.
|
|
|
|
Set the shared network at the top level:
|
|
|
|
```yaml
|
|
floci:
|
|
services:
|
|
docker-network: my-project_default
|
|
```
|
|
|
|
Environment variable: `FLOCI_SERVICES_DOCKER_NETWORK`
|
|
|
|
Individual services can override the network with their own `docker-network` setting (e.g. `floci.services.lambda.docker-network`).
|
|
|
|
!!! tip
|
|
In Docker Compose, the default network name is `<project-name>_default`. If your compose file is in a directory named `myapp`, the network is `myapp_default`.
|
|
|
|
## Running on Podman (rootless)
|
|
|
|
Floci runs under rootless Podman, but Podman's network topology needs a few
|
|
explicit settings that Docker handles automatically. The following configuration
|
|
is known to work:
|
|
|
|
```bash
|
|
podman network create floci-net
|
|
|
|
podman run -d --name floci \
|
|
--network floci-net \
|
|
-p 4566:4566 \
|
|
-v /run/user/$(id -u)/podman/podman.sock:/var/run/docker.sock:z \
|
|
-e FLOCI_SERVICES_LAMBDA_DOCKER_NETWORK=floci-net \
|
|
-e FLOCI_HOSTNAME=floci \
|
|
floci/floci
|
|
```
|
|
|
|
What each setting does and why it is needed:
|
|
|
|
- **Named network (`floci-net`)** — the rootless default bridge does not assign
|
|
reachable IPs between containers, so spawned Lambda containers cannot reach
|
|
Floci. Create a named network and put both Floci and its Lambda containers on it.
|
|
- **`FLOCI_SERVICES_LAMBDA_DOCKER_NETWORK=floci-net`** — makes Floci attach the
|
|
Lambda containers it spawns to that same named network.
|
|
- **`FLOCI_HOSTNAME=floci`** — gives Floci a stable name that Lambda containers
|
|
resolve when calling back to the Runtime API.
|
|
- **`:z` on the socket mount** — relabels the Podman socket for SELinux. Without
|
|
it, Floci fails to talk to the Podman socket: Lambda/ECR container creation
|
|
errors with `java.io.IOException: Broken pipe`, and the **Floci UI** sidecar
|
|
fails to launch with `java.net.BindException: Permission denied`. Use the
|
|
lowercase `:z` (shared relabel) rather than `:Z` — the Podman API socket is
|
|
shared with the Podman service, and `:Z` applies a container-private SELinux
|
|
label that can break access. If `:z` is still not enough on your host, fall
|
|
back to `--security-opt label=disable`.
|
|
|
|
!!! tip "When the Runtime API address is still unreachable"
|
|
On some Podman network topologies the auto-detected Runtime API address
|
|
(the host/IP Lambda containers use to call back into Floci) is still wrong,
|
|
and invocations fail with `connect ECONNREFUSED <ip>:12000`. Set the address
|
|
explicitly to bypass auto-detection:
|
|
|
|
```bash
|
|
FLOCI_SERVICES_LAMBDA_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.
|
|
|
|
## Full Reference
|
|
|
|
| Environment variable | Default | Description |
|
|
|---|---|---|
|
|
| `FLOCI_DOCKER_DOCKER_HOST` | `unix:///var/run/docker.sock` | Docker daemon socket |
|
|
| `FLOCI_DOCKER_DOCKER_CONFIG_PATH` | _(unset)_ | Path to directory containing Docker's `config.json` |
|
|
| `FLOCI_DOCKER_REGISTRY_CREDENTIALS_0__SERVER` | _(unset)_ | Registry hostname for credential entry 0 |
|
|
| `FLOCI_DOCKER_REGISTRY_CREDENTIALS_0__USERNAME` | _(unset)_ | Username for credential entry 0 |
|
|
| `FLOCI_DOCKER_REGISTRY_CREDENTIALS_0__PASSWORD` | _(unset)_ | Password for credential entry 0 |
|
|
| `FLOCI_DOCKER_LOG_MAX_SIZE` | `10m` | Max container log file size before rotation |
|
|
| `FLOCI_DOCKER_LOG_MAX_FILE` | `3` | Number of rotated log files to retain |
|
|
| `FLOCI_DOCKER_EXTRA_LABELS_0__KEY` | _(unset)_ | Label key for extra-label entry 0, applied to every Floci-created container and volume (increment the index for more) |
|
|
| `FLOCI_DOCKER_EXTRA_LABELS_0__VALUE` | _(unset)_ | Label value for extra-label entry 0 |
|
|
| `FLOCI_SERVICES_DOCKER_NETWORK` | _(unset)_ | Shared Docker network for all container-based services |
|
|
| `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). Must be a valid Docker name segment (`[A-Za-z0-9][A-Za-z0-9_.-]*`); invalid values are ignored with a warning. See the [Lambda docs](../services/lambda.md#configuration) |
|