Migrate to Gitea + local Docker Desktop k8s/Harbor; remove SSO
- Remove Microsoft Entra ID SSO entirely; local admin credentials login is the only sign-in path (fail-closed on empty LOCAL_ADMIN_PASSWORD). Delete config/users.json allowlist and lookupRole. - Move CI from .github to .gitea/workflows (Gitea Actions, runner label gitea-runner); drop the k8s-API network debug step. - Replace JFrog with local Harbor: push/pull via host.docker.internal:8080/library, login with HARBOR_* Gitea secrets, pull secret renamed to harbor-pull-secret (created by CI per namespace). - Adapt Helm values to Docker Desktop k8s: storageClassName hostpath, Harbor image repositories, *.local ingress hosts, AUTH_URL scheme http (configurable via ingress.scheme). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
a79a01437a
commit
b3d48198c4
@@ -94,38 +94,18 @@ Restart=always
|
||||
|
||||
## Authentication & authorization
|
||||
|
||||
Sign-in uses Auth.js / NextAuth v5. There are **two** ways in, and access is
|
||||
**role-based** (`admin` = full access; `user` = read-only dashboard/trend):
|
||||
Sign-in uses Auth.js / NextAuth v5 with a single sign-in path:
|
||||
|
||||
1. **Microsoft Entra ID SSO** — allowed only if the user's email is in the
|
||||
allowlist (see below). Unlisted emails cannot enter the app (fail closed).
|
||||
2. **Local username/password** (break-glass admin) — a form on `/login`,
|
||||
controlled by `LOCAL_ADMIN_USERNAME` / `LOCAL_ADMIN_PASSWORD`. This account is
|
||||
always `admin` and bypasses the allowlist, so you can always get in to fix a
|
||||
broken/empty `config/users.json`.
|
||||
- **Local username/password** — a form on `/login`, controlled by
|
||||
`LOCAL_ADMIN_USERNAME` / `LOCAL_ADMIN_PASSWORD`. This account always has the
|
||||
`admin` role. An empty `LOCAL_ADMIN_PASSWORD` disables login entirely (fail
|
||||
closed).
|
||||
|
||||
Middleware redirects any unauthenticated request to `/login` and enforces roles
|
||||
**server-side**: normal users are redirected away from admin pages
|
||||
**server-side**: non-admin users are redirected away from admin pages
|
||||
(`/cost-registration`, `/cost-item-creation`, `/year-creation`) and any write API
|
||||
call (non-`GET` `/api/*`) returns **403**. Read APIs (`GET /api/*`) stay open to
|
||||
any signed-in user. The sidebar "Admin" group is also hidden for normal users.
|
||||
|
||||
### Role allowlist — `config/users.json`
|
||||
|
||||
Committed (NOT secret), hand-edited map of **email → role**:
|
||||
|
||||
```json
|
||||
{
|
||||
"Sunny_Ho@trendmicro.com": "admin",
|
||||
"tom_chien@trendmicro.com": "user"
|
||||
}
|
||||
```
|
||||
|
||||
- Emails are matched **case-insensitively**.
|
||||
- An email that is absent (or an unreadable/invalid file) ⇒ SSO sign-in denied.
|
||||
- The role is baked into the session JWT at sign-in, so after editing this file
|
||||
users must **re-login** (or restart the app) for changes to apply:
|
||||
`pm2 restart it_cost_dashboard`.
|
||||
any signed-in user. The sidebar "Admin" group is also hidden for non-admins.
|
||||
|
||||
### Required env vars (`.env.production`)
|
||||
|
||||
@@ -133,32 +113,22 @@ Next.js does **not** load `.env.local` in production, so these must live in
|
||||
`.env.production` on the EC2 host:
|
||||
|
||||
```env
|
||||
AUTH_MICROSOFT_ENTRA_ID_ID="<prod Application (client) ID>"
|
||||
AUTH_MICROSOFT_ENTRA_ID_SECRET="<prod client secret VALUE>"
|
||||
AUTH_MICROSOFT_ENTRA_ID_ISSUER="https://login.microsoftonline.com/<tenant ID>/v2.0"
|
||||
AUTH_SECRET="<32-byte random string, e.g. `npx auth secret`>"
|
||||
AUTH_URL="https://<your-prod-domain>" # or set AUTH_TRUST_HOST=true behind a TLS proxy/ALB
|
||||
|
||||
# Local break-glass admin. Non-empty password ENABLES the /login form; empty disables it.
|
||||
# Local admin login. Non-empty password ENABLES the /login form; empty disables it.
|
||||
LOCAL_ADMIN_USERNAME="admin"
|
||||
LOCAL_ADMIN_PASSWORD="<set a strong password>"
|
||||
```
|
||||
|
||||
After changing `config/users.json` or the auth env vars, rebuild and restart:
|
||||
After changing the auth env vars, rebuild and restart:
|
||||
|
||||
```bash
|
||||
rm -rf .next && npm run build:prod && pm2 restart it_cost_dashboard --update-env
|
||||
```
|
||||
|
||||
In the Entra app registration, add the prod **redirect URI**:
|
||||
|
||||
```
|
||||
https://<your-prod-domain>/api/auth/callback/microsoft-entra-id
|
||||
```
|
||||
|
||||
(Dev uses `http://localhost:3000/api/auth/callback/microsoft-entra-id`, configured
|
||||
in the gitignored `.env.local`.) The `AUTH_*` vars are read at both build and
|
||||
runtime, so they must be present before `npm run build:prod` and at `pm2` start.
|
||||
The `AUTH_*` vars are read at both build and runtime, so they must be present
|
||||
before `npm run build:prod` and at `pm2` start.
|
||||
|
||||
## Notes
|
||||
|
||||
|
||||
Reference in New Issue
Block a user