Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(web): allow non-root runtime configuration writes (#1767)

Tin Sever3c7a030fb649
diff --git a/apps/web/Dockerfile b/apps/web/Dockerfile
index 2439f2606..be8378b8e 100644
--- a/apps/web/Dockerfile
+++ b/apps/web/Dockerfile
@@ -71,6 +71,8 @@ RUN addgroup -g 1001 appuser && \
# Copy built files from builder stage
COPY --from=builder --chown=appuser:appuser /app/apps/web/dist /usr/share/nginx/html
+# The inherited web root must be writable for atomic runtime configuration updates.
+RUN chown appuser:appuser /usr/share/nginx/html
# Copy nginx configuration and public runtime configuration renderer
COPY --chown=appuser:appuser apps/web/nginx.conf /etc/nginx/conf.d/default.conf
diff --git a/scripts/security/web-runtime-env.test.mjs b/scripts/security/web-runtime-env.test.mjs
index 6ecf5b6ce..84d2f6792 100644
--- a/scripts/security/web-runtime-env.test.mjs
+++ b/scripts/security/web-runtime-env.test.mjs
@@ -3,6 +3,7 @@ import { spawnSync } from "node:child_process";
import {
chmodSync,
copyFileSync,
+ mkdirSync,
mkdtempSync,
readFileSync,
rmSync,
@@ -35,6 +36,83 @@ const scenarios = [
{ name: "unset public values", api: "", client: "", key: "" },
];
+test("production runtime starts and serves configuration as its default non-root user", () => {
+ 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 docker = (args, timeout = 30_000) => {
+ const result = spawnSync("docker", args, { encoding: "utf8", timeout });
+ assert.equal(result.status, 0, result.error?.message ?? result.stderr);
+ return result.stdout;
+ };
+ try {
+ mkdirSync(resolve(fixture, "dist/assets"), { recursive: true });
+ mkdirSync(resolve(fixture, "apps/web"), { recursive: true });
+ writeFileSync(resolve(fixture, "dist/index.html"), "runtime fixture");
+ for (const asset of ["root.js", "assets/app.js"]) {
+ writeFileSync(resolve(fixture, "dist", asset), '"KANEO_API_URL"');
+ }
+ for (const file of ["nginx.conf", "env.sh", "env.awk"]) {
+ copyFileSync(
+ resolve(root, "apps/web", file),
+ resolve(fixture, "apps/web", file),
+ );
+ }
+ // Exercise the real runtime stage, substituting only the frontend build.
+ // A writable bind mount over the web root would hide image ownership bugs.
+ const dockerfile = readFileSync(
+ resolve(root, "apps/web/Dockerfile"),
+ "utf8",
+ );
+ const runtime = dockerfile.match(/^FROM nginx:.* AS runtime\r?\n[\s\S]*/m);
+ assert.ok(runtime, "standalone web runtime stage must exist");
+ writeFileSync(
+ resolve(fixture, "Dockerfile"),
+ `FROM scratch AS builder\nCOPY dist /app/apps/web/dist\n${runtime[0]}`,
+ );
+ docker(["image", "inspect", image]);
+ docker(["build", "--network=none", "-t", runtimeImage, fixture], 120_000);
+ const output = docker([
+ "run",
+ "--rm",
+ "--name",
+ container,
+ "--pull=never",
+ "--network=none",
+ "--env",
+ "KANEO_API_URL=https://api.example.test/api",
+ runtimeImage,
+ "sh",
+ "-eu",
+ "-c",
+ [
+ 'test "$(id -u)" = 1001',
+ "/docker-entrypoint.sh nginx -t",
+ "nginx > /tmp/nginx-output.log 2>&1",
+ 'test "$(wget -qO- http://127.0.0.1:5173/)" = "runtime fixture"',
+ "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",
+ "wget -qO- http://127.0.0.1:5173/.well-known/oauth-authorization-server/api",
+ "nginx -s quit",
+ ].join("; "),
+ ]);
+ const responses = output
+ .trim()
+ .split("\n")
+ .slice(-4)
+ .map((line) => JSON.parse(line));
+ assert.equal(responses[0], "https://api.example.test/api");
+ 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");
+ } finally {
+ spawnSync("docker", ["rm", "-f", container], { timeout: 30_000 });
+ spawnSync("docker", ["image", "rm", runtimeImage], { timeout: 30_000 });
+ rmSync(fixture, { recursive: true, force: true });
+ }
+});
+
for (const scenario of scenarios) {
test(scenario.name, () => {
const fixture = mkdtempSync(resolve(tmpdir(), "kaneo-web-env-"));