build(docker): run as a non-root user with a read-only root filesystem

- Use the distroless nonroot image and USER 65532
- Make /data the only writable path, owned by the unprivileged user
- Read the config from /etc/parsimony/parsimony.yaml, mounted read-only
- Expose the three listener ports
- Document the run command in the README
This commit is contained in:
tgiachi 2026-11-09 16:11:55 +01:00
commit ccb2940d6e
2 changed files with 26 additions and 3 deletions

View file

@ -12,9 +12,16 @@ COPY go.mod go.sum ./
RUN go mod download
COPY . .
COPY --from=admin /src/internal/adminui/dist ./internal/adminui/dist
RUN CGO_ENABLED=0 go build -o /parsimony ./cmd/parsimony
RUN CGO_ENABLED=0 go build -o /parsimony ./cmd/parsimony && mkdir /data
FROM gcr.io/distroless/static-debian12
# Run as the unprivileged "nonroot" user (uid 65532). /data is the only writable path:
# the database and its WAL files live there. A new named volume inherits this ownership;
# for a bind mount, make the host directory writable by uid 65532.
FROM gcr.io/distroless/static-debian12:nonroot
COPY --from=build /parsimony /parsimony
COPY --from=build --chown=65532:65532 /data /data
VOLUME /data
ENTRYPOINT ["/parsimony", "-config", "/data/parsimony.yaml"]
EXPOSE 2424 8080 8081
USER 65532:65532
# Mount the config read-only at /etc/parsimony/parsimony.yaml; keep "db: /data/parsimony.db" in it.
ENTRYPOINT ["/parsimony", "-config", "/etc/parsimony/parsimony.yaml"]

View file

@ -45,6 +45,22 @@ the unsubscribe links in every message use it. Keep the `api` listener private.
curl -H "Authorization: Bearer $PARSIMONY_API_TOKEN" -d '{"name":"dev","domain":"example.org","title":"Dev"}' localhost:8080/api/v1/lists
```
## Docker
The image runs as an unprivileged user (uid 65532) and works with a read-only root filesystem.
Config is mounted read-only; the only writable path is the `/data` volume (the database).
```
docker build -t parsimony .
docker run -d --name parsimony --read-only --cap-drop ALL \
-v parsimony-data:/data \
-v $PWD/parsimony.yaml:/etc/parsimony/parsimony.yaml:ro \
-e PARSIMONY_API_TOKEN=... -p 2424:2424 -p 8080:8080 -p 8081:8081 parsimony
```
Use `db: /data/parsimony.db` in the config. A new named volume gets the right ownership by itself;
for a bind mount, make the host directory writable by uid 65532.
## Delivery and the queue
LMTP answers `250` when the post is in the queue, so a down relay never bounces mail back to Postfix.