fix: add container hardening (cap_drop, read_only, resource limits)#50
Draft
dasirra wants to merge 8 commits into
Draft
fix: add container hardening (cap_drop, read_only, resource limits)#50dasirra wants to merge 8 commits into
dasirra wants to merge 8 commits into
Conversation
merge: develop into main
fix: remove legacy .initialized cleanup from entrypoint
Reduces attack surface per security audit 2026-03-25 by dropping all Linux capabilities (retaining only NET_BIND_SERVICE, CHOWN, DAC_OVERRIDE), enabling read-only root filesystem with tmpfs for writable paths, enforcing no-new-privileges, and capping CPU/memory/PIDs. Closes #44
- Add SETUID and SETGID caps required by gosu for user switching - Remove NET_BIND_SERVICE (unnecessary with host networking and ports >1024) - Document reliance on Docker default seccomp profile
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
Hardens the Docker container by dropping all Linux capabilities (retaining only those needed for operation), enabling a read-only root filesystem with tmpfs for writable paths, enforcing no-new-privileges, and capping CPU/memory/PID usage. This reduces the attack surface and prevents a compromised process from consuming host resources.
Source
Closes #44
What Changed
docker-compose.yaml:
cap_drop: ALL— drops all capabilities by defaultcap_add: CHOWN, DAC_OVERRIDE, SETUID, SETGID— retains only what is needed (CHOWN/DAC_OVERRIDE for filesystem ops, SETUID/SETGID for gosu user switching in entrypoint)security_opt: no-new-privileges:true— prevents privilege escalation via setuid binariesread_only: true— root filesystem is read-onlytmpfs: /tmp, /run, /var/tmp— in-memory writable paths (covers Node compile cache at/var/tmp)deploy.resources.limits: cpus=2, memory=4G— prevents resource exhaustionpids_limit: 512— caps process countTasks
Code Review
SETUID/SETGIDcapabilities required bygosufor user switching in entrypoint; without these the container would fail to startNET_BIND_SERVICE(unnecessary withnetwork_mode: hostand ports >1024); added comment documenting Docker default seccomp profileBuilt autonomously by
/build