Repository navigation
Check Compose projects against a list of allowed settings - #136
Merged
Merged
Conversation
The policy check judged the settings it knew to be dangerous and let
every other setting through. Compose has many more, and several reach
the host or another app just as well. Deployed through the engine with a
real Docker and Compose, without the relax flag:
- a `provider` service ran a script of the repository on the host, as
the user koroku runs as;
- `use_api_socket: true` mounted the Docker socket into the container;
- a volume with `driver_opts` of type overlay read host directories;
- `build.entitlements: [network.host]` gave RUN steps the host network,
and `build.ssh` handed a host key file to the build;
- a `post_start` hook with `privileged: true` ran with every capability;
- `network_mode: <another app's network>` reached that app's services;
- `build.tags` named the image like another app's image;
- an `include` with `env_file` put another app's variables into this
app's containers;
- a relative `build.dockerfile` with `..` printed a host file's first
line into the deployment log.
The normalized project is now compared with a list of the settings
koroku allows (internal/compose/schema.go); anything else is refused
under the rule `unsupported_setting`, so a setting nobody has looked at
does not pass. Settings on the list whose value matters are judged by
value: network_mode, pid/ipc/uts/userns_mode/cgroup, security_opt (only
no-new-privileges), volume driver options (only nfs, nfs4, tmpfs), mount
types, volume/network/logging drivers, local build caches, and the
Dockerfile path resolved against its context. A service without `build`
may not name an image koroku built for another app (`foreign_image`),
and a failed pull no longer removes images that a release of another
app was built as.
`include` and `extends.file` are resolved while Compose loads the files
and leave nothing in the normalized project, so koroku reads the files
itself before Compose does: only plain paths to files inside the
checkout, no `env_file` or `project_directory`, no Git or OCI addresses.
That needs a YAML parser. The standard library has none, and a text
search misses keys written with quotes, escapes or anchors, so
go.yaml.in/yaml/v3 is added.
A release that is started again (start, rollback, one-off commands) was
checked with other conditions than the `up` that followed: without the
app's DOCKER_CONFIG and with the env file of whatever release was
running. Compose interpolates `${VAR}` from both, so a file could
describe one project to the check and another to `up`. The check now
uses the release's own env snapshot and the DOCKER_CONFIG of the command
that follows, and Compose gets only the part of koroku's environment it
needs to run.
Every new rule can be waived with the app's relax flag, like the other
rules that protect the host. The seven apps of a running instance were
checked against the new rules beforehand: none is refused.
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The policy check judged the settings it knew to be dangerous and let every other setting through. Compose has many more, and several reach the host or another app just as well. Deployed through the engine with a real Docker and Compose, without the relax flag, each of these worked:
providerserviceuse_api_socket: truedriver_optsof type overlaybuild.entitlements: [network.host],build.sshpost_starthook withprivileged: truenetwork_mode: <another app's network>build.tagsincludewithenv_filebuild.dockerfilewith..What changes:
internal/compose/schema.go); anything else is refused under the new ruleunsupported_setting, so a setting nobody has looked at does not pass.network_mode,pid/ipc/uts/userns_mode/cgroup,security_opt(onlyno-new-privileges), volume driver options (only nfs, nfs4, tmpfs), mount types, volume/network/logging drivers, local build caches, and the Dockerfile path resolved against its context. A service withoutbuildmay not name an image koroku built for another app (foreign_image).includeandextends.fileare resolved while Compose loads the files and leave nothing in the normalized project, so koroku reads the files itself before Compose does: only plain paths to files inside the checkout, noenv_fileorproject_directory, no Git or OCI addresses. That needs a YAML parser;go.yaml.in/yaml/v3is added (the standard library has none, and a text search misses keys written with quotes, escapes or anchors).DOCKER_CONFIGand with the env file of whatever release was running; Compose interpolates${VAR}from both, so a file could describe one project to the check and another toup. The check now uses the release's own env snapshot and theDOCKER_CONFIGof the command that follows, and Compose gets only the part of koroku's environment it needs to run.Every new rule can be waived with the app's relax flag, like the other rules that protect the host.
build.tagsis refused rather than silently reset, so that the error names the setting.ARCHITECTURE 6 and 10, the prepare-app requirements and the deploy-status Skill describe the rules; the plugin version goes to 0.26.0.
Test plan
go vet ./...,go vet -tags integration ./...,go test ./...docker compose config(Compose v5.8.0):escape(every service must be blocked) andallowed(ordinary settings, only the published port is reported)TestPolicyBlocksWaysOutdeploys 13 such repositories through the engine; each fails at validation, nothing runs, no host file content reaches the logTestComposePrintsOnlyAllowedSettingsForOrdinaryFilesruns the local Compose over the ordinary file, to catch a Compose release that renames or adds settings🤖 Generated with Claude Code