mirror of
https://github.com/floci-io/floci-cli.git
synced 2026-11-22 21:50:47 -05:00
feat(start): add --security-opt so Floci can reach the socket on SELinux hosts (#70)
* feat(start): add --security-opt so Floci can reach the socket on SELinux hosts With SELinux enforcing, as in the podman machine VM, the emulator cannot connect to the mounted Podman socket: the kernel denies connectto from container_t to the daemon's container_runtime_t, and the web console fails with java.net.BindException: Permission denied. Relabeling the mount with :z fixes access to the socket file but not that check. --security-opt label=disable gets past it, and start had no way to pass it. The option is repeatable and goes to docker run unchanged. A restart without --profile reads it back from the running container, like the port, image and services; with --profile the start is rebuilt from the profile, which has no key for it. docker inspect reports a seccomp profile file inline, which docker run rejects, so such a value fails start's validation, and with it the restart, before the stop removes the container. Signed-off-by: soreavis <263610811+soreavis@users.noreply.github.com> * fix(start): keep --security-opt in retry and recovery commands The failed-pull hint and the restart recovery command rebuild the start from its flags, so they dropped --security-opt and a retry lost label=disable. Carry it into both, shell-quoted. The README's profile workaround stopped the default instance: name the same profile and product on stop as on start. Signed-off-by: soreavis <263610811+soreavis@users.noreply.github.com> --------- Signed-off-by: soreavis <263610811+soreavis@users.noreply.github.com>
This commit is contained in:
1 parent
587860da0f
commit
3c70876448
16 files changed
+216
-120
No files matched your search
@@ -474,6 +474,23 @@ For a `unix://` socket the resolved path is bind-mounted into the container; for
|
||||
remote `tcp://` daemon the `DOCKER_HOST` value is passed through to the container
|
||||
instead. Run `floci doctor` to see which endpoint was resolved.
|
||||
|
||||
With SELinux enforcing (for example the Fedora VM behind `podman machine`), the container's label
|
||||
keeps Floci from connecting to the socket, and the web console fails to start with
|
||||
`java.net.BindException: Permission denied`. Relabeling the mount with `:z` is not enough: it fixes
|
||||
access to the socket file, but SELinux also checks the daemon on the other end of the socket. Turn
|
||||
labeling off for the Floci container instead:
|
||||
|
||||
```sh
|
||||
floci start --security-opt label=disable
|
||||
```
|
||||
|
||||
`--security-opt` is passed to `docker run` unchanged and can be repeated. Without `--profile`,
|
||||
`floci restart` passes back the options `docker inspect` reports for the running container. With
|
||||
`--profile` it starts from the profile, which has no key for them: run
|
||||
`floci <product> stop --profile <name> --remove`, then
|
||||
`floci <product> start --profile <name> --security-opt ...`, where `<product>` is the profile's
|
||||
`aws`, `gcp`, `az` or `oci`.
|
||||
|
||||
### `floci stop` / `floci gcp stop` / `floci az stop` / `floci oci stop`
|
||||
|
||||
```sh
|
||||
@@ -979,7 +996,7 @@ Where a command's codes carry a specific meaning a script can rely on:
|
||||
| `doctor` | every check passed (warnings allowed) | at least one check failed | `--check` names no known check |
|
||||
| `update --check` | up to date | an update is available | the check itself failed |
|
||||
| `update` | updated, or already up to date | the update failed; the binary is unchanged | `--version` is not a release version |
|
||||
| `start`, `restart` | started (and ready, unless `--detach`) | Docker, the image, the port or readiness failed, or the `--persist` directory cannot be created | `--port`, `--pull`, the namespace or the `--persist` path is not valid |
|
||||
| `start`, `restart` | started (and ready, unless `--detach`) | Docker, the image, the port or readiness failed, or the `--persist` directory cannot be created | `--port`, `--pull`, the namespace, the `--persist` path or a `--security-opt seccomp=` value is not valid |
|
||||
| `stop` | stopped, or was not running | no such container, or Docker failed | bad flag or profile |
|
||||
| `reset` | state reset | declined, not available on this server, no running instance to reset, or the configuration names two different servers | no terminal to ask on and no `--yes` |
|
||||
| `config validate` | no errors (warnings allowed) | errors found, or the file cannot be read | bad flag |
|
||||
|
||||
@@ -1,27 +1,29 @@
|
||||
Usage: floci aws start [-hqvV] [--detach] [--json] [--no-color] [--no-emoji] [--container=<name>]
|
||||
[--endpoint=<url>] [--image=<ref>] [--namespace=<name>] [-o=text|json|yaml]
|
||||
[--persist=<dir>] [--port=<port>] [--profile=<name>]
|
||||
[--pull=always|missing|never] [--services=<csv>]
|
||||
[--pull=always|missing|never] [--services=<csv>] [--security-opt=<opt>]...
|
||||
Start the Floci AWS emulator container
|
||||
--container=<name> Floci container name (default: floci)
|
||||
--detach Return immediately without waiting for readiness
|
||||
--endpoint=<url> Floci server endpoint URL (default: http://localhost:4566)
|
||||
-h, --help Show this help message and exit.
|
||||
--image=<ref> Image reference to use (default: floci/floci:latest)
|
||||
--json Shorthand for --output json
|
||||
--namespace=<name> Docker resource namespace for the containers this instance launches
|
||||
(default: derived from --container; none for the default container)
|
||||
--no-color Disable ANSI colors
|
||||
--no-emoji Plain ASCII marks instead of Unicode ones (the default when output is
|
||||
piped)
|
||||
--container=<name> Floci container name (default: floci)
|
||||
--detach Return immediately without waiting for readiness
|
||||
--endpoint=<url> Floci server endpoint URL (default: http://localhost:4566)
|
||||
-h, --help Show this help message and exit.
|
||||
--image=<ref> Image reference to use (default: floci/floci:latest)
|
||||
--json Shorthand for --output json
|
||||
--namespace=<name> Docker resource namespace for the containers this instance launches
|
||||
(default: derived from --container; none for the default container)
|
||||
--no-color Disable ANSI colors
|
||||
--no-emoji Plain ASCII marks instead of Unicode ones (the default when output is
|
||||
piped)
|
||||
-o, --output=text|json|yaml
|
||||
Output format: text, json, yaml
|
||||
--persist=<dir> Host directory for persistent state
|
||||
--port=<port> Host port to bind (default: 4566)
|
||||
--profile=<name> Config profile from ~/.floci/profiles/
|
||||
Output format: text, json, yaml
|
||||
--persist=<dir> Host directory for persistent state
|
||||
--port=<port> Host port to bind (default: 4566)
|
||||
--profile=<name> Config profile from ~/.floci/profiles/
|
||||
--pull=always|missing|never
|
||||
Image pull policy: always, missing, never
|
||||
-q, --quiet Suppress non-error output
|
||||
--services=<csv> Comma-separated list of services to enable
|
||||
-v, --verbose Debug logging to stderr
|
||||
-V, --version Print version information and exit.
|
||||
Image pull policy: always, missing, never
|
||||
-q, --quiet Suppress non-error output
|
||||
--security-opt=<opt> Docker security option for the emulator container, repeatable
|
||||
(label=disable lets it reach the Docker socket on SELinux hosts)
|
||||
--services=<csv> Comma-separated list of services to enable
|
||||
-v, --verbose Debug logging to stderr
|
||||
-V, --version Print version information and exit.
|
||||
@@ -1,27 +1,29 @@
|
||||
Usage: floci az start [-hqvV] [--detach] [--json] [--no-color] [--no-emoji] [--container=<name>]
|
||||
[--endpoint=<url>] [--image=<ref>] [--namespace=<name>] [-o=text|json|yaml]
|
||||
[--persist=<dir>] [--port=<port>] [--profile=<name>]
|
||||
[--pull=always|missing|never] [--services=<csv>]
|
||||
[--pull=always|missing|never] [--services=<csv>] [--security-opt=<opt>]...
|
||||
Start the Floci Azure emulator container
|
||||
--container=<name> Floci container name (default: floci-az)
|
||||
--detach Return immediately without waiting for readiness
|
||||
--endpoint=<url> Floci server endpoint URL (default: http://localhost:4577)
|
||||
-h, --help Show this help message and exit.
|
||||
--image=<ref> Image reference to use (default: floci/floci-az:latest)
|
||||
--json Shorthand for --output json
|
||||
--namespace=<name> Docker resource namespace for the containers this instance launches
|
||||
(default: derived from --container; none for the default container)
|
||||
--no-color Disable ANSI colors
|
||||
--no-emoji Plain ASCII marks instead of Unicode ones (the default when output is
|
||||
piped)
|
||||
--container=<name> Floci container name (default: floci-az)
|
||||
--detach Return immediately without waiting for readiness
|
||||
--endpoint=<url> Floci server endpoint URL (default: http://localhost:4577)
|
||||
-h, --help Show this help message and exit.
|
||||
--image=<ref> Image reference to use (default: floci/floci-az:latest)
|
||||
--json Shorthand for --output json
|
||||
--namespace=<name> Docker resource namespace for the containers this instance launches
|
||||
(default: derived from --container; none for the default container)
|
||||
--no-color Disable ANSI colors
|
||||
--no-emoji Plain ASCII marks instead of Unicode ones (the default when output is
|
||||
piped)
|
||||
-o, --output=text|json|yaml
|
||||
Output format: text, json, yaml
|
||||
--persist=<dir> Host directory for persistent state
|
||||
--port=<port> Host port to bind (default: 4577)
|
||||
--profile=<name> Config profile from ~/.floci/profiles/
|
||||
Output format: text, json, yaml
|
||||
--persist=<dir> Host directory for persistent state
|
||||
--port=<port> Host port to bind (default: 4577)
|
||||
--profile=<name> Config profile from ~/.floci/profiles/
|
||||
--pull=always|missing|never
|
||||
Image pull policy: always, missing, never
|
||||
-q, --quiet Suppress non-error output
|
||||
--services=<csv> Comma-separated list of services to enable
|
||||
-v, --verbose Debug logging to stderr
|
||||
-V, --version Print version information and exit.
|
||||
Image pull policy: always, missing, never
|
||||
-q, --quiet Suppress non-error output
|
||||
--security-opt=<opt> Docker security option for the emulator container, repeatable
|
||||
(label=disable lets it reach the Docker socket on SELinux hosts)
|
||||
--services=<csv> Comma-separated list of services to enable
|
||||
-v, --verbose Debug logging to stderr
|
||||
-V, --version Print version information and exit.
|
||||
@@ -1,27 +1,29 @@
|
||||
Usage: floci gcp start [-hqvV] [--detach] [--json] [--no-color] [--no-emoji] [--container=<name>]
|
||||
[--endpoint=<url>] [--image=<ref>] [--namespace=<name>] [-o=text|json|yaml]
|
||||
[--persist=<dir>] [--port=<port>] [--profile=<name>]
|
||||
[--pull=always|missing|never] [--services=<csv>]
|
||||
[--pull=always|missing|never] [--services=<csv>] [--security-opt=<opt>]...
|
||||
Start the Floci GCP emulator container
|
||||
--container=<name> Floci container name (default: floci-gcp)
|
||||
--detach Return immediately without waiting for readiness
|
||||
--endpoint=<url> Floci server endpoint URL (default: http://localhost:4588)
|
||||
-h, --help Show this help message and exit.
|
||||
--image=<ref> Image reference to use (default: floci/floci-gcp:latest)
|
||||
--json Shorthand for --output json
|
||||
--namespace=<name> Docker resource namespace for the containers this instance launches
|
||||
(default: derived from --container; none for the default container)
|
||||
--no-color Disable ANSI colors
|
||||
--no-emoji Plain ASCII marks instead of Unicode ones (the default when output is
|
||||
piped)
|
||||
--container=<name> Floci container name (default: floci-gcp)
|
||||
--detach Return immediately without waiting for readiness
|
||||
--endpoint=<url> Floci server endpoint URL (default: http://localhost:4588)
|
||||
-h, --help Show this help message and exit.
|
||||
--image=<ref> Image reference to use (default: floci/floci-gcp:latest)
|
||||
--json Shorthand for --output json
|
||||
--namespace=<name> Docker resource namespace for the containers this instance launches
|
||||
(default: derived from --container; none for the default container)
|
||||
--no-color Disable ANSI colors
|
||||
--no-emoji Plain ASCII marks instead of Unicode ones (the default when output is
|
||||
piped)
|
||||
-o, --output=text|json|yaml
|
||||
Output format: text, json, yaml
|
||||
--persist=<dir> Host directory for persistent state
|
||||
--port=<port> Host port to bind (default: 4588)
|
||||
--profile=<name> Config profile from ~/.floci/profiles/
|
||||
Output format: text, json, yaml
|
||||
--persist=<dir> Host directory for persistent state
|
||||
--port=<port> Host port to bind (default: 4588)
|
||||
--profile=<name> Config profile from ~/.floci/profiles/
|
||||
--pull=always|missing|never
|
||||
Image pull policy: always, missing, never
|
||||
-q, --quiet Suppress non-error output
|
||||
--services=<csv> Comma-separated list of services to enable
|
||||
-v, --verbose Debug logging to stderr
|
||||
-V, --version Print version information and exit.
|
||||
Image pull policy: always, missing, never
|
||||
-q, --quiet Suppress non-error output
|
||||
--security-opt=<opt> Docker security option for the emulator container, repeatable
|
||||
(label=disable lets it reach the Docker socket on SELinux hosts)
|
||||
--services=<csv> Comma-separated list of services to enable
|
||||
-v, --verbose Debug logging to stderr
|
||||
-V, --version Print version information and exit.
|
||||
@@ -1,27 +1,29 @@
|
||||
Usage: floci oci start [-hqvV] [--detach] [--json] [--no-color] [--no-emoji] [--container=<name>]
|
||||
[--endpoint=<url>] [--image=<ref>] [--namespace=<name>] [-o=text|json|yaml]
|
||||
[--persist=<dir>] [--port=<port>] [--profile=<name>]
|
||||
[--pull=always|missing|never] [--services=<csv>]
|
||||
[--pull=always|missing|never] [--services=<csv>] [--security-opt=<opt>]...
|
||||
Start the Floci OCI emulator container
|
||||
--container=<name> Floci container name (default: floci-oci)
|
||||
--detach Return immediately without waiting for readiness
|
||||
--endpoint=<url> Floci server endpoint URL (default: http://localhost:4599)
|
||||
-h, --help Show this help message and exit.
|
||||
--image=<ref> Image reference to use (default: floci/floci-oci:latest)
|
||||
--json Shorthand for --output json
|
||||
--namespace=<name> Docker resource namespace for the containers this instance launches
|
||||
(default: derived from --container; none for the default container)
|
||||
--no-color Disable ANSI colors
|
||||
--no-emoji Plain ASCII marks instead of Unicode ones (the default when output is
|
||||
piped)
|
||||
--container=<name> Floci container name (default: floci-oci)
|
||||
--detach Return immediately without waiting for readiness
|
||||
--endpoint=<url> Floci server endpoint URL (default: http://localhost:4599)
|
||||
-h, --help Show this help message and exit.
|
||||
--image=<ref> Image reference to use (default: floci/floci-oci:latest)
|
||||
--json Shorthand for --output json
|
||||
--namespace=<name> Docker resource namespace for the containers this instance launches
|
||||
(default: derived from --container; none for the default container)
|
||||
--no-color Disable ANSI colors
|
||||
--no-emoji Plain ASCII marks instead of Unicode ones (the default when output is
|
||||
piped)
|
||||
-o, --output=text|json|yaml
|
||||
Output format: text, json, yaml
|
||||
--persist=<dir> Host directory for persistent state
|
||||
--port=<port> Host port to bind (default: 4599)
|
||||
--profile=<name> Config profile from ~/.floci/profiles/
|
||||
Output format: text, json, yaml
|
||||
--persist=<dir> Host directory for persistent state
|
||||
--port=<port> Host port to bind (default: 4599)
|
||||
--profile=<name> Config profile from ~/.floci/profiles/
|
||||
--pull=always|missing|never
|
||||
Image pull policy: always, missing, never
|
||||
-q, --quiet Suppress non-error output
|
||||
--services=<csv> Comma-separated list of services to enable
|
||||
-v, --verbose Debug logging to stderr
|
||||
-V, --version Print version information and exit.
|
||||
Image pull policy: always, missing, never
|
||||
-q, --quiet Suppress non-error output
|
||||
--security-opt=<opt> Docker security option for the emulator container, repeatable
|
||||
(label=disable lets it reach the Docker socket on SELinux hosts)
|
||||
--services=<csv> Comma-separated list of services to enable
|
||||
-v, --verbose Debug logging to stderr
|
||||
-V, --version Print version information and exit.
|
||||
+23
-21
@@ -1,27 +1,29 @@
|
||||
Usage: floci start [-hqvV] [--detach] [--json] [--no-color] [--no-emoji] [--container=<name>]
|
||||
[--endpoint=<url>] [--image=<ref>] [--namespace=<name>] [-o=text|json|yaml]
|
||||
[--persist=<dir>] [--port=<port>] [--profile=<name>]
|
||||
[--pull=always|missing|never] [--services=<csv>]
|
||||
[--pull=always|missing|never] [--services=<csv>] [--security-opt=<opt>]...
|
||||
Start the Floci AWS emulator container
|
||||
--container=<name> Floci container name (default: floci)
|
||||
--detach Return immediately without waiting for readiness
|
||||
--endpoint=<url> Floci server endpoint URL (default: http://localhost:4566)
|
||||
-h, --help Show this help message and exit.
|
||||
--image=<ref> Image reference to use (default: floci/floci:latest)
|
||||
--json Shorthand for --output json
|
||||
--namespace=<name> Docker resource namespace for the containers this instance launches
|
||||
(default: derived from --container; none for the default container)
|
||||
--no-color Disable ANSI colors
|
||||
--no-emoji Plain ASCII marks instead of Unicode ones (the default when output is
|
||||
piped)
|
||||
--container=<name> Floci container name (default: floci)
|
||||
--detach Return immediately without waiting for readiness
|
||||
--endpoint=<url> Floci server endpoint URL (default: http://localhost:4566)
|
||||
-h, --help Show this help message and exit.
|
||||
--image=<ref> Image reference to use (default: floci/floci:latest)
|
||||
--json Shorthand for --output json
|
||||
--namespace=<name> Docker resource namespace for the containers this instance launches
|
||||
(default: derived from --container; none for the default container)
|
||||
--no-color Disable ANSI colors
|
||||
--no-emoji Plain ASCII marks instead of Unicode ones (the default when output is
|
||||
piped)
|
||||
-o, --output=text|json|yaml
|
||||
Output format: text, json, yaml
|
||||
--persist=<dir> Host directory for persistent state
|
||||
--port=<port> Host port to bind (default: 4566)
|
||||
--profile=<name> Config profile from ~/.floci/profiles/
|
||||
Output format: text, json, yaml
|
||||
--persist=<dir> Host directory for persistent state
|
||||
--port=<port> Host port to bind (default: 4566)
|
||||
--profile=<name> Config profile from ~/.floci/profiles/
|
||||
--pull=always|missing|never
|
||||
Image pull policy: always, missing, never
|
||||
-q, --quiet Suppress non-error output
|
||||
--services=<csv> Comma-separated list of services to enable
|
||||
-v, --verbose Debug logging to stderr
|
||||
-V, --version Print version information and exit.
|
||||
Image pull policy: always, missing, never
|
||||
-q, --quiet Suppress non-error output
|
||||
--security-opt=<opt> Docker security option for the emulator container, repeatable
|
||||
(label=disable lets it reach the Docker socket on SELinux hosts)
|
||||
--services=<csv> Comma-separated list of services to enable
|
||||
-v, --verbose Debug logging to stderr
|
||||
-V, --version Print version information and exit.
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",
|
||||
"name": "floci",
|
||||
"version": "1.0.4",
|
||||
"version": "1.0.5",
|
||||
"description": "Run, wire up and troubleshoot Floci, the free local emulators for AWS, GCP, Azure and OCI: floci-cli lifecycle, safe wiring of aws, gcloud, az, oci and the SDKs, docker run and Docker Compose files, several instances side by side, and lookups in the published docs.",
|
||||
"author": {
|
||||
"name": "Floci",
|
||||
|
||||
@@ -41,7 +41,10 @@ pass `-o text`. Then check the cloud-specific leaks: SQS endpoint bypass (AWS),
|
||||
**Docker-backed services fail (Lambda, ECS, RDS, Cloud Run, AKS, Functions, OKE)**
|
||||
The emulator cannot reach a Docker daemon. floci-cli resolves `DOCKER_HOST`, then `DOCKER_SOCK`,
|
||||
then the OS default socket. For Podman: `export DOCKER_HOST=unix:///run/user/$(id -u)/podman/podman.sock`.
|
||||
`doctor` shows the resolved endpoint. In Compose, mount the socket explicitly.
|
||||
`doctor` shows the resolved endpoint. In Compose, mount the socket explicitly. With SELinux
|
||||
enforcing (for example the `podman machine` VM), `java.net.BindException: Permission denied` means
|
||||
the container's label blocks the socket: run `floci <tree> start --security-opt label=disable`
|
||||
(`docker run` takes the same flag). Relabeling the mount with `:z` is not enough.
|
||||
|
||||
**Child containers vanish or another instance's tasks get killed**
|
||||
Two instances share a Docker host without distinct namespaces. See namespaces.md.
|
||||
@@ -81,7 +84,8 @@ lists supported operations and gaps. Report it instead of retrying.
|
||||
## Exit codes worth knowing
|
||||
|
||||
- `0` success; non-zero failure for every command.
|
||||
- `2` usage or validation error: bad profile, duration, namespace, port, `--pull` or `--shell`.
|
||||
- `2` usage or validation error: bad profile, duration, namespace, port, `--pull`, `--shell` or an
|
||||
inline `--security-opt seccomp=` profile.
|
||||
- `1` from every snapshot subcommand (`save`, `load`, `list`, `delete`, `export`, `import`) in
|
||||
every tree: not available server-side yet. A name that is a path (`.`, `..`, or with `/`) is
|
||||
`2`, and a bare `floci <tree> snapshot` just prints its usage and exits `0`.
|
||||
|
||||
@@ -157,6 +157,7 @@ public class RestartCommand implements Callable<Integer> {
|
||||
if (services != null) start.services = services;
|
||||
String namespace = run.env().get(profile.envVar("DOCKER_RESOURCE_NAMESPACE"));
|
||||
if (namespace != null) start.namespace = namespace;
|
||||
start.securityOpts = run.securityOpts();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -81,6 +81,9 @@ public class StartCommand implements Callable<Integer> {
|
||||
// Docker's own name rule: the emulators put the namespace inside child container names.
|
||||
private static final Pattern NAMESPACE = Pattern.compile("[A-Za-z0-9][A-Za-z0-9_.-]*");
|
||||
|
||||
@Option(names = {"--security-opt"}, description = "Docker security option for the emulator container, repeatable (label=disable lets it reach the Docker socket on SELinux hosts)", paramLabel = "<opt>")
|
||||
List<String> securityOpts = List.of();
|
||||
|
||||
@Option(names = {"--pull"}, description = "Image pull policy: always, missing, never", defaultValue = "missing", paramLabel = "always|missing|never")
|
||||
String pull;
|
||||
|
||||
@@ -125,6 +128,7 @@ public class StartCommand implements Callable<Integer> {
|
||||
if (global.typed("--persist")) flags.append(" --persist ").append(GlobalOptions.shellWord(persistDir));
|
||||
if (global.typed("--services")) flags.append(" --services ").append(GlobalOptions.shellWord(services));
|
||||
if (global.typed("--namespace")) flags.append(" --namespace ").append(GlobalOptions.shellWord(namespace));
|
||||
if (global.typed("--security-opt")) securityOpts.forEach(opt -> flags.append(" --security-opt ").append(GlobalOptions.shellWord(opt)));
|
||||
return flags.toString();
|
||||
}
|
||||
|
||||
@@ -144,6 +148,7 @@ public class StartCommand implements Callable<Integer> {
|
||||
}
|
||||
if (services != null) command.append(" --services ").append(GlobalOptions.shellWord(services));
|
||||
if (namespace != null) command.append(" --namespace ").append(GlobalOptions.shellWord(namespace));
|
||||
securityOpts.forEach(opt -> command.append(" --security-opt ").append(GlobalOptions.shellWord(opt)));
|
||||
return command.toString();
|
||||
}
|
||||
|
||||
@@ -180,6 +185,14 @@ public class StartCommand implements Callable<Integer> {
|
||||
// Anything else used to fall through to a pull, so a typo silently meant "always".
|
||||
return "Invalid --pull '" + pull + "'.\nUse always, missing or never.";
|
||||
}
|
||||
// docker inspect reports a seccomp profile file inline, so restart would carry it over in a
|
||||
// form docker run rejects, and only after the stop has removed the container.
|
||||
if (securityOpts.stream().anyMatch(opt -> opt.startsWith("seccomp={"))) {
|
||||
String prefix = profile.commandPrefix();
|
||||
return "--security-opt seccomp= takes the path of a profile file, not the profile itself.\n"
|
||||
+ "Run '" + prefix + " start" + global.instanceSelector() + " --security-opt seccomp=<file>', after '"
|
||||
+ prefix + " stop" + global.instanceSelector() + " --remove' if the container exists.";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -303,6 +316,7 @@ public class StartCommand implements Callable<Integer> {
|
||||
args.addAll(List.of("-d", "--name", global.container));
|
||||
args.addAll(List.of("-p", port + ":" + profile.defaultPort()));
|
||||
args.addAll(socketArgs);
|
||||
securityOpts.forEach(opt -> args.addAll(List.of("--security-opt", opt)));
|
||||
if (persistDir != null && !persistDir.isBlank()) {
|
||||
args.addAll(List.of("-v", bindSource(daemon) + ":/app/data"));
|
||||
// The server defaults to in-memory storage; enable persistent mode so
|
||||
|
||||
@@ -61,9 +61,11 @@ public class DockerClient {
|
||||
/**
|
||||
* What a container was started with, as {@code restart} needs it back: the image, the host
|
||||
* port bound to {@code containerPort}, the host directory bind-mounted at {@code /app/data}
|
||||
* (null for a docker volume), and the environment. Any of them may be absent (null, or an empty map).
|
||||
* (null for a docker volume), the environment and the {@code --security-opt} values. Any of them
|
||||
* may be absent (null, or an empty map or list).
|
||||
*/
|
||||
public record RunSettings(String image, Integer hostPort, String persistSource, Map<String, String> env) {}
|
||||
public record RunSettings(String image, Integer hostPort, String persistSource, Map<String, String> env,
|
||||
List<String> securityOpts) {}
|
||||
|
||||
private static final ObjectMapper JSON = new ObjectMapper();
|
||||
|
||||
@@ -95,7 +97,9 @@ public class DockerClient {
|
||||
int eq = kv.indexOf('=');
|
||||
if (eq > 0) env.put(kv.substring(0, eq), kv.substring(eq + 1));
|
||||
}
|
||||
return Optional.of(new RunSettings(image, hostPort, persist, Map.copyOf(env)));
|
||||
List<String> securityOpts = new ArrayList<>();
|
||||
for (JsonNode opt : c.path("HostConfig").path("SecurityOpt")) securityOpts.add(opt.asText());
|
||||
return Optional.of(new RunSettings(image, hostPort, persist, Map.copyOf(env), List.copyOf(securityOpts)));
|
||||
} catch (Exception e) {
|
||||
throw new DockerException("Could not read the settings of container '" + name + "': " + e.getMessage());
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ class DockerClientProcessTest {
|
||||
Path json = tempDir.resolve("inspect.json");
|
||||
Files.writeString(json, """
|
||||
{"Config":{"Image":"floci/floci-gcp:0.9","Env":["FLOCI_GCP_SERVICES=storage","PATH=/usr/bin"]},
|
||||
"HostConfig":{"PortBindings":{"4588/tcp":[{"HostIp":"","HostPort":"14588"}]}},
|
||||
"HostConfig":{"PortBindings":{"4588/tcp":[{"HostIp":"","HostPort":"14588"}]},"SecurityOpt":["label=disable"]},
|
||||
"Mounts":[{"Type":"bind","Source":"/data/gcp","Destination":"/app/data"}]}
|
||||
""");
|
||||
Path fakeDocker = tempDir.resolve("docker");
|
||||
@@ -230,6 +230,7 @@ class DockerClientProcessTest {
|
||||
assertEquals(14588, run.hostPort());
|
||||
assertEquals("/data/gcp", run.persistSource());
|
||||
assertEquals("storage", run.env().get("FLOCI_GCP_SERVICES"));
|
||||
assertEquals(List.of("label=disable"), run.securityOpts());
|
||||
}
|
||||
|
||||
/** Without --persist the image's /app/data volume is mounted; that is not a persist directory. */
|
||||
@@ -250,6 +251,7 @@ class DockerClientProcessTest {
|
||||
.inspectRunSettings("floci-oci", 4599).orElseThrow();
|
||||
|
||||
assertNull(run.persistSource());
|
||||
assertEquals(List.of(), run.securityOpts());
|
||||
}
|
||||
|
||||
/** BL-041: with --verbose set, each docker command is echoed to stderr before it runs. */
|
||||
|
||||
@@ -84,9 +84,11 @@ class InstanceHintsTest {
|
||||
@Override public void pull(String image, String policy, PrintStream stream) throws DockerException { throw new DockerException("no such image"); }
|
||||
};
|
||||
Run start = run(new StartCommand(ProductProfile.AWS, docker), "--container", "other", "--port", "14566",
|
||||
"--image", "my image:1", "--pull", "always");
|
||||
"--image", "my image:1", "--pull", "always", "--security-opt", "label=disable",
|
||||
"--security-opt", "seccomp=/etc/my profile.json");
|
||||
assertEquals(1, start.exit());
|
||||
assertTrue(start.err().contains("floci start --pull never --container other --port 14566 --image 'my image:1'"), start.err());
|
||||
assertTrue(start.err().contains("floci start --pull never --container other --port 14566 --image 'my image:1'"
|
||||
+ " --security-opt label=disable --security-opt 'seccomp=/etc/my profile.json'"), start.err());
|
||||
}
|
||||
@Test
|
||||
void envLoadHintsPreserveTheProfileInAllFourTrees() throws Exception {
|
||||
|
||||
@@ -219,7 +219,8 @@ class RestartCommandTest {
|
||||
@Test
|
||||
void withoutAProfileTheRunningContainersSettingsCarryOver() throws Exception {
|
||||
var running = new DockerClient.RunSettings("floci/floci-gcp:0.9", 14588, "/data/gcp",
|
||||
Map.of("FLOCI_GCP_SERVICES", "storage", "FLOCI_GCP_DOCKER_RESOURCE_NAMESPACE", "team"));
|
||||
Map.of("FLOCI_GCP_SERVICES", "storage", "FLOCI_GCP_DOCKER_RESOURCE_NAMESPACE", "team"),
|
||||
List.of("label=disable"));
|
||||
|
||||
List<String> args = restartWith(ProductProfile.GCP, running).buildStartCommand().dockerRunArgs(SOCKET);
|
||||
|
||||
@@ -227,6 +228,7 @@ class RestartCommandTest {
|
||||
assertTrue(args.contains("/data/gcp:/app/data"), args.toString());
|
||||
assertTrue(args.contains("FLOCI_GCP_SERVICES=storage"), args.toString());
|
||||
assertTrue(args.contains("FLOCI_GCP_DOCKER_RESOURCE_NAMESPACE=team"), args.toString());
|
||||
assertEquals("label=disable", args.get(args.indexOf("--security-opt") + 1), args.toString());
|
||||
assertEquals("floci/floci-gcp:0.9", args.get(args.size() - 1));
|
||||
}
|
||||
|
||||
@@ -234,13 +236,15 @@ class RestartCommandTest {
|
||||
@Test
|
||||
void aProfileWinsOverTheRunningContainersSettings() throws Exception {
|
||||
writeProfile("pinned", "port: 15000\n");
|
||||
var running = new DockerClient.RunSettings("floci/floci:0.9", 14566, "/data/x", Map.of());
|
||||
var running = new DockerClient.RunSettings("floci/floci:0.9", 14566, "/data/x", Map.of(),
|
||||
List.of("label=disable"));
|
||||
|
||||
List<String> args = restartWith(ProductProfile.AWS, running, "--profile", "pinned")
|
||||
.buildStartCommand().dockerRunArgs(SOCKET);
|
||||
|
||||
assertTrue(args.contains("15000:4566"), args.toString());
|
||||
assertFalse(args.contains("/data/x:/app/data"), args.toString());
|
||||
assertFalse(args.contains("--security-opt"), args.toString());
|
||||
}
|
||||
|
||||
/** What a restart did, in order: "stop" and "start" as it ran them. */
|
||||
@@ -332,7 +336,7 @@ class RestartCommandTest {
|
||||
DockerClient present = new DockerClient() {
|
||||
@Override
|
||||
public Optional<RunSettings> inspectRunSettings(String name, int containerPort) {
|
||||
return Optional.of(new RunSettings("floci/floci:0.9", 14566, null, Map.of()));
|
||||
return Optional.of(new RunSettings("floci/floci:0.9", 14566, null, Map.of(), List.of()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -375,6 +379,30 @@ class RestartCommandTest {
|
||||
assertTrue(r.err().contains("floci restart"), r.err());
|
||||
}
|
||||
|
||||
/** docker inspect reports a seccomp profile file inline, which docker run does not take back. */
|
||||
@Test
|
||||
void anInlineSeccompProfileFailsTheRestartBeforeTheStop() {
|
||||
DockerClient seccomp = new DockerClient() {
|
||||
@Override
|
||||
public Optional<RunSettings> inspectRunSettings(String name, int containerPort) {
|
||||
return Optional.of(new RunSettings("floci/floci:0.9", 14566, null, Map.of(),
|
||||
List.of("label=disable", "seccomp={\"defaultAction\":\"SCMP_ACT_ALLOW\"}")));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ContainerInfo> inspectContainer(String name) {
|
||||
return Optional.of(new ContainerInfo("abc", name, "floci/floci:0.9", "running", ""));
|
||||
}
|
||||
};
|
||||
List<String> ran = new ArrayList<>();
|
||||
|
||||
Ran r = run(recordingRestart(seccomp, ran));
|
||||
|
||||
assertEquals(2, r.exit());
|
||||
assertEquals(List.of(), ran);
|
||||
assertTrue(r.err().contains("floci stop --remove"), r.err());
|
||||
}
|
||||
|
||||
/**
|
||||
* A --persist value that cannot be used is a usage error (exit 2), and restart finds out before
|
||||
* it stops anything: here a relative path, which a remote daemon cannot resolve.
|
||||
@@ -386,7 +414,7 @@ class RestartCommandTest {
|
||||
@Override
|
||||
public Optional<RunSettings> inspectRunSettings(String name, int containerPort) {
|
||||
// What the running container was started with: a relative data directory.
|
||||
return Optional.of(new RunSettings("floci/floci:0.9", 14566, "data", Map.of()));
|
||||
return Optional.of(new RunSettings("floci/floci:0.9", 14566, "data", Map.of(), List.of()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -34,7 +34,8 @@ class RestartRecoveryTest {
|
||||
}
|
||||
@Override public Optional<RunSettings> inspectRunSettings(String name, int port) {
|
||||
return Optional.of(new RunSettings("floci/floci-gcp:0.9", 14588, "/data/team's state",
|
||||
Map.of("FLOCI_GCP_SERVICES", "storage,pubsub", "FLOCI_GCP_DOCKER_RESOURCE_NAMESPACE", "team")));
|
||||
Map.of("FLOCI_GCP_SERVICES", "storage,pubsub", "FLOCI_GCP_DOCKER_RESOURCE_NAMESPACE", "team"),
|
||||
List.of("label=disable", "seccomp=/etc/my profile.json")));
|
||||
}
|
||||
@Override public void stopContainer(String name, int timeout) throws DockerException {
|
||||
if (failStop) throw new DockerException("stop failed");
|
||||
@@ -67,6 +68,7 @@ class RestartRecoveryTest {
|
||||
assertTrue(line.contains("--image floci/floci-gcp:0.9"), line);
|
||||
assertTrue(line.contains("--persist '/data/team'\\''s state'"), line);
|
||||
assertTrue(line.contains("--services storage,pubsub --namespace team"), line);
|
||||
assertTrue(line.contains("--security-opt label=disable --security-opt 'seccomp=/etc/my profile.json'"), line);
|
||||
assertTrue(line.contains("--container floci-gcp-team"), line);
|
||||
assertFalse(line.contains("--endpoint"), line);
|
||||
if (format.equals("json")) assertEquals("", stdout.toString());
|
||||
|
||||
@@ -96,6 +96,18 @@ class StartCommandArgsTest {
|
||||
assertFalse(args.stream().anyMatch(a -> a.contains("STORAGE_MODE")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void eachSecurityOptReachesDockerRunInEveryTree() {
|
||||
assertEquals(List.of("-d", "--name", "floci", "-p", "4566:4566", "-v", "/sock:/sock",
|
||||
"--security-opt", "label=disable", "--security-opt", "no-new-privileges", "floci/floci:latest"),
|
||||
parse("start", "--security-opt", "label=disable", "--security-opt", "no-new-privileges")
|
||||
.dockerRunArgs(SOCKET));
|
||||
for (String tree : new String[]{"gcp", "az", "oci"}) {
|
||||
List<String> args = parse(tree, "start", "--security-opt", "label=disable").dockerRunArgs(SOCKET);
|
||||
assertEquals("label=disable", args.get(args.indexOf("--security-opt") + 1), tree);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void explicitPersistFlagStillWinsOverTheProfile() throws Exception {
|
||||
writeProfile("probe", "persistDir: /from-profile\n");
|
||||
|
||||
Reference in new issue
Block a user