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(docker): render nginx templates into runtime storage

Tin6186f4008fe1
diff --git a/Dockerfile.kaneo b/Dockerfile.kaneo
index 64746f306..fdb22f602 100644
--- a/Dockerfile.kaneo
+++ b/Dockerfile.kaneo
@@ -106,11 +106,12 @@ RUN cd /app/apps/api && node -e "const fs=require('fs');for(const m of ['bcryptj
COPY --from=web-builder --chown=appuser:appuser /app/apps/web/dist /usr/share/nginx/html
COPY apps/web/nginx.main.conf /etc/nginx/nginx.conf
COPY --chown=appuser:appuser apps/web/nginx.kaneo.conf /etc/nginx/conf.d/default.conf
+COPY --chown=appuser:appuser apps/web/runtime-storage.sh /docker-entrypoint.d/05-kaneo-runtime-storage.sh
COPY --chown=appuser:appuser apps/web/env.sh /docker-entrypoint.d/env.sh
COPY --chown=appuser:appuser apps/web/env.awk /docker-entrypoint.d/env.awk
COPY --chown=appuser:appuser deploy/kaneo-entrypoint.sh /usr/local/bin/kaneo-entrypoint.sh
-RUN chmod +x /docker-entrypoint.d/env.sh /usr/local/bin/kaneo-entrypoint.sh
+RUN chmod +x /docker-entrypoint.d/05-kaneo-runtime-storage.sh /docker-entrypoint.d/env.sh /usr/local/bin/kaneo-entrypoint.sh
ENV NODE_ENV=production
ENV TMPDIR=/var/lib/kaneo/tmp
diff --git a/apps/web/Dockerfile b/apps/web/Dockerfile
index c6ef7b045..b22514e5d 100644
--- a/apps/web/Dockerfile
+++ b/apps/web/Dockerfile
@@ -65,13 +65,16 @@ COPY apps/web/nginx.main.conf /etc/nginx/nginx.conf
COPY --chown=appuser:appuser apps/web/nginx.conf /etc/nginx/conf.d/default.conf
RUN chown -R appuser:appuser /etc/nginx/conf.d
-# Copy and set permissions for environment script
+# Copy and set permissions for runtime storage and environment scripts.
+# env.sh keeps sorting after numbered hooks so their exports reach it.
+COPY --chown=appuser:appuser apps/web/runtime-storage.sh /docker-entrypoint.d/05-kaneo-runtime-storage.sh
COPY --chown=appuser:appuser apps/web/env.sh /docker-entrypoint.d/env.sh
COPY --chown=appuser:appuser apps/web/env.awk /docker-entrypoint.d/env.awk
-RUN chmod +x /docker-entrypoint.d/env.sh
+RUN chmod +x /docker-entrypoint.d/05-kaneo-runtime-storage.sh /docker-entrypoint.d/env.sh
# Switch to non-root user
ENV TMPDIR=/var/lib/kaneo/tmp
+ENV NGINX_ENVSUBST_OUTPUT_DIR=/var/lib/kaneo/nginx/conf.d
USER 1001:0
EXPOSE 5173
diff --git a/apps/web/nginx.kaneo.conf b/apps/web/nginx.kaneo.conf
index 03165feba..c64dd21e4 100644
--- a/apps/web/nginx.kaneo.conf
+++ b/apps/web/nginx.kaneo.conf
@@ -2,6 +2,10 @@ server {
listen 5173;
server_name localhost;
+ # The API logs its own requests; per-request lines and health probes from
+ # nginx would interleave with them in the same container output.
+ access_log off;
+
# Allow larger OAuth/Better Auth session cookies in request headers.
client_header_buffer_size 8k;
large_client_header_buffers 4 32k;
diff --git a/apps/web/nginx.main.conf b/apps/web/nginx.main.conf
index d58b95876..61d6bb1e3 100644
--- a/apps/web/nginx.main.conf
+++ b/apps/web/nginx.main.conf
@@ -9,7 +9,14 @@ events {
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
- access_log /dev/stdout;
+
+ log_format main '$remote_addr - $remote_user [$time_local] "$request" '
+ '$status $body_bytes_sent "$http_referer" '
+ '"$http_user_agent" "$http_x_forwarded_for"';
+ access_log /dev/stdout main;
+
+ sendfile on;
+ keepalive_timeout 65;
client_body_temp_path /var/lib/kaneo/nginx/client_body;
proxy_temp_path /var/lib/kaneo/nginx/proxy;
@@ -17,5 +24,6 @@ http {
uwsgi_temp_path /var/lib/kaneo/nginx/uwsgi;
scgi_temp_path /var/lib/kaneo/nginx/scgi;
- include /etc/nginx/conf.d/*.conf;
+ # Seeded from /etc/nginx/conf.d at startup; see runtime-storage.sh.
+ include /var/lib/kaneo/nginx/conf.d/*.conf;
}
diff --git a/apps/web/runtime-storage.sh b/apps/web/runtime-storage.sh
new file mode 100644
index 000000000..53828fd29
--- /dev/null
+++ b/apps/web/runtime-storage.sh
@@ -0,0 +1,11 @@
+#!/bin/sh
+set -eu
+
+# nginx reads its server configuration from writable runtime storage so an
+# arbitrary UID or a read-only root can still render nginx templates. Runs
+# before nginx's template hook, which may replace these copies by file name.
+runtime=/var/lib/kaneo
+mkdir -p "$runtime/html" "$runtime/nginx/conf.d" "$runtime/tmp"
+find "$runtime/nginx/conf.d" -mindepth 1 -delete
+cp -R /etc/nginx/conf.d/. "$runtime/nginx/conf.d/"
+chmod -R u+rwX "$runtime/nginx/conf.d"
diff --git a/charts/kaneo/README.md b/charts/kaneo/README.md
index e9e745bf8..2240708fd 100644
--- a/charts/kaneo/README.md
+++ b/charts/kaneo/README.md
@@ -470,6 +470,8 @@ 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, set `root /var/lib/kaneo/html;`; the previous `/usr/share/nginx/html` holds the unconfigured build. Templates in `/etc/nginx/templates` still render at startup, and `default.conf.template` replaces the bundled server configuration.
+
### Registration Control
By default, user registration is enabled. To disable new user registration:
```yaml
diff --git a/deploy/kaneo-entrypoint.sh b/deploy/kaneo-entrypoint.sh
index 6bc71bfd4..939284ab1 100644
--- a/deploy/kaneo-entrypoint.sh
+++ b/deploy/kaneo-entrypoint.sh
@@ -75,6 +75,7 @@ elif [ -z "${AUTH_SECRET:-}" ]; then
echo "WARNING: Set AUTH_SECRET in your .env to persist sessions across restarts."
fi
+/docker-entrypoint.d/05-kaneo-runtime-storage.sh
/docker-entrypoint.d/env.sh
node --enable-source-maps /app/apps/api/dist/index.js &
diff --git a/scripts/security/web-runtime-env.test.mjs b/scripts/security/web-runtime-env.test.mjs
index e902f2210..bce54f2f6 100644
--- a/scripts/security/web-runtime-env.test.mjs
+++ b/scripts/security/web-runtime-env.test.mjs
@@ -66,7 +66,13 @@ test("production runtime serves configuration with default and restricted users"
template,
'server { listen 5174; return 200 "$KANEO_CLIENT_URL"; }\n',
);
- for (const file of ["nginx.conf", "nginx.main.conf", "env.sh", "env.awk"]) {
+ for (const file of [
+ "nginx.conf",
+ "nginx.main.conf",
+ "runtime-storage.sh",
+ "env.sh",
+ "env.awk",
+ ]) {
copyFileSync(
resolve(root, "apps/web", file),
resolve(fixture, "apps/web", file),
@@ -88,12 +94,9 @@ test("production runtime serves configuration with default and restricted users"
docker(["build", "--network=none", "-t", runtimeImage, fixture], 120_000);
for (const scenario of [
{
- name: "default non-root user with nginx template",
+ name: "default non-root user",
uid: "1001",
- args: [
- "--mount",
- `type=bind,source=${template},target=/etc/nginx/templates/runtime.conf.template,readonly`,
- ],
+ args: [],
},
{
name: "arbitrary OpenShift UID",
@@ -123,6 +126,8 @@ test("production runtime serves configuration with default and restricted users"
...scenario.args,
"--mount",
`type=bind,source=${hook},target=/docker-entrypoint.d/00-test.envsh,readonly`,
+ "--mount",
+ `type=bind,source=${template},target=/etc/nginx/templates/runtime.conf.template,readonly`,
"--env",
"KANEO_API_URL=https://api.example.test/api",
runtimeImage,
@@ -134,6 +139,8 @@ test("production runtime serves configuration with default and restricted users"
"test ! -d /var/lib/kaneo/html",
'test "$(cat /usr/share/nginx/html/root.js)" = \'"KANEO_API_URL"\'',
"/docker-entrypoint.sh nginx -t",
+ "test -f /var/lib/kaneo/nginx/conf.d/default.conf",
+ "test -f /var/lib/kaneo/nginx/conf.d/runtime.conf",
'test "$(cat /var/lib/kaneo/html/hook.js)" = \'"https://hook.example.test"\'',
'test "$(cat /var/lib/kaneo/html/mcp-oauth-resource.json)" != "{}"',
"KANEO_API_URL=https://changed.example.test/api /docker-entrypoint.d/env.sh",
@@ -142,7 +149,7 @@ test("production runtime serves configuration with default and restricted users"
"nginx -t",
"nginx > /var/lib/kaneo/tmp/nginx-output.log 2>&1",
'test "$(wget -qO- http://127.0.0.1:5173/)" = "runtime fixture"',
- 'if [ "$(id -u)" = 1001 ]; then test "$(wget -qO- http://127.0.0.1:5174/)" = "https://hook.example.test"; fi',
+ 'test "$(wget -qO- http://127.0.0.1:5174/)" = "https://hook.example.test"',
"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",
@@ -218,7 +225,7 @@ for (const scenario of scenarios) {
image,
"-eu",
"-c",
- "sh /renderer/env.sh; nginx -t; nginx; wget -qO /var/lib/kaneo/resource-response.json http://127.0.0.1:5173/.well-known/oauth-protected-resource/api/mcp; wget -qO /var/lib/kaneo/authorization-response.json http://127.0.0.1:5173/.well-known/oauth-authorization-server/api; nginx -s quit",
+ "sh /renderer/runtime-storage.sh; sh /renderer/env.sh; nginx -t; nginx; wget -qO /var/lib/kaneo/resource-response.json http://127.0.0.1:5173/.well-known/oauth-protected-resource/api/mcp; wget -qO /var/lib/kaneo/authorization-response.json http://127.0.0.1:5173/.well-known/oauth-authorization-server/api; nginx -s quit",
],
{
encoding: "utf8",