Skip to content

Run hgweb container as non-root - #2593

Open
hahn-kev-bot wants to merge 1 commit into
developfrom
claude/hgweb-non-root-container-4ec109
Open

Run hgweb container as non-root#2593
hahn-kev-bot wants to merge 1 commit into
developfrom
claude/hgweb-non-root-container-4ec109

Conversation

@hahn-kev-bot

@hahn-kev-bot hahn-kev-bot commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

we really should be running hgweb as non root, there were some issues but claude worked them out.


AI summary

The hgweb container previously ran as root. It failed to start when forced to a non-root UID — not because of a privileged port (it listens on the unprivileged 8088), but because the httpd:2.4-bookworm base image keeps its runtime state under /usr/local/apache2/logs, which is root-owned. As UID 33 (www-data), Apache couldn't create its PID file, the mod_wsgi socket (WSGISocketPrefix logs/wsgi), the mod_cgid socket, or its file-based mutexes, so startup aborted.

Changes:

  • hgweb/Dockerfilechown /usr/local/apache2/logs to www-data and add USER www-data, so the image runs non-root everywhere (CI, Tilt, k8s).
  • deployment/base/hg-deployment.yaml — add runAsUser/runAsGroup: 33 and runAsNonRoot: true at the pod level (alongside the existing fsGroup: 33), and drop the now-redundant container-level securityContext on hgresumable.

Repo writes to the shared PVC were already fine: the pod has fsGroup: 33, and the populate-test-repos init container already runs as UID 33. chg (used by the /command/ CGI) needs no config — its socket defaults into /tmp.

This follows the earlier move of the sibling hgresumable container to www-data (#2590).

Test plan

Verified locally by building the image and running it rootless (no k8s):

  • Container runs as uid=33(www-data).
  • Apache reaches "resuming normal operations"; the mod_wsgi socket is created under logs/ with no permission errors.
  • /command/x/healthz returns 200 (mod_cgid socket works under UID 33).
  • chg version runs successfully as UID 33.

Remaining check for a reviewer: deploy to a dev cluster and confirm the hg pod's hgweb container reaches Ready with the real PVC mounted.

Apache kept its PID file, mod_wsgi socket, mod_cgid socket, and mutexes
under /usr/local/apache2/logs (root-owned), so the container couldn't
start as a non-root UID. Chown that dir to www-data and set USER www-data
in the image.

Add runAsUser/runAsGroup/runAsNonRoot at the pod level in the hg
deployment (alongside the existing fsGroup: 33), and drop the now-redundant
container-level securityContext on hgresumable.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions github-actions Bot added the 📦 Lexbox issues related to any server side code, fw-headless included label Aug 24, 2026
@coderabbitai

coderabbitai Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1c4154db-69c8-4cab-b229-fe69ef7915b9


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@rmunn rmunn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I don't see any omissions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📦 Lexbox issues related to any server side code, fw-headless included

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants