Skip to content

Commit 2e8d2d9

Browse files
committed
Update readme
1 parent 2fbbefd commit 2e8d2d9

File tree

1 file changed

+59
-27
lines changed

1 file changed

+59
-27
lines changed

README.md

Lines changed: 59 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
# OCI Interceptor
22

33
An OCI runtime wrapper that modifies containers'
4-
[`config.json`](https://github.com/opencontainers/runtime-spec/blob/master/config.md) according to
5-
specified rules before forwarding the container to a real OCI runtime for creation.
4+
[runtime configuration](https://github.com/opencontainers/runtime-spec/blob/main/config.md) according to
5+
specified rules before forwarding the container to a real runtime for creation.
66

77
This can be used to enforce certain policies on created containers, or to work around limitations
8-
in higher-level tools like Docker.
9-
10-
Note that programs like Docker track their own container metadata, which may not accurately reflect
11-
these last-minute changes to the underlying OCI configuration.
8+
in higher-level container management tools such as Docker.
129

1310
## Installation
1411

@@ -29,15 +26,31 @@ Currently, prebuilt binaries are only available for x86 Linux (glibc-based). Oth
2926

3027
## Usage
3128

32-
All `oci-interceptor` flags are prefixed with `--oi-` in order to avoid conflicts with the underlying OCI runtime.
29+
All `oci-interceptor` flags are prefixed with `--oi` in order to avoid conflicts with the underlying OCI runtime.
3330

34-
```bash
35-
$ oci-interceptor \
36-
[--oi-runtime-path=runc] \
37-
[--oi-debug-output-dir=/var/log/oci-interceptor] \
38-
[--oi-write-debug-output] \
39-
[--oi-readonly-networking-mounts] \
40-
[...other flags forwarded to runtime]
31+
```
32+
Usage: oci-interceptor [OPTIONS] [runtime-options]...
33+
34+
Arguments:
35+
[runtime-options]... All additional options will be forwarded to the OCI runtime.
36+
37+
Options:
38+
--oi-runtime-path <runtime-path>
39+
Path to OCI runtime. [default: runc]
40+
--oi-readonly-networking-mounts
41+
Mount networking files as readonly
42+
--oi-write-debug-output
43+
Write debug output
44+
--oi-debug-output-dir <debug-output-dir>
45+
Debug output location [default: /var/log/oci-interceptor]
46+
--oi-env <NAME=VALUE>
47+
Set an environment variable if not already present in config
48+
--oi-env-force <NAME=VALUE>
49+
Override an environment variable, regardless of any original value
50+
--oi-version
51+
Print version
52+
--oi-help
53+
Print help
4154
```
4255

4356
### With Docker
@@ -47,8 +60,8 @@ configuration](https://docs.docker.com/engine/reference/commandline/dockerd/#dae
4760
must be modified to add this runtime. If you want it to be invoked every time a container is
4861
created, you should also make it the default runtime (instead of `runc`).
4962

50-
If you are not using a custom OCI runtime like `crun` or `youki`, you can omit the `--oi-runtime-path`
51-
option, as it defaults to `runc`, the default runtime included with Docker.
63+
If you are not using an alternative OCI runtime such as [`crun`](https://github.com/containers/crun) or [`youki`](https://github.com/containers/youki), you can omit the `--oi-runtime-path`
64+
option, as it defaults to `runc`, the default runtime bundled with Docker.
5265

5366
#### Example `/etc/docker/daemon.json` contents
5467

@@ -65,36 +78,55 @@ option, as it defaults to `runc`, the default runtime included with Docker.
6578
}
6679
}
6780
```
81+
The Docker daemon must be restarted (`systemctl restart docker.service`) in order to apply changes to this configuration file.
6882

69-
Even if you set `oci-interceptor` as the default runtime, you can still bypass it while running a container via `docker run --runtime=runc`.
83+
Note that if you set `oci-interceptor` as the default runtime, you can still bypass it for a specific container by specifying `docker run --runtime=runc`.
7084

71-
While it is not possible to override `runtimeArgs` using a `docker run` option, you could specify several different "runtimes" (with different `runtimeArgs`) and switch between them using `docker run --runtime=<name>`.
85+
While it is not possible to override `runtimeArgs` with a `docker run` option, you could specify multiple interceptor "runtimes" (with different flags) and switch between them using `docker run --runtime=<name>`.
7286

7387
## Supported Customizations
7488

75-
### Readonly networking mounts
89+
### Read-only networking mounts
7690

77-
Works around the fact that Docker mounts the following files as read/write by default (https://github.com/moby/moby/issues/41991):
91+
Works around the fact that Docker mounts the following files as read/write by default:
7892

7993
- `/etc/hosts`
8094
- `/etc/hostname`
8195
- `/etc/resolv.conf`
8296

8397
When XFS project quotas are used to [restrict a container's writable layer
8498
size](https://github.com/moby/moby/pull/24771), these files provide an escape hatch for malicious
85-
users to fill the graph storage volume. This can be circumvented by manually mounting readonly files
86-
over these paths, but in that case Docker can no longer manage the container's DNS configuration.
99+
users to fill the host storage volume.
100+
101+
This can usually only be circumvented by manually creating read-only bind mounts over these paths (in which case Docker can no longer manage the container's DNS configuration) or by making the entire rootfs read-only (which severely constrains the workloads possible inside the container).
102+
103+
To avoid this issue, specify the `--oi-readonly-networking-mounts` flag. This modifies these mounts to be read-only, preventing writes from inside the container.
104+
105+
#### Related issues
106+
107+
- Workaround for [moby#13152](https://github.com/moby/moby/issues/41991), [moby#41991](https://github.com/moby/moby/issues/41991) (without custom bind mounts or making entire rootfs readonly)
108+
- Optionally reverts [moby#5129](https://github.com/moby/moby/pull/5129)
109+
110+
### Overriding environment variables
111+
112+
Allows specifying default environment variable values for containers without using `docker run --env` or `--env-file`.
113+
114+
Use `--oi-env <NAME=VALUE>` to set a default for an environment variable. This will not take precedence over a value explicitly specified via `docker run --env` or `--env-file`.
115+
116+
Alternatively, use `--oi-env-force <NAME=VALUE>` to force an certain value even when otherwise specified via `docker run --env` or `--env-file`.
87117

88-
To avoid this issue, specify the `--oi-readonly-networking-mounts` flag, which automatically modifies
89-
these mounts to be read-only, preventing writes from inside the container.
118+
#### Related issues
119+
- Workaround for [moby#16699](https://github.com/moby/moby/issues/16699) (supports arbitrary environment variables, not only proxy config)
120+
- Solution for https://stackoverflow.com/questions/33775075/how-to-set-default-docker-environment-variables
121+
- Solution for https://stackoverflow.com/questions/50644143/dockerd-set-default-environment-variable-for-all-containers
90122

91123
### Debug output
92124

93-
Specify the `--oi-write-debug-output` flag to write original, parsed, and modified container configs to the directory specified by `--oi-debug-output-dir` (default `/var/log/oci-interceptor`).
125+
Specify the `--oi-write-debug-output` flag to write original, parsed, and modified container configs to the directory specified as `--oi-debug-output-dir` (default `/var/log/oci-interceptor`).
94126

95-
These filenames will have the format:
127+
The resulting files will be named:
96128
- `<container_hostname>_original.json` (the original config)
97129
- `<container_hostname>_parsed.json` (the parsed config)
98130
- `<container_hostname>_modified.json` (the modified config, only written if modification occurred)
99131

100-
Additionally, forwarded calls to the underlying OCI runtime will be appended to the file `runtime_calls.txt` within this directory.
132+
Additionally, forwarded calls to the underlying OCI runtime will be appended to the file `runtime_calls.txt` within the debug output directory.

0 commit comments

Comments
 (0)