fix(admin-ui): middleware login gate; add admin API systemd unit

- Middleware: require development+demo or SKIP_LOGIN for unauthenticated access.
- Document SKIP_LOGIN and stricter demo in .env.example.
- Ship bitreport-error-reporting-api.service (PORT via ExecStart env; shared env has PORT for ingest).
This commit is contained in:
1sonhador committed 2026-03-29 18:32:05 +01:00
1 parent c02c300dc3
commit 83308b465b
3 files changed
+40 -4

No files matched your search

+4 -1
View File
@@ -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
+8 -3
View File
@@ -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"
);
}
@@ -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