Repository navigation
docker-compose: Run services with a read-only root filesystem - #1470
Open
marcleblanc2 wants to merge 5 commits into
Open
marcleblanc2 wants to merge 5 commits into
marcleblanc2 wants to merge 5 commits into
Conversation
This was referenced Nov 10, 2026
marcleblanc2
force-pushed
the
read-only-root-filesystem
branch
from
November 13, 2026 05:44
3039784 to
34eeb7e
Compare
marcleblanc2
changed the base branch from
main
to
marc/prometheus-read-only-root-filesystem
November 13, 2026 05:44
marcleblanc2
marked this pull request as ready for review
November 13, 2026 05:44
Set read_only: true on every service except prometheus, whose image writes its alertmanager config and data outside the mounted volumes. Writable paths follow the Helm chart's emptyDir mounts: /tmp for gitserver and searcher, /home/sourcegraph for the frontends, /var/run/postgresql for the databases. The frontends and blobstore also get /tmp. The two code intel workers get /tmp as a named volume, because their scratch files can be several GB and a tmpfs counts against mem_limit. Amp-Thread-ID: https://ampcode.com/threads/T-01a13cfb-9756-7111-8b29-381a841065e1 Co-authored-by: Amp <amp@ampcode.com>
A tmpfs mounted over an existing directory keeps that directory's mode but is owned by root, so postgres could not create its socket lock file in /var/run/postgresql and the smoke test failed. Set uid and gid on the /var/run/postgresql and /home/sourcegraph mounts to the image's user. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a13cfb-9756-7111-8b29-381a841065e1
The postgres user is uid 999 in the postgresql-16 image but uid 70 in the codeinsights image, so codeinsights-db still could not write its socket lock file. A world-writable sticky tmpfs, like /tmp, works for any user. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a13cfb-9756-7111-8b29-381a841065e1
The executor writes workspaces under TMPDIR, which is the /scratch bind mount. The git, docker, and src commands it runs do not inherit TMPDIR, so /tmp is a tmpfs. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a13cfb-9756-7111-8b29-381a841065e1
CI showed mode=1777 has no effect on a tmpfs mounted over an existing image directory: postgres still could not write to /var/run/postgresql. A named volume takes the owner and mode of the image directory it covers, so it is writable by the image's user without naming a uid, gid, or mode in the compose file. /tmp stays a tmpfs: it is 1777 in the images. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a1d36e-7d38-77c8-98dc-e4678a3ad2b0
marcleblanc2
force-pushed
the
read-only-root-filesystem
branch
from
November 13, 2026 05:56
34eeb7e to
9db1af3
Compare
2 tasks done
marcleblanc2
enabled stacked auto-merge (squash)
November 13, 2026 06:34
1 task done
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.
Problem
Some customers need a read-only root filesystem on every container
No Compose service set
read_only: true, so a process could modify its own container image at runtimesg-infra-writable-filesystem-serviceSolution
Set
read_only: trueon every service in every Compose file, exceptprometheusServices that write outside their volumes get a writable path, mirroring the Helm chart's
emptyDirmounts where it has them:/tmp/tmp, new named volume at/home/sourcegraph/var/run/postgresql/tmpReview notes:
/var/run/postgresqland/home/sourcegraphare named volumes, because a tmpfs over an existing directory is owned by root, which broke postgres in CI/tmpis on disk, because uploads can be several GB, and a tmpfs counts againstmem_limitdocker exec,docker cp) outside a volumeNot changed:
prometheus, which is fix/observability: Prometheus read only root volume #1479, and waits on an image changeTest plan
docker-compose config -q(v1 1.29.2, same as CI) passes for the main file, the db-only file, the executor file, and the jaeger and dev overlaysprometheus)Docker Compose
Not run:
Helm
Linked PRs
prometheus, which this PR is stacked onno-new-privilegeson every service, which this followsAmp threads