feat: run containers as non-root user by default#547
Open
constantinexanthos wants to merge 2 commits intorailwayapp:mainfrom
Open
feat: run containers as non-root user by default#547constantinexanthos wants to merge 2 commits intorailwayapp:mainfrom
constantinexanthos wants to merge 2 commits intorailwayapp:mainfrom
Conversation
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"}}
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.
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 (
railpackuser) by default. A newsetup:userbuild step creates the user/group and sets ownership of/app.Changes across 5 files:
core/plan/plan.go— AddedUserfield toDeploystructcore/config/config.go— Addeduseroption toDeployConfigso users can overridecore/generate/deploy_builder.go— Defaults to UID1001, creates non-root user step withgroupadd/useradd/chowncore/generate/context.go— Wires config override to deploy builderbuildkit/convert.go— SetsUserin OCI image configOpt-out: Users who need root can set their railpack config:
{"deploy": {"user": "root"}}Testing