All jobs

Run a Fiber Docker Image as a Non-Root User

Yes. An agent adds an unprivileged user to your Fiber app's Dockerfile, fixes ownership of the static assets, proves the container still serves, and opens a PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent reads the image and what the binary touches at runtime before it changes who runs it. In an app laid out like gofiber/boilerplate, the Dockerfile has two stages: golang:1.27-alpine copies the source into /go/src/boilerplate, runs go mod download and builds a static binary with CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o app .; alpine:latest then sets WORKDIR /app, makes ./static, copies ./static and the binary in, runs apk -U upgrade and installs dumb-init and ca-certificates, exposes 3000 and sets ENTRYPOINT ["/usr/bin/dumb-init", "--"]. There is no USER line, so the process is root. app.go listens on -port, default :3000, serves ./static/public through the static middleware and sends ./static/private/404.html from handlers.NotFound, both relative to the working directory, and -prod turns on prefork through fiber.ListenConfig{EnablePrefork: *prod}. The Makefile builds gofiber:latest and runs it with docker run -d -p 3000:3000 ... ./app, and the README's production line is docker run -d -p 3000:3000 gofiber ./app -prod.

Three facts decide the change. The binary writes nothing: database/database.go is an in-memory slice, so the user needs read access to /app/app and /app/static and nothing else. The port is 3000, above 1024, so no capability is needed to bind it. And prefork forks child processes of the same binary, which works for any user. The agent therefore adds, in the release stage and after the apk commands, RUN addgroup -S app && adduser -S -G app -H app, changes the two COPY lines to --chown=app:app, keeps chmod +x /app/app, and puts USER app as the last instruction before EXPOSE. dumb-init stays as the entrypoint, since it only forwards signals and reaps children and needs no privilege. The mkdir ./static line goes, because COPY --chown creates the directory with the right owner.

The sandbox has no Docker, so the agent installs it first with sudo apt-get install -y docker.io and starts dockerd, then runs make build, which is docker build -t gofiber:latest ., and starts the container the way the Makefile does. It checks docker inspect --format '{{.Config.User}}' prints app, that docker exec <container> id -u is not 0, that curl of /api/v1/users returns the JSON list, that a POST with user=alice is echoed back, that / serves static/public/index.html and an unknown path serves the 404.html from static/private, and then repeats the GET with ./app -prod to see prefork start its children as the same user. go test ./... -race, the command .github/workflows/test.yml runs, is unaffected, and the agent runs it anyway.

The workflow set gets one small addition that the existing security.yml and lint.yml do not cover: a docker.yml that builds the image on pull requests and fails when docker inspect reports an empty or root user, written with the same pinned actions/checkout SHA the other workflows use. The README's production section gains a sentence saying the container runs as app and that a bind mount over /app/static has to be readable by that user. The agent keeps the command output from every check with the run.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Make this Fiber app's Docker image run as a non-root user. Read Dockerfile, .dockerignore, app.go, handlers/handlers.go, database/database.go, Makefile, README.md and the workflows under .github first. In the release stage, add a system user and group named app, copy the static directory and the binary with --chown, keep dumb-init as the entrypoint, and set USER app before EXPOSE. Install Docker in the sandbox with sudo apt-get install -y docker.io, start dockerd, build the image with make build, run it with and without -prod, and check docker inspect reports the app user, id -u is not 0, GET and POST /api/v1/users work, / serves the index and an unknown path serves the 404 page. Add a docker.yml workflow that builds the image on pull requests and fails if the configured user is empty or root, pinning actions the way the other workflows do. Note the change in the README. Run go test ./... -race and quote every command's output. Open a pull request.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

The pull request changes Dockerfile (the user, the two --chown copies, the USER line, the dropped mkdir) and README.md, and adds .github/workflows/docker.yml. Its description quotes the docker build log, the docker inspect user, the id -u output from inside the container, the curl responses with and without -prod, and the go test output.

A reviewer rebuilds the image, runs docker run --rm gofiber:latest id and reads uid=100(app) or whatever Alpine assigned, then opens http://localhost:3000 and the 404 path. In the Dockerfile they check the order: the apk upgrade and install run before USER, and nothing after USER needs to write. They decide whether to pin alpine:latest to a tag in the same change, which the pull request raises and leaves alone.

The Go code, the Makefile targets and the test workflow are unchanged. make shell now opens a shell as app, which the README notes.

Run it on every new Dockerfile

A platform team that wants no root containers starts this from its own server: a handler lists the repositories, and for each Dockerfile whose final stage has no USER instruction, sends this body to POST /o/{org}/sessions with that repository in resources. A request_id that is a UUID v5 of the repository's full name plus the Dockerfile path makes the call safe to retry, because the same request_id and body return the run already started.

A Rush automation with a github trigger on pull_request.opened can comment when a pull request adds or changes a Dockerfile without a USER line; its runs are read-only, so they comment and never push. The run that fixes the file is started as above.

The use case this job follows, with its automation and trigger: Hand off a long task.

Why run it on Rush?

Whether a container still works as an unprivileged user is only known by running it. The agent installs Docker in its own sandbox, builds the image, starts it both ways the Makefile does, and checks the user, the port and every route, keeping each command and its output with the pull request, so the reviewer reads what the container answered rather than a description of the Dockerfile.

A fleet of Go services has one Dockerfile each, and each differs in what it writes at runtime. One request per repository, started at once, gives each a pull request that read its own binary's file access, so a service that writes logs or a SQLite file gets a writable directory and one that writes nothing gets only USER.

Frequently asked questions

Why can the app still bind port 3000 without root?

Ports above 1024 need no privilege on Linux. The -port flag defaults to :3000 in app.go, so nothing changes; the pull request notes that a deployment that sets -port=:80 would need cap_net_bind_service or a proxy in front.

Does prefork work as a non-root user?

Yes. With -prod, Fiber forks children of the same binary, which inherit the app user, and the agent runs the container with ./app -prod to see them answer. The README's production command keeps working.

Why keep dumb-init?

It runs as the entrypoint to forward signals to the Go process and reap children, which matters more with prefork. It needs no privilege, so it runs as app like everything after the USER line.

What about bind mounts over /app/static?

A mounted directory keeps the host's ownership, so files the app user cannot read answer 403 or 404. The README sentence the pull request adds says to make a mounted static readable by that user, and the image's own copy is owned by app through --chown.

How does the sandbox build an image?

The agent's sandbox has no Docker installed, so it installs docker.io with apt-get, starts dockerd, and then runs make build and the docker run lines from the Makefile. The commands and their output are kept with the run and quoted in the pull request.

More Fiber jobs

The same job on other stacks

Keep reading