Let Cloudron turn on named admins, the ops token, and Umami after the image is built #118

Merged
an.di merged 3 commits from adilallo/fix/CR-394-rule-admin-ops-token-umami into main 2026-11-23 21:35:56 +00:00
Member

Overview

Staging needs named rule admins, an ops bearer token, and cookieless Umami without rebuilding the Next image every time env changes.

NEXT_PUBLIC_* is normally inlined at build time, so cloudron env set would not show the tracker. This reads the Umami vars at request time, always allows the analytics host in CSP, and documents the staging env plus smoke checks.

Changes

  • lib/umami.ts — read NEXT_PUBLIC_UMAMI_SRC / NEXT_PUBLIC_UMAMI_WEBSITE_ID by key at call time (not a static process.env.NEXT_PUBLIC_* lookup that gets inlined).
  • app/layout.tsx — Umami script in a Suspense child that await connection(), so the tracker can appear after env is set, with data-do-not-track and data-exclude-search.
  • next.config.mjs — CSP always allows https://analytics.communityrule.info for script and connect, even when the tracker is off.
  • scripts/staging-smoke.sh — logged-out /api/ops/rule-counts expects 401 (or 404 skip if neither admin emails nor token is set); optional bearer 200; homepage data-website-id (required only with EXPECT_UMAMI=1).
  • Docs: staging env for RULE_ADMIN_EMAILS and OPS_PRUNE_TOKEN, Umami install with --no-sso, smoke flags.
  • Tests for request-time Umami env and the analytics origin in CSP.

Screenshots

01-umami-websites-logged-in.png

How to Test

  1. npx vitest run tests/unit/umami.test.ts tests/unit/securityHeaders.test.ts

  2. npx tsc --noEmit

  3. Against staging (token from 1Password, do not paste it into the PR):

    ./scripts/staging-smoke.sh staging.communityrule.info
    EXPECT_UMAMI=1 OPS_PRUNE_TOKEN=... ./scripts/staging-smoke.sh staging.communityrule.info![02-umami-staging-dashboard.png](attachments/43111409-a37b-4d17-9518-5ea39cd5aa4d)![04-umami-tracking-code-replays-off.png](attachments/aeb4a84a-376c-4dec-8a8d-98b85072856c)![08-staging-profile-named-admin.png](attachments/c92b19f3-43c7-4dce-a1a0-a28fbffe94cf)![10-admin-opened-private-rule.png](attachments/db1d963c-46ec-49dd-b2e7-d0eb59834d4f)
    
## Overview Staging needs named rule admins, an ops bearer token, and cookieless Umami without rebuilding the Next image every time env changes. `NEXT_PUBLIC_*` is normally inlined at build time, so `cloudron env set` would not show the tracker. This reads the Umami vars at request time, always allows the analytics host in CSP, and documents the staging env plus smoke checks. ## Changes - `lib/umami.ts` — read `NEXT_PUBLIC_UMAMI_SRC` / `NEXT_PUBLIC_UMAMI_WEBSITE_ID` by key at call time (not a static `process.env.NEXT_PUBLIC_*` lookup that gets inlined). - `app/layout.tsx` — Umami script in a Suspense child that `await connection()`, so the tracker can appear after env is set, with `data-do-not-track` and `data-exclude-search`. - `next.config.mjs` — CSP always allows `https://analytics.communityrule.info` for script and connect, even when the tracker is off. - `scripts/staging-smoke.sh` — logged-out `/api/ops/rule-counts` expects 401 (or 404 skip if neither admin emails nor token is set); optional bearer 200; homepage `data-website-id` (required only with `EXPECT_UMAMI=1`). - Docs: staging env for `RULE_ADMIN_EMAILS` and `OPS_PRUNE_TOKEN`, Umami install with `--no-sso`, smoke flags. - Tests for request-time Umami env and the analytics origin in CSP. ## Screenshots ![01-umami-websites-logged-in.png](attachments/ae4fb336-d193-46d5-af65-d8d3f22278d4) ## How to Test 1. `npx vitest run tests/unit/umami.test.ts tests/unit/securityHeaders.test.ts` 2. `npx tsc --noEmit` 3. Against staging (token from 1Password, do not paste it into the PR): ```bash ./scripts/staging-smoke.sh staging.communityrule.info EXPECT_UMAMI=1 OPS_PRUNE_TOKEN=... ./scripts/staging-smoke.sh staging.communityrule.info![02-umami-staging-dashboard.png](attachments/43111409-a37b-4d17-9518-5ea39cd5aa4d)![04-umami-tracking-code-replays-off.png](attachments/aeb4a84a-376c-4dec-8a8d-98b85072856c)![08-staging-profile-named-admin.png](attachments/c92b19f3-43c7-4dce-a1a0-a28fbffe94cf)![10-admin-opened-private-rule.png](attachments/db1d963c-46ec-49dd-b2e7-d0eb59834d4f)
an.di added 3 commits 2026-11-23 21:35:42 +00:00
Tracker env is read at request time and the CSP already allows the analytics host, so staging can set a rule admin, an ops bearer token, and the cookieless Umami site without rebuilding.
Unconfigured hosts were failing checks that only apply once an admin, ops token, or tracker is set.
an.di self-assigned this 2026-11-23 21:35:48 +00:00
an.di merged commit 077942166c into main 2026-11-23 21:35:56 +00:00
an.di deleted branch adilallo/fix/CR-394-rule-admin-ops-token-umami 2026-11-23 21:35:56 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: CommunityRule/community-rule#118