Skip to content

[T-127] Container hardening: non-root, read-only root FS, dropped capabilities, resource limits, healthchecks #219

Open

Description

@CodewithJha

Task T-127 · Milestone M10 — Evaluation · Size S · Priority P1 · Epic #10

Implements NFR-SEC-002

Branch ci/t-127-container-hardening-non-root-read — one task = one branch = one PR (doc 32 §6)

Summary

Harden all compose services: read_only: true + tmpfs, cap_drop: [ALL], security_opt: no-new-privileges, mem/cpu limits from .env, healthchecks for every service, Postgres not published beyond localhost.

Context / motivation

Doc 31 §3 container-escape and DoS mitigations.

Scope

In scope

  • CI check (docker compose config + policy script) asserting hardening keys present.

Implementation guidance

  • For every compose service: read_only: true with tmpfs for /tmp (and nginx cache/run dirs); cap_drop: [ALL] (any cap_add must be proven necessary and documented); security_opt: ["no-new-privileges:true"]; non-root user:; mem_limit/cpus from .env variables (ROBOPROBE_API_MEM, ROBOPROBE_WORKER_MEM, …, new) with defaults in .env.example; pids_limit; healthchecks everywhere; restart policies.
  • Postgres published only on 127.0.0.1 (or not at all in the app profile); secrets via secrets: files, never env literals.
  • scripts/check_compose_policy.py parses docker compose config --format json for each profile and asserts the rules; CI step.
  • Standards: respect the layering contracts (doc 16 §2) and conventions in doc 34; no hard-coded tunables — thresholds/defaults come from typed settings (doc 27); no magic numbers (ruff PLR2004); public APIs typed (mypy strict) and documented.

Acceptance criteria

  • Stack runs with hardening; policy check in CI.
  • Policy script green for profiles core, app, gazebo and observability.
  • Stack passes E2E with hardening enabled.
  • Tests listed below added and green in CI; coverage of new code meets the gate in doc 18 §3.
  • Docs, config reference and CHANGELOG Unreleased updated where behaviour, keys or interfaces changed.
  • Definition of Done (doc 32 §3) satisfied.

Tests required

  • scripts/check_compose_policy.py in CI.

Dependencies

Blocked by: #185 (T-116), #200 (T-095), #97 (T-047)

Blocks: no other task (leaf)

Parallelization notes

Files / paths owned by this task — avoid editing other paths; shared files (pyproject.toml entry points, cli/main.py, api/routers/__init__.py, router.tsx, docker/compose.yaml, ci.yml) are append-only:

  • docker/compose.yaml (service options)
  • scripts/check_compose_policy.py
  • .env.example

Touches compose service options — coordinate (sequenced after T-116/T-095).

Definition of Done

Per doc 32 §3 and AGENTS.md §5: lint, format, mypy strict and import-linter green; tests added and passing; docs updated; PR template completed with Closes #<this issue>; Conventional Commit messages referencing T-127 (doc 16 §6); commits authored only by the repository owner identity (AGENTS.md §4); CI green; reviewer checklist (doc 32 §5.1) satisfied.

References

Design docs: doc 31 §3 · doc 17 §4 · doc 29 §4

Requirements: NFR-SEC-002 (traceability: doc 28)

External:

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:deployDocker images, compose, release packagingarea:securitySecurity hardening, supply chainmilestone:M10M10 — Evaluationpriority:P1Required for milestone exitsize:S<= 1 daytaskChild task of a milestone epictype:infraCI, build, deployment infrastructure

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions