Skip to content

feat: run containers as non-root user by default#547

Open
constantinexanthos wants to merge 2 commits intorailwayapp:mainfrom
constantinexanthos:feat/non-root-user
Open

feat: run containers as non-root user by default#547
constantinexanthos wants to merge 2 commits intorailwayapp:mainfrom
constantinexanthos:feat/non-root-user

Conversation

@constantinexanthos
Copy link
Copy Markdown

Closes #286

Problem

Containers built by Railpack run as root by default, which is a security concern and violates container best practices.

Solution

Containers now run as UID 1001 (railpack user) by default. A new setup:user build step creates the user/group and sets ownership of /app.

Changes across 5 files:

  • core/plan/plan.go — Added User field to Deploy struct
  • core/config/config.go — Added user option to DeployConfig so users can override
  • core/generate/deploy_builder.go — Defaults to UID 1001, creates non-root user step with groupadd/useradd/chown
  • core/generate/context.go — Wires config override to deploy builder
  • buildkit/convert.go — Sets User in OCI image config

Opt-out: Users who need root can set their railpack config:

{"deploy": {"user": "root"}}

Testing

  • All 110 snapshot tests updated and passing
  • Compiles clean on macOS (Apple Silicon)

Resolves railwayapp#286. Containers built by Railpack now run as UID 1001 (railpack)
instead of root. A setup:user step creates the user/group and chowns /app.

Changes:
- core/plan: Add User field to Deploy struct
- core/config: Add user option to DeployConfig for user override
- core/generate/deploy_builder: Default to UID 1001, create non-root user
  step with groupadd/useradd/chown
- core/generate/context: Wire config override to deploy builder
- buildkit/convert: Set User in OCI image config

Users can opt out by setting user to root in their railpack config:
{"deploy": {"user": "root"}}
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.

Runs as root user

1 participant