Skip to main content

Run Infrahub as a non-root user

This guide explains how to run the Infrahub server, the task workers and the task manager as a non-root user. The Infrahub Docker image runs as root by default. It also contains an infrahub user (user ID 1000, group ID 0, home directory /home/infrahub), which owns every directory Infrahub writes to at runtime, and group 0 has the same permissions on them. You can therefore run the containers as:

  • user ID 1000, with any group ID
  • any other user ID with group ID 0, for example on platforms that assign a random user ID, such as OpenShift

Any other combination, such as a random user ID with a group ID other than 0, cannot write to these directories.

What you'll accomplish​

By following this guide, you'll learn how to:

  • Make the data in existing volumes writable for the non-root user
  • Run the Infrahub containers as a non-root user with Docker Compose, Podman, Helm or OpenShift
  • Verify that the containers run as the non-root user

Prerequisites​

Before starting, ensure you have:

  • A running Infrahub instance deployed with Docker Compose or Helm, or a new deployment
  • Infrahub 1.12.2 or later. In earlier images, the directories Infrahub writes to belong to root and group 0 cannot write to them. With Helm or OpenShift, check that your values file does not pin an earlier version in global.infrahubTag.
  • Command-line access to the host or cluster running Infrahub
  • For production deployments, a maintenance window, as the containers restart

Step 1: Make existing volumes writable​

New volumes need no preparation. On an existing deployment, the files in the storage and workflow volumes belong to root. Give them to the infrahub user and give group 0 the same permissions as the owner before you switch users.

Run a one-off container as root that mounts the same volumes as the server:

docker compose run --rm --no-deps --user 0 infrahub-server \
sh -c 'chown -R 1000:0 /opt/infrahub/storage /opt/infrahub/workflow && chmod -R g=u /opt/infrahub/storage /opt/infrahub/workflow'

Step 2: Run the containers as the non-root user​

Create a docker-compose.override.yml file next to docker-compose.yml:

services:
infrahub-server:
user: "1000:0"
task-worker:
user: "1000:0"
task-manager:
user: "1000:0"

Restart Infrahub:

docker compose up -d

Step 3: Verify​

Check the user of each container:

docker compose exec infrahub-server id -u
docker compose exec task-worker id -u
docker compose exec task-manager id -u

Each command prints 1000.

Then check the logs of the task workers for permission errors. At startup, each task worker writes its git configuration and logs Set git config file to /opt/infrahub/.gitconfig. A message that starts with Failed to set git means that the user cannot write to /opt/infrahub.

Finally, create a branch to confirm that the task workers run tasks. infrahubctl reads the address of Infrahub from INFRAHUB_ADDRESS and an API token from INFRAHUB_API_TOKEN.

On OpenShift, if Infrahub is not reachable from your computer, forward a local port to the Infrahub server and set INFRAHUB_ADDRESS to http://localhost:8000. The command runs until you stop it, so run infrahubctl in another terminal:

oc port-forward svc/infrahub-infrahub-server 8000:8000

Create and delete a branch:

infrahubctl branch create non-root-check
infrahubctl branch delete non-root-check