Skip to content

fix: add container hardening (cap_drop, read_only, resource limits)#50

Draft
dasirra wants to merge 8 commits into
developfrom
build/44-sec-add-container-hardening
Draft

fix: add container hardening (cap_drop, read_only, resource limits)#50
dasirra wants to merge 8 commits into
developfrom
build/44-sec-add-container-hardening

Conversation

@dasirra
Copy link
Copy Markdown
Owner

@dasirra dasirra commented Mar 25, 2026

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 default
  • cap_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 binaries
  • read_only: true — root filesystem is read-only
  • tmpfs: /tmp, /run, /var/tmp — in-memory writable paths (covers Node compile cache at /var/tmp)
  • deploy.resources.limits: cpus=2, memory=4G — prevents resource exhaustion
  • pids_limit: 512 — caps process count

Tasks

Task Status Notes
Add container hardening to docker-compose.yaml DONE

Code Review

  • MUST_FIX resolved: Added SETUID/SETGID capabilities required by gosu for user switching in entrypoint; without these the container would fail to start
  • SHOULD_FIX resolved: Removed NET_BIND_SERVICE (unnecessary with network_mode: host and ports >1024); added comment documenting Docker default seccomp profile

Built autonomously by /build

dasirra and others added 8 commits March 16, 2026 18:56
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
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