Skip to content

v0.1.2 hotfix: add required capabilities for entrypoint init under cap_drop ALL#513

Closed
bdeetz wants to merge 1 commit intodefaultfrom
fix/container-cap-drop-permission-denied-0.1.2-hotfix
Closed

v0.1.2 hotfix: add required capabilities for entrypoint init under cap_drop ALL#513
bdeetz wants to merge 1 commit intodefaultfrom
fix/container-cap-drop-permission-denied-0.1.2-hotfix

Conversation

@bdeetz
Copy link

@bdeetz bdeetz commented Mar 5, 2026

Known Impacted Versions

Problem

Test runs with different cap than what's required.

/entrypoint.sh: line 112: /data/.magpie-init.lock: Permission denied

Root Cause

docker-compose.prod.yml specifies cap_drop: ALL for security hardening, which removes all Linux capabilities — including ones essential for the entrypoint's "start as root → init → drop privileges" pattern:

  • CAP_DAC_OVERRIDE — needed for root to write to the /data bind mount owned by a non-root host user
  • CAP_SETUID / CAP_SETGID — needed by gosu to drop privileges
  • CAP_CHOWN — needed to set correct ownership on directories created during init

Fix

docker-compose.prod.yml

Added cap_add with the 4 minimum capabilities needed after cap_drop: ALL:

  • CHOWN, DAC_OVERRIDE, SETUID, SETGID

This follows the same pattern already used by the Caddy service in the same file.

entrypoint.sh

Added early creation of the storage directory (/data/artifacts) before the lock file resolution logic. On first boot, the directory doesn't exist yet, causing the lock file to fall back to /data. Creating it early keeps the lock file in the correct location.

Security

These capabilities are only effective during the brief root initialization phase of the entrypoint. After gosu switches to the target UID/GID, they have no effect. The container retains read_only: true, all other capabilities remain dropped, and the application runs with zero capabilities.

Testing

  • All 977 unit tests pass
  • Ruff lint/format clean
  • Shellcheck clean on both shell scripts
  • Code review approved

(AI-generated via Claude Code w/ Opus 4.5)

Manual testing

  • upon initialization of magpie on a fresh install of ubuntu 24.04, the magpie container failed to start. After building with these changes, the container made it further in the initialization process.

@bdeetz bdeetz marked this pull request as draft March 5, 2026 07:56
@bdeetz bdeetz closed this Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant