⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
fix(docker): leave files mounted into the web root untouched
Tin09f3eee2c2ab
diff --git a/Dockerfile.kaneo b/Dockerfile.kaneoindex 4c8a518b4..075209a42 100644--- a/Dockerfile.kaneo+++ b/Dockerfile.kaneo@@ -97,10 +97,10 @@ FROM node:24.19.0-alpine AS runtimeRUN apk add --no-cache nginx=~1.30.4 && \addgroup -g 1001 appuser && \adduser -u 1001 -G appuser -D appuser && \- mkdir -p /app /app/apps/api/data /var/lib/kaneo /docker-entrypoint.d && \+ mkdir -p /app /app/apps/api/data /var/lib/kaneo/html /docker-entrypoint.d && \chown -R appuser:appuser /app && \- chown appuser:root /var/lib/kaneo && \- chmod 2775 /var/lib/kaneo && \+ chown appuser:root /var/lib/kaneo /var/lib/kaneo/html && \+ chmod 2775 /var/lib/kaneo /var/lib/kaneo/html && \rm -rf /usr/share/nginx/html && \mkdir -p /usr/share/nginx && \ln -s /var/lib/kaneo/html /usr/share/nginx/htmldiff --git a/apps/web/Dockerfile b/apps/web/Dockerfileindex 84bef02fd..92092bf3d 100644--- a/apps/web/Dockerfile+++ b/apps/web/Dockerfile@@ -52,12 +52,13 @@ FROM nginx:1.29.5-alpine AS runtime# Only runtime storage needs write access, including for an arbitrary UID.# The legacy web root links to the rendered assets so mounted server configs-# with `root /usr/share/nginx/html` keep serving the configured app.+# with `root /usr/share/nginx/html` keep serving the configured app. Creating+# the target keeps files mounted through that link in a directory we own.RUN addgroup -g 1001 appuser && \adduser -u 1001 -G appuser -D appuser && \- mkdir -p /var/lib/kaneo && \- chown appuser:root /var/lib/kaneo && \- chmod 2775 /var/lib/kaneo && \+ mkdir -p /var/lib/kaneo/html && \+ chown appuser:root /var/lib/kaneo /var/lib/kaneo/html && \+ chmod 2775 /var/lib/kaneo /var/lib/kaneo/html && \rm -rf /usr/share/nginx/html && \ln -s /var/lib/kaneo/html /usr/share/nginx/htmldiff --git a/apps/web/env.sh b/apps/web/env.shindex d4db7dc33..87701004c 100644--- a/apps/web/env.sh+++ b/apps/web/env.sh@@ -11,25 +11,34 @@ export KANEO_ENV_RENDERER="$script_dir/env.awk"# The image's assets stay immutable. A volume at /var/lib/kaneo also supports# read-only root filesystems and OpenShift's arbitrary runtime UID.mkdir -p "$asset_root" /var/lib/kaneo/nginx /var/lib/kaneo/tmp-cp -R "$asset_source/." "$asset_root/"-chmod -R u+rwX "$asset_root"if [ -z "${KANEO_API_URL:-}" ]; thenecho "WARNING: KANEO_API_URL is not set. API calls may fail." >&2fi-# find -exec preserves spaces/newlines in filenames. Write each replacement-# beside its source before atomically replacing the complete file.-find "$asset_root" -type f -name '*.js' -exec sh -eu -c '+# /usr/share/nginx/html links here, so files mounted there for older images+# land in this directory. Unlinking a mount point fails, and -xdev keeps find+# out of mounted directories, so cleanup removes only the previous copies.+find /var/lib/kaneo -xdev -path "$asset_root/*" -delete 2>/dev/null || true++# Copy the build file by file, skipping paths that survived as mounts so they+# are never overwritten. find -exec preserves spaces/newlines in filenames.+find "$asset_source" -mindepth 1 -exec sh -eu -c '+ asset_source=$1+ shiftfor asset do- temporary=$(mktemp "${asset}.XXXXXX")- trap '\''rm -f "$temporary"'\'' EXIT HUP INT TERM- LC_ALL=C awk -v mode=bundle -f "$KANEO_ENV_RENDERER" "$asset" > "$temporary"- chmod 644 "$temporary"- mv "$temporary" "$asset"- trap - EXIT HUP INT TERM+ target="$0${asset#"$asset_source"}"+ if [ -d "$asset" ]; then+ mkdir -p "$target"+ elif [ ! -e "$target" ] && [ ! -L "$target" ]; then+ case "$asset" in+ *.js) LC_ALL=C awk -v mode=bundle -f "$KANEO_ENV_RENDERER" "$asset" > "$target" ;;+ *) cp "$asset" "$target" ;;+ esac+ chmod 644 "$target"+ fidone-' sh {} ++' "$asset_root" "$asset_source" {} +# Serve JSON as static content. It must never become an nginx configuration# string, where quotes, backslashes, and dollar signs have another meaning.diff --git a/charts/kaneo/README.md b/charts/kaneo/README.mdindex 2feade689..04da2f9ab 100644--- a/charts/kaneo/README.md+++ b/charts/kaneo/README.md@@ -470,7 +470,7 @@ docker run --read-only \```For a bind mount, grant write access to the container's UID or a group it belongs to. The image's default user is UID 1001 with GID 0; arbitrary UIDs can write its runtime directory through GID 0 when the root filesystem is writable.-nginx serves the web app from `/var/lib/kaneo/html`, where startup writes the runtime configuration, and reads server configuration copied from `/etc/nginx/conf.d` into `/var/lib/kaneo/nginx/conf.d`. If you mount your own server configuration, `root /usr/share/nginx/html;` keeps working because that path now links to `/var/lib/kaneo/html`, but `root /var/lib/kaneo/html;` is recommended. The unconfigured build lives in `/usr/share/kaneo/html`; do not serve it directly. Templates in `/etc/nginx/templates` still render at startup, and `default.conf.template` replaces the bundled server configuration.+nginx serves the web app from `/var/lib/kaneo/html`, where startup writes the runtime configuration, and reads server configuration copied from `/etc/nginx/conf.d` into `/var/lib/kaneo/nginx/conf.d`. If you mount your own server configuration, `root /usr/share/nginx/html;` keeps working because that path now links to `/var/lib/kaneo/html`, but `root /var/lib/kaneo/html;` is recommended. The unconfigured build lives in `/usr/share/kaneo/html`; do not serve it directly. Startup copies it next to any files you mount into either web root and leaves those files untouched. With a tmpfs at `/var/lib/kaneo`, mount custom files into `/usr/share/kaneo/html` instead, because the runtime creates mount points inside a tmpfs as root. Templates in `/etc/nginx/templates` still render at startup, and `default.conf.template` replaces the bundled server configuration.### Registration ControlBy default, user registration is enabled. To disable new user registration:diff --git a/scripts/security/web-runtime-env.test.mjs b/scripts/security/web-runtime-env.test.mjsindex 4cd895937..98788280b 100644--- a/scripts/security/web-runtime-env.test.mjs+++ b/scripts/security/web-runtime-env.test.mjs@@ -40,6 +40,7 @@ test("production runtime serves configuration with default and restricted users"const fixture = mkdtempSync(resolve(tmpdir(), "kaneo-web-runtime-"));const runtimeImage = `kaneo-web-runtime-test:${process.pid}`;const container = `kaneo-web-runtime-test-${process.pid}`;+ const volume = `kaneo-web-runtime-test-${process.pid}`;const docker = (args, timeout = 30_000) => {const result = spawnSync("docker", args, { encoding: "utf8", timeout });assert.equal(result.status, 0, result.error?.message ?? result.stderr);@@ -53,6 +54,16 @@ test("production runtime serves configuration with default and restricted users"writeFileSync(resolve(fixture, "dist", asset), '"KANEO_API_URL"');}writeFileSync(resolve(fixture, "dist/hook.js"), '"KANEO_CLIENT_URL"');+ // Files mounted into the old web root must survive startup untouched,+ // whether the mount is read-only or writes through to the host.+ for (const asset of ["favicon.ico", "robots.txt"]) {+ writeFileSync(resolve(fixture, "dist", asset), "kaneo asset");+ }+ const customFavicon = resolve(fixture, "favicon.ico");+ writeFileSync(customFavicon, "custom favicon");+ const customRobots = resolve(fixture, "robots.txt");+ writeFileSync(customRobots, "custom robots", { mode: 0o666 });+ chmodSync(customRobots, 0o666);const hook = resolve(fixture, "00-test.envsh");writeFileSync(hook,@@ -98,26 +109,45 @@ test("production runtime serves configuration with default and restricted users");docker(["image", "inspect", image]);docker(["build", "--network=none", "-t", runtimeImage, fixture], 120_000);+ const restricted = [+ "--read-only",+ "--cap-drop=ALL",+ "--security-opt=no-new-privileges",+ ];+ // The runtime creates a tmpfs's mount points as root, so custom files go+ // in the build directory there; the old web root works everywhere else.for (const scenario of [{name: "default non-root user",uid: "1001",+ assets: "/usr/share/nginx/html",args: [],},{name: "arbitrary OpenShift UID",uid: "1001230000",+ assets: "/usr/share/nginx/html",args: ["--user=1001230000:0"],},{name: "arbitrary UID and read-only root with writable volume",uid: "1001230000",+ assets: "/usr/share/kaneo/html",args: ["--user=1001230000:1001230000",- "--read-only","--tmpfs=/var/lib/kaneo:rw,mode=0770,gid=1001230000",- "--cap-drop=ALL",- "--security-opt=no-new-privileges",+ ...restricted,+ ],+ },+ {+ name: "arbitrary UID and read-only root with named volume",+ uid: "1001230000",+ assets: "/usr/share/nginx/html",+ args: [+ "--user=1001230000:0",+ "--mount",+ `type=volume,source=${volume},target=/var/lib/kaneo`,+ ...restricted,],},]) {@@ -136,6 +166,10 @@ test("production runtime serves configuration with default and restricted users"`type=bind,source=${template},target=/etc/nginx/templates/runtime.conf.template,readonly`,"--mount",`type=bind,source=${legacy},target=/etc/nginx/conf.d/legacy.conf,readonly`,+ "--mount",+ `type=bind,source=${customFavicon},target=${scenario.assets}/favicon.ico,readonly`,+ "--mount",+ `type=bind,source=${customRobots},target=${scenario.assets}/robots.txt`,"--env","KANEO_API_URL=https://api.example.test/api",runtimeImage,@@ -144,7 +178,7 @@ test("production runtime serves configuration with default and restricted users""-c",[`test "$(id -u)" = ${scenario.uid}`,- "test ! -d /var/lib/kaneo/html",+ "test ! -e /var/lib/kaneo/html/root.js","test -L /usr/share/nginx/html",'test "$(cat /usr/share/kaneo/html/root.js)" = \'"KANEO_API_URL"\'',"/docker-entrypoint.sh nginx -t",@@ -160,6 +194,9 @@ test("production runtime serves configuration with default and restricted users"'test "$(wget -qO- http://127.0.0.1:5173/)" = "runtime fixture"','test "$(wget -qO- http://127.0.0.1:5174/)" = "https://hook.example.test"','test "$(wget -qO- http://127.0.0.1:5175/root.js)" = \'"https://api.example.test/api"\'',+ 'test "$(wget -qO- http://127.0.0.1:5173/favicon.ico)" = "custom favicon"',+ 'test "$(wget -qO- http://127.0.0.1:5175/favicon.ico)" = "custom favicon"',+ 'test "$(wget -qO- http://127.0.0.1:5175/robots.txt)" = "custom robots"',"wget -qO- http://127.0.0.1:5173/root.js","wget -qO- http://127.0.0.1:5173/assets/app.js","wget -qO- http://127.0.0.1:5173/.well-known/oauth-protected-resource/api/mcp",@@ -176,10 +213,13 @@ test("production runtime serves configuration with default and restricted users"assert.equal(responses[1], "https://api.example.test/api");assert.equal(responses[2].resource, "https://api.example.test/api/mcp");assert.equal(responses[3].issuer, "https://api.example.test/api");+ assert.equal(readFileSync(customFavicon, "utf8"), "custom favicon");+ assert.equal(readFileSync(customRobots, "utf8"), "custom robots");});}} finally {spawnSync("docker", ["rm", "-f", container], { timeout: 30_000 });+ spawnSync("docker", ["volume", "rm", volume], { timeout: 30_000 });spawnSync("docker", ["image", "rm", runtimeImage], { timeout: 30_000 });rmSync(fixture, { recursive: true, force: true });}