diff --git a/admin-ui/.env.example b/admin-ui/.env.example index fd7d69d..9a1fed0 100644 --- a/admin-ui/.env.example +++ b/admin-ui/.env.example @@ -6,5 +6,8 @@ # quando o proxy encaminha /admin/* para a API). Opcional: omite para usar window.location.origin. # NEXT_PUBLIC_ERROR_REPORTING_AUTH_ORIGIN=https://errors.bitreport.pt -# Apenas desenvolvimento (NODE_ENV!==production): dados fictícios sem API. +# Apenas com NODE_ENV=development: dados fictícios sem API (não confiar em "!== production" no Edge). # ERROR_REPORTING_UI_DEMO=1 +# +# Só para ambientes fechados / local: desliga redirect para /login (nunca em produção pública). +# ERROR_REPORTING_UI_SKIP_LOGIN=1 diff --git a/admin-ui/middleware.ts b/admin-ui/middleware.ts index efe313c..3efad1b 100644 --- a/admin-ui/middleware.ts +++ b/admin-ui/middleware.ts @@ -5,12 +5,17 @@ import { NextResponse } from "next/server"; const ACCESS_COOKIE = "__Host-access"; /** - * Unauthenticated access is only allowed in non-production when demo mode is on. - * In production, demo data is disabled in `lib/incidents-data.ts` and routes require a session. + * Unauthenticated access is only allowed when demo mode is explicitly enabled in development. + * Edge middleware often sees `NODE_ENV` unset; treating "not production" as dev would open the shell publicly if DEMO=1. + * Opt-in escape hatch: ERROR_REPORTING_UI_SKIP_LOGIN=1 (local/staging only; never in public prod). */ function _allowWithoutSession(): boolean { + if (process.env.ERROR_REPORTING_UI_SKIP_LOGIN === "1") { + return true; + } return ( - process.env.NODE_ENV !== "production" && process.env.ERROR_REPORTING_UI_DEMO === "1" + process.env.NODE_ENV === "development" && + process.env.ERROR_REPORTING_UI_DEMO === "1" ); } diff --git a/deploy/lxc/systemd/bitreport-error-reporting-api.service b/deploy/lxc/systemd/bitreport-error-reporting-api.service new file mode 100644 index 0000000..34951b2 --- /dev/null +++ b/deploy/lxc/systemd/bitreport-error-reporting-api.service @@ -0,0 +1,28 @@ +# BitReport error reporting — Fastify admin API (auth, RBAC, dados para admin-ui). +# Install: copy to /etc/systemd/system/ on the LXC, then daemon-reload + enable --now. +# +# PORT: o EnvironmentFile partilhado (/etc/error-reporting/env) define PORT=3041 para o ingest-api. +# O systemd não garante que Environment=PORT=3200 sobrescreva o ficheiro em todas as versões; +# usar /usr/bin/env PORT=3200 no ExecStart. +# +# Segredos: JWT_SECRET e COOKIE_SECRET em /etc/error-reporting/env (openssl rand -base64 …). + +[Unit] +Description=BitReport error reporting admin API (Fastify) +After=network-online.target mariadb.service +Wants=network-online.target + +[Service] +Type=simple +User=error-reporting +Group=error-reporting +EnvironmentFile=-/etc/error-reporting/env +WorkingDirectory=/opt/errors.bitreport.pt/api +ExecStart=/usr/bin/env PORT=3200 /usr/bin/node dist/index.js +Restart=on-failure +RestartSec=5 +NoNewPrivileges=yes +PrivateTmp=yes + +[Install] +WantedBy=multi-user.target