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:
Tom Chien (IQ-AS)
2026-11-17 14:00:45 +08:00
co-authored by Claude Opus 4.6
parent a79a01437a
commit b3d48198c4
16 changed files with 104 additions and 324 deletions
-23
View File
@@ -7,19 +7,11 @@ function errorMessage(code: string | undefined): string | null {
switch (code) {
case "CredentialsSignin":
return "Invalid username or password";
case "AccessDenied":
return "Your account is not authorized — contact the administrator";
default:
return code ? "Sign-in failed — please try again" : null;
}
}
// Server action: kick off the Microsoft SSO flow.
async function microsoftLogin() {
"use server";
await signIn("microsoft-entra-id", { redirectTo: "/" });
}
// Server action: local username/password login.
async function credentialsLogin(formData: FormData) {
"use server";
@@ -63,21 +55,6 @@ export default async function LoginPage({
</div>
)}
<form action={microsoftLogin} className="mt-6">
<button
type="submit"
className="w-full rounded-md bg-[#2F2F2F] px-3 py-2 text-sm font-medium text-white transition-colors hover:bg-black"
>
Sign in with Microsoft
</button>
</form>
<div className="my-6 flex items-center gap-3 text-xs text-[#9CA3AF]">
<span className="h-px flex-1 bg-[#E5E7EB]" />
OR
<span className="h-px flex-1 bg-[#E5E7EB]" />
</div>
<form action={credentialsLogin} className="mt-6 flex flex-col gap-3">
<label className="flex flex-col gap-1 text-sm text-[#374151]">
Username
+4 -5
View File
@@ -10,14 +10,13 @@ const ADMIN_PAGE_PREFIXES = [
];
// Edge-safe Auth.js config. This is imported by the middleware, which runs in
// the edge runtime, so it MUST NOT import Node APIs (node:fs) or the providers
// (Credentials/MicrosoftEntraID pull in Node crypto). The JSON allowlist is read
// only at sign-in in src/auth.ts (Node) and the resulting role is baked into the
// JWT; here we only read the role off the token.
// the edge runtime, so it MUST NOT import Node APIs or the Credentials provider
// (it pulls in Node crypto). The role is baked into the JWT at sign-in in
// src/auth.ts (Node); here we only read the role off the token.
export const authConfig = {
// Stateless JWT sessions — no DB adapter, keeps the middleware edge-compatible.
session: { strategy: "jwt" },
// Custom sign-in page offering both SSO and local username/password.
// Custom sign-in page with local username/password.
pages: { signIn: "/login" },
// Providers are added in the Node config (src/auth.ts). Empty here on purpose.
providers: [],
+7 -42
View File
@@ -1,38 +1,17 @@
import NextAuth from "next-auth";
import MicrosoftEntraID from "next-auth/providers/microsoft-entra-id";
import Credentials from "next-auth/providers/credentials";
import { authConfig } from "@/auth.config";
import { lookupRole, safeEqual } from "@/lib/authz";
import { safeEqual } from "@/lib/authz";
// Auth.js v5 (NextAuth). Node-runtime config: spreads the edge-safe authConfig
// and adds the providers + Node-only callbacks (signIn/jwt) that need node:fs
// via lookupRole. Imported by the API route handler and server components —
// NEVER by the edge middleware (which uses src/auth.config.ts instead).
// and adds the Credentials provider + the jwt callback. Imported by the API
// route handler and server components — NEVER by the edge middleware (which
// uses src/auth.config.ts instead).
//
// Two sign-in paths:
// 1. Microsoft Entra ID SSO — allowed only if the email is in config/users.json.
// 2. Local username/password — break-glass admin, bypasses the JSON allowlist.
// Single sign-in path: local username/password (admin account).
export const { handlers, auth, signIn, signOut } = NextAuth({
...authConfig,
providers: [
MicrosoftEntraID({
clientId: process.env.AUTH_MICROSOFT_ENTRA_ID_ID,
clientSecret: process.env.AUTH_MICROSOFT_ENTRA_ID_SECRET,
// Tenant-specific issuer restricts sign-in to our organization only.
issuer: process.env.AUTH_MICROSOFT_ENTRA_ID_ISSUER,
// The provider's default profile() pulls the Graph photo and inlines it as a
// base64 data-URI into user.image -> the `picture` JWT claim. Since sessions
// are JWTs, that becomes a multi-KB chunked session cookie whose combined
// Cookie header overflows nginx's proxy buffer -> 502 before the request ever
// reaches this app. We never render an avatar, so keep the token lean.
authorization: { params: { scope: "openid profile email" } },
profile: (profile) => ({
id: profile.sub,
name: profile.name,
email: profile.email,
image: null,
}),
}),
Credentials({
name: "Local account",
credentials: {
@@ -58,24 +37,10 @@ export const { handlers, auth, signIn, signOut } = NextAuth({
],
callbacks: {
...authConfig.callbacks,
// Gate SSO sign-ins against the JSON allowlist. The local Credentials
// account is always allowed (its role is set in authorize()).
signIn({ user, account, profile }) {
if (account?.provider === "credentials") return true;
const email =
user.email ??
(profile?.email as string | undefined) ??
(profile?.preferred_username as string | undefined);
// Returning false surfaces to the login page as ?error=AccessDenied.
return lookupRole(email) !== null;
},
// On first sign-in, bake the role into the JWT so the edge middleware can
// read it without touching node:fs.
// On sign-in, bake the role into the JWT so the edge middleware can read it.
jwt({ token, user }) {
if (user) {
token.role = user.role ?? lookupRole(user.email) ?? "user";
token.role = user.role ?? "user";
}
return token;
},
+7 -13
View File
@@ -1,4 +1,5 @@
import { auth, signIn, signOut } from "@/auth";
import Link from "next/link";
import { auth, signOut } from "@/auth";
export default async function TopNav() {
const session = await auth();
@@ -25,19 +26,12 @@ export default async function TopNav() {
</form>
</div>
) : (
<form
action={async () => {
"use server";
await signIn("microsoft-entra-id");
}}
<Link
href="/login"
className="rounded-md bg-white/10 px-4 py-1.5 text-sm font-medium hover:bg-white/20"
>
<button
type="submit"
className="rounded-md bg-white/10 px-4 py-1.5 text-sm font-medium hover:bg-white/20"
>
Login
</button>
</form>
Login
</Link>
)}
</header>
);
-42
View File
@@ -1,48 +1,6 @@
import fs from "node:fs";
import path from "node:path";
// Role model for the app. Access is either full "admin" or read-only "user".
// NOTE: this module uses node:fs and MUST only be imported from Node runtime
// code (src/auth.ts / server components / API routes) — never from the edge
// middleware, or the edge bundle will fail to compile.
export type Role = "admin" | "user";
// Resolve a user's role from the hand-edited allowlist at config/users.json.
// Emails are matched case-insensitively. This is FAIL CLOSED: a missing file,
// invalid JSON, or an email that is not listed all return null (access denied).
export function lookupRole(email: string | null | undefined): Role | null {
if (!email) return null;
let raw: string;
try {
raw = fs.readFileSync(
path.join(process.cwd(), "config", "users.json"),
"utf8"
);
} catch {
// File missing/unreadable -> deny everyone (local admin is the break-glass).
return null;
}
let parsed: unknown;
try {
parsed = JSON.parse(raw);
} catch {
return null;
}
if (!parsed || typeof parsed !== "object") return null;
// Lowercase every key so the lookup is case-insensitive.
const table: Record<string, Role> = {};
for (const [key, value] of Object.entries(parsed as Record<string, unknown>)) {
if (value === "admin" || value === "user") {
table[key.toLowerCase()] = value;
}
}
return table[email.toLowerCase()] ?? null;
}
// Constant-time string comparison to avoid leaking secrets via timing.
// Pure JS (no node:crypto) so this stays cheap and dependency-free.
export function safeEqual(a: string, b: string): boolean {
+2 -1
View File
@@ -2,7 +2,8 @@ import NextAuth from "next-auth";
import { authConfig } from "@/auth.config";
// Edge-runtime gate for the whole app. Uses the edge-safe config only —
// src/auth.ts pulls in node:fs via lookupRole and must never be imported here.
// src/auth.ts pulls in the Node-only Credentials provider and must never be
// imported here.
export const { auth: middleware } = NextAuth(authConfig);
export const config = {