Repository navigation
build: run the image as a non-root user - #89
Conversation
The image ran as root. It now runs as the user tesk (UID 1000, group 0, home /home/tesk), replacing the base image's user ubuntu with the same UID, as the images of foca and cloud-registry do. Group 0 owns the home directory, so that arbitrary UIDs in group 0 (OpenShift) work too. The smoke test checks the image's user and starts it with an arbitrary UID and a read-only root file system. Closes #83 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Check in the smoke test that an arbitrary UID in group 0 gets the home directory and may write to it. Run the documented local examples with the host's UID in group 0, so that a kubeconfig readable only by the host user can be read. Guard the removal of the user ubuntu. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideConfigurationConfigure the image to run as
DocumentationUpdate the local run examples and deployment and upgrade guidance to explain the non-root identity, kubeconfig location and permissions, read-only filesystem support, and rootless Docker option.
TestsExtend the smoke test to verify the configured image identity and check arbitrary group-0 UID operation, including writable home-directory behavior.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #89 +/- ##
=======================================
Coverage 56.39% 56.39%
=======================================
Files 66 66
Lines 2167 2167
Branches 236 236
=======================================
Hits 1222 1222
Misses 804 804
Partials 141 141 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="Dockerfile" line_range="24" />
<code_context>
+# writes only to `/tmp`; the Kubernetes client reads `~/.kube/config` (or
+# `KUBECONFIG`) when it runs outside a cluster. The user `ubuntu` of the
+# Ubuntu base image is removed, as it has UID 1000
+ENV HOME=/home/tesk
+RUN if id ubuntu > /dev/null 2>&1; then userdel --remove ubuntu; fi && \
+ useradd --uid 1000 --gid 0 --create-home --home-dir "${HOME}" tesk && \
</code_context>
<issue_to_address>
**Mounted kubeconfig is ignored**
When the image runs outside a cluster as a UID with no passwd entry and `KUBECONFIG` is unset, `Config.defaultClient()` uses Java’s `user.home`, which `HOME` does not set for that UID, so it looks somewhere other than `/home/tesk/.kube/config`; the mounted kubeconfig is not loaded and Kubernetes requests fail.
Set Java’s `user.home` to `/home/tesk` or otherwise ensure it resolves to that directory.
Also at `docs/deployment.md:32`, `docs/deployment.md:34`, `README.md:43`.
</issue_to_address>
### Comment 2
<location path="README.md" line_range="43" />
<code_context>
```bash
-docker run --rm --publish 127.0.0.1:8080:8080 \
- --volume "${KUBECONFIG:-${HOME}/.kube/config}:/root/.kube/config:ro" \
+docker run --rm --publish 127.0.0.1:8080:8080 --user "$(id -u):0" \
+ --volume "${KUBECONFIG:-${HOME}/.kube/config}:/home/tesk/.kube/config:ro" \
elixircloud/tesk-api:latest
</code_context>
<issue_to_address>
**Rootless Docker cannot read kubeconfig**
When a user follows the README quick start with rootless Docker and a kubeconfig readable only by the host user, rootless Docker maps host-owned files to container UID 0, but this command runs the process as the host UID inside the container. A kubeconfig readable only by its owner is therefore unreadable, so Kubernetes requests fail for rootless Docker users following the quick start.
Add the rootless Docker exception to the README example, or direct users to the deployment instructions for the appropriate `--user` value.
</issue_to_address>Sourcery assessment
Approval pending. 2 findings to address first.
Blocking findings: Dockerfile:24, README.md:43
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
The image ran as root. It now runs as the user
tesk(UID 1000, group 0, home/home/tesk), as the images of foca and cloud-registry do. Group 0 owns the home directory, so arbitrary UIDs in group 0 (OpenShift) work too. The Ubuntu base image's userubuntu, which has UID 1000, is removed first.Dockerfile: user,HOME,WORKDIR,USER 1000:0.ci.yml, jobsmoke): checks that the image user is1000:0; starts the image with an arbitrary UID (1000750000:0) and a read-only root file system (--tmpfs /tmp), and checks that such a UID getsHOME=/home/teskand may write to it.docs/deployment.md(user, home, kubeconfig location, read-only root file system, rootless Docker), thedocker runexamples in the README anddocs/deployment.md(kubeconfig mounted to/home/tesk/.kube/config, run with--user "$(id -u):0"so that a 0600 kubeconfig can be read), and an upgrade note indocs/upgrading.md.The TESK chart already runs the API as UID 1000 when
tesk.securityContext.enabledis true (the default), and mounts only a ConfigMap (0644), so the chart needs no change. Testing on OpenShift is left for a deployment (see the issue).Closes #83 (part of #65)
Verification
docker buildand the smoke script of thesmokejob, run locally: before the change it failed with "Image user is '', expected '1000:0'"; after it, it passes (both profiles, arbitrary UID with read-only root file system, home directory check, Swagger UI setting).docker run --rm --entrypoint id tesk-api:smoke:uid=1000(tesk) gid=0(root).CI passed, Smoke test with the new checks, Test, Scan image, Docs, Lint, CodeQL, Codecov), also after mergingdevwith the coverage check (ci: add coverage targets #88).Lane
Full review:
adversarial-reviewerandquality-reviewer, two rounds. Fixed: the docs'docker runexamples failed for a 0600 kubeconfig of a host UID other than 1000 (medium; now--user "$(id -u):0"), the unverified chart claim in the upgrade note (medium; now namestesk.securityContext), theuserdel ... || true(now guarded byid ubuntu), no check of the home directory for arbitrary UIDs (now in the smoke test), a note for rootless Docker.Declined review findings
USER 1000:0instead ofUSER 1000, no/appdirectory): equivalent, and the explicit group documents the design.Open questions
None.
🤖 Generated with Claude Code
Summary by Sourcery
Run the TESK API image as a non-root user while preserving compatibility with arbitrary group-0 UIDs and existing Kubernetes deployments.
Enhancements:
tesk(UID 1000, group 0) with a shared home directory that supports arbitrary group-0 UIDs.Build:
CI:
Documentation: