turn on SSO
This commit is contained in:
@@ -31,7 +31,8 @@
|
|||||||
"Bash(git:*)",
|
"Bash(git:*)",
|
||||||
"Bash(/tmp/windows-amd64/helm.exe template:*)",
|
"Bash(/tmp/windows-amd64/helm.exe template:*)",
|
||||||
"Bash(echo \"exit=$?\")",
|
"Bash(echo \"exit=$?\")",
|
||||||
"Read(//tmp/**)"
|
"Read(//tmp/**)",
|
||||||
|
"Bash(tail:*)"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -265,6 +265,9 @@ jobs:
|
|||||||
--set-string secrets.authSecret="${{ secrets.AUTH_SECRET_DEV }}" \
|
--set-string secrets.authSecret="${{ secrets.AUTH_SECRET_DEV }}" \
|
||||||
--set-string secrets.dbRootPassword="${{ secrets.DB_PASSWORD_DEV }}" \
|
--set-string secrets.dbRootPassword="${{ secrets.DB_PASSWORD_DEV }}" \
|
||||||
--set-string secrets.localAdminPassword="${{ secrets.LOCAL_ADMIN_PASSWORD_DEV }}" \
|
--set-string secrets.localAdminPassword="${{ secrets.LOCAL_ADMIN_PASSWORD_DEV }}" \
|
||||||
|
--set-string secrets.entraClientId="${{ secrets.ENTRA_CLIENT_ID_DEV }}" \
|
||||||
|
--set-string secrets.entraClientSecret="${{ secrets.ENTRA_CLIENT_SECRET_DEV }}" \
|
||||||
|
--set-string secrets.entraIssuer="${{ secrets.ENTRA_ISSUER_DEV }}" \
|
||||||
--wait --timeout 10m --atomic --debug
|
--wait --timeout 10m --atomic --debug
|
||||||
|
|
||||||
# ---- PROD DEPLOY (tag push only) ----
|
# ---- PROD DEPLOY (tag push only) ----
|
||||||
@@ -290,6 +293,9 @@ jobs:
|
|||||||
--set-string secrets.authSecret="${{ secrets.AUTH_SECRET_PROD }}" \
|
--set-string secrets.authSecret="${{ secrets.AUTH_SECRET_PROD }}" \
|
||||||
--set-string secrets.dbRootPassword="${{ secrets.DB_PASSWORD_PROD }}" \
|
--set-string secrets.dbRootPassword="${{ secrets.DB_PASSWORD_PROD }}" \
|
||||||
--set-string secrets.localAdminPassword="${{ secrets.LOCAL_ADMIN_PASSWORD_PROD }}" \
|
--set-string secrets.localAdminPassword="${{ secrets.LOCAL_ADMIN_PASSWORD_PROD }}" \
|
||||||
|
--set-string secrets.entraClientId="${{ secrets.ENTRA_CLIENT_ID_PROD }}" \
|
||||||
|
--set-string secrets.entraClientSecret="${{ secrets.ENTRA_CLIENT_SECRET_PROD }}" \
|
||||||
|
--set-string secrets.entraIssuer="${{ secrets.ENTRA_ISSUER_PROD }}" \
|
||||||
--wait --timeout 10m --atomic --debug
|
--wait --timeout 10m --atomic --debug
|
||||||
|
|
||||||
# Strictly redundant with immutable image tags: Helm already rolled the
|
# Strictly redundant with immutable image tags: Helm already rolled the
|
||||||
|
|||||||
@@ -50,13 +50,13 @@ spec:
|
|||||||
- secretRef:
|
- secretRef:
|
||||||
name: {{ include "it-cost-dashboard.fullname" . }}-server-secret
|
name: {{ include "it-cost-dashboard.fullname" . }}-server-secret
|
||||||
# Readiness hits a DB-backed route on purpose: a pod only takes
|
# Readiness hits a DB-backed route on purpose: a pod only takes
|
||||||
# traffic once MySQL is reachable AND the schema is right.
|
# traffic once MySQL is reachable. /api/health is allow-listed in
|
||||||
# NOTE (SSO restore): /api/years will 307 to /login once the
|
# src/auth.config.ts, so the middleware lets it through unauthenticated
|
||||||
# middleware is back on, which is non-2xx — add a public /api/health
|
# instead of 307-ing it to /login (which would be non-2xx and would
|
||||||
# route and probe that instead.
|
# keep the pod permanently unready).
|
||||||
readinessProbe:
|
readinessProbe:
|
||||||
httpGet:
|
httpGet:
|
||||||
path: /api/years
|
path: /api/health
|
||||||
port: http
|
port: http
|
||||||
initialDelaySeconds: 10
|
initialDelaySeconds: 10
|
||||||
periodSeconds: 5
|
periodSeconds: 5
|
||||||
|
|||||||
@@ -18,11 +18,13 @@ stringData:
|
|||||||
# Break-glass local login. Empty disables it entirely (src/auth.ts fails closed).
|
# Break-glass local login. Empty disables it entirely (src/auth.ts fails closed).
|
||||||
LOCAL_ADMIN_PASSWORD: {{ .Values.secrets.localAdminPassword | default "" | quote }}
|
LOCAL_ADMIN_PASSWORD: {{ .Values.secrets.localAdminPassword | default "" | quote }}
|
||||||
|
|
||||||
# --- SSO DISABLED FOR CICD TEST ---
|
# Microsoft Entra ID SSO. Required: a deploy fails loudly rather than shipping
|
||||||
# Kept present but optional. To restore SSO: supply these values from the
|
# a build whose sign-in button 500s.
|
||||||
# per-env GitHub secrets and swap `| default ""` for `| required "..."`.
|
AUTH_MICROSOFT_ENTRA_ID_ID: {{ required "secrets.entraClientId is required" .Values.secrets.entraClientId | quote }}
|
||||||
AUTH_MICROSOFT_ENTRA_ID_ID: {{ .Values.secrets.entraClientId | default "" | quote }}
|
AUTH_MICROSOFT_ENTRA_ID_SECRET: {{ required "secrets.entraClientSecret is required" .Values.secrets.entraClientSecret | quote }}
|
||||||
AUTH_MICROSOFT_ENTRA_ID_SECRET: {{ .Values.secrets.entraClientSecret | default "" | quote }}
|
AUTH_MICROSOFT_ENTRA_ID_ISSUER: {{ required "secrets.entraIssuer is required" .Values.secrets.entraIssuer | quote }}
|
||||||
AUTH_MICROSOFT_ENTRA_ID_ISSUER: {{ .Values.secrets.entraIssuer | default "" | quote }}
|
# Derived from the ingress host so the OAuth callback URL always matches what
|
||||||
AUTH_URL: {{ .Values.secrets.authUrl | default "" | quote }}
|
# is registered in Entra. AUTH_TRUST_HOST alone would leave Auth.js depending
|
||||||
# --- END SSO DISABLED ---
|
# on X-Forwarded-Proto; if that is ever wrong it builds an http:// callback and
|
||||||
|
# Entra rejects it with AADSTS50011 (http is invalid for non-localhost).
|
||||||
|
AUTH_URL: {{ printf "https://%s" (required "ingress.host is required" .Values.ingress.host) | quote }}
|
||||||
|
|||||||
@@ -31,4 +31,4 @@ ingress:
|
|||||||
enabled: true
|
enabled: true
|
||||||
className: nginx
|
className: nginx
|
||||||
# TODO: point this at a hostname resolving to the ingress-nginx external IP.
|
# TODO: point this at a hostname resolving to the ingress-nginx external IP.
|
||||||
host: it-cost-dashboard.trendmicro.com
|
host: it-cost-dashboard-prod.trendmicro.com
|
||||||
|
|||||||
+6
-6
@@ -50,12 +50,12 @@ secrets:
|
|||||||
dbRootPassword: "" # from GitHub secret DB_ROOT_PASSWORD_<ENV>
|
dbRootPassword: "" # from GitHub secret DB_ROOT_PASSWORD_<ENV>
|
||||||
# Optional; empty disables local login entirely (src/auth.ts fails closed).
|
# Optional; empty disables local login entirely (src/auth.ts fails closed).
|
||||||
localAdminPassword: ""
|
localAdminPassword: ""
|
||||||
# --- SSO restore: set these (and swap `default ""` for `required` in
|
# Microsoft Entra ID SSO. Supplied per-env by the CI workflow from GitHub
|
||||||
# templates/server-secret.yaml) when Entra ID is re-enabled ---
|
# secrets; server-secret.yaml marks them required, so a deploy fails loudly
|
||||||
# entraClientId: ""
|
# rather than shipping a build whose sign-in button 500s.
|
||||||
# entraClientSecret: ""
|
entraClientId: ""
|
||||||
# entraIssuer: ""
|
entraClientSecret: ""
|
||||||
# authUrl: ""
|
entraIssuer: ""
|
||||||
|
|
||||||
# Pre-created manually, once per namespace (see the deploy notes). Not templated:
|
# Pre-created manually, once per namespace (see the deploy notes). Not templated:
|
||||||
# the kubelet needs it independently of Helm.
|
# the kubelet needs it independently of Helm.
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { prisma } from "@/lib/prisma";
|
||||||
|
|
||||||
|
// Public readiness endpoint (allow-listed in src/auth.config.ts). DB-backed on
|
||||||
|
// purpose: a pod should only take traffic once MySQL is actually reachable,
|
||||||
|
// which is what the old /api/years probe gave us before auth was restored.
|
||||||
|
// force-dynamic keeps Prisma from being invoked during `next build`, which runs
|
||||||
|
// without a DATABASE_URL in the Dockerfile builder stage.
|
||||||
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
|
export async function GET() {
|
||||||
|
try {
|
||||||
|
await prisma.$queryRaw`SELECT 1`;
|
||||||
|
return NextResponse.json({ status: "ok" });
|
||||||
|
} catch {
|
||||||
|
return NextResponse.json({ status: "unavailable" }, { status: 503 });
|
||||||
|
}
|
||||||
|
}
|
||||||
+13
-21
@@ -2,9 +2,7 @@ import type { Metadata } from "next";
|
|||||||
import "./globals.css";
|
import "./globals.css";
|
||||||
import TopNav from "@/components/TopNav";
|
import TopNav from "@/components/TopNav";
|
||||||
import Sidebar from "@/components/Sidebar";
|
import Sidebar from "@/components/Sidebar";
|
||||||
// --- SSO DISABLED FOR CICD TEST ---
|
import { auth } from "@/auth";
|
||||||
// import { auth } from "@/auth";
|
|
||||||
// --- END SSO DISABLED ---
|
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
title: "Global IT Cost Dashboard",
|
title: "Global IT Cost Dashboard",
|
||||||
@@ -16,25 +14,19 @@ export default async function RootLayout({
|
|||||||
}: {
|
}: {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
}) {
|
}) {
|
||||||
// --- SSO DISABLED FOR CICD TEST ---
|
const session = await auth();
|
||||||
// const session = await auth();
|
|
||||||
//
|
|
||||||
// // Unauthenticated (e.g. the /login page) -> render a bare shell with no
|
|
||||||
// // sidebar/topnav so the sign-in screen shows on its own.
|
|
||||||
// if (!session?.user) {
|
|
||||||
// return (
|
|
||||||
// <html lang="en">
|
|
||||||
// <body>{children}</body>
|
|
||||||
// </html>
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// const isAdmin = session.user.role === "admin";
|
|
||||||
|
|
||||||
// Hardcoded so the sidebar/topnav still render — auth() would return null
|
// Unauthenticated (e.g. the /login page) -> render a bare shell with no
|
||||||
// with SSO off and the whole UI chrome would vanish.
|
// sidebar/topnav so the sign-in screen shows on its own.
|
||||||
const isAdmin = true;
|
if (!session?.user) {
|
||||||
// --- END SSO DISABLED ---
|
return (
|
||||||
|
<html lang="en">
|
||||||
|
<body>{children}</body>
|
||||||
|
</html>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const isAdmin = session.user.role === "admin";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|||||||
@@ -14,13 +14,11 @@ function errorMessage(code: string | undefined): string | null {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- SSO DISABLED FOR CICD TEST ---
|
|
||||||
// Server action: kick off the Microsoft SSO flow.
|
// Server action: kick off the Microsoft SSO flow.
|
||||||
// async function microsoftLogin() {
|
async function microsoftLogin() {
|
||||||
// "use server";
|
"use server";
|
||||||
// await signIn("microsoft-entra-id", { redirectTo: "/" });
|
await signIn("microsoft-entra-id", { redirectTo: "/" });
|
||||||
// }
|
}
|
||||||
// --- END SSO DISABLED ---
|
|
||||||
|
|
||||||
// Server action: local username/password login.
|
// Server action: local username/password login.
|
||||||
async function credentialsLogin(formData: FormData) {
|
async function credentialsLogin(formData: FormData) {
|
||||||
@@ -65,7 +63,6 @@ export default async function LoginPage({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* --- SSO DISABLED FOR CICD TEST ---
|
|
||||||
<form action={microsoftLogin} className="mt-6">
|
<form action={microsoftLogin} className="mt-6">
|
||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
@@ -80,7 +77,6 @@ export default async function LoginPage({
|
|||||||
OR
|
OR
|
||||||
<span className="h-px flex-1 bg-[#E5E7EB]" />
|
<span className="h-px flex-1 bg-[#E5E7EB]" />
|
||||||
</div>
|
</div>
|
||||||
--- END SSO DISABLED --- */}
|
|
||||||
|
|
||||||
<form action={credentialsLogin} className="mt-6 flex flex-col gap-3">
|
<form action={credentialsLogin} className="mt-6 flex flex-col gap-3">
|
||||||
<label className="flex flex-col gap-1 text-sm text-[#374151]">
|
<label className="flex flex-col gap-1 text-sm text-[#374151]">
|
||||||
|
|||||||
+2
-2
@@ -35,8 +35,8 @@ export const authConfig = {
|
|||||||
authorized({ auth, request }) {
|
authorized({ auth, request }) {
|
||||||
const { pathname } = request.nextUrl;
|
const { pathname } = request.nextUrl;
|
||||||
|
|
||||||
// Always let the sign-in page through, even when unauthenticated.
|
// Public: the sign-in page and the k8s readiness probe.
|
||||||
if (pathname === "/login") return true;
|
if (pathname === "/login" || pathname === "/api/health") return true;
|
||||||
|
|
||||||
// Not signed in -> Auth.js redirects to the sign-in page.
|
// Not signed in -> Auth.js redirects to the sign-in page.
|
||||||
if (!auth?.user) return false;
|
if (!auth?.user) return false;
|
||||||
|
|||||||
+24
-36
@@ -1,56 +1,44 @@
|
|||||||
// --- SSO DISABLED FOR CICD TEST ---
|
import { auth, signIn, signOut } from "@/auth";
|
||||||
// import { auth, signIn, signOut } from "@/auth";
|
|
||||||
// --- END SSO DISABLED ---
|
|
||||||
|
|
||||||
export default async function TopNav() {
|
export default async function TopNav() {
|
||||||
// --- SSO DISABLED FOR CICD TEST ---
|
const session = await auth();
|
||||||
// const session = await auth();
|
const user = session?.user;
|
||||||
// const user = session?.user;
|
|
||||||
const user = { name: "CI Test User" };
|
|
||||||
// --- END SSO DISABLED ---
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<header className="flex h-14 items-center justify-between bg-[#111827] px-6 text-white">
|
<header className="flex h-14 items-center justify-between bg-[#111827] px-6 text-white">
|
||||||
<span className="text-lg font-semibold">Global IT Cost Dashboard</span>
|
<span className="text-lg font-semibold">Global IT Cost Dashboard</span>
|
||||||
{/* --- SSO DISABLED FOR CICD TEST ---
|
{user ? (
|
||||||
Original: `{user ? (<logged-in block/>) : (<login form/>)}`. Both forms
|
<div className="flex items-center gap-3">
|
||||||
are server actions calling signOut/signIn, which would throw without
|
<span className="text-sm text-white/80">{user.name ?? user.email}</span>
|
||||||
the Entra env vars, so only the name is rendered below.
|
|
||||||
|
|
||||||
<div className="flex items-center gap-3">
|
|
||||||
<span className="text-sm text-white/80">{user.name ?? user.email}</span>
|
|
||||||
<form
|
|
||||||
action={async () => {
|
|
||||||
"use server";
|
|
||||||
await signOut({ redirectTo: "/" });
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<button
|
|
||||||
type="submit"
|
|
||||||
className="rounded-md bg-white/10 px-4 py-1.5 text-sm font-medium hover:bg-white/20"
|
|
||||||
>
|
|
||||||
Logout
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<form
|
<form
|
||||||
action={async () => {
|
action={async () => {
|
||||||
"use server";
|
"use server";
|
||||||
await signIn("microsoft-entra-id");
|
await signOut({ redirectTo: "/" });
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
className="rounded-md bg-white/10 px-4 py-1.5 text-sm font-medium hover:bg-white/20"
|
className="rounded-md bg-white/10 px-4 py-1.5 text-sm font-medium hover:bg-white/20"
|
||||||
>
|
>
|
||||||
Login
|
Logout
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
--- END SSO DISABLED --- */}
|
</div>
|
||||||
<div className="flex items-center gap-3">
|
) : (
|
||||||
<span className="text-sm text-white/80">{user.name}</span>
|
<form
|
||||||
</div>
|
action={async () => {
|
||||||
|
"use server";
|
||||||
|
await signIn("microsoft-entra-id");
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<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>
|
||||||
|
)}
|
||||||
</header>
|
</header>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-14
@@ -1,18 +1,10 @@
|
|||||||
// --- SSO DISABLED FOR CICD TEST ---
|
import NextAuth from "next-auth";
|
||||||
// Original: protect the whole app with role-aware auth in the edge runtime.
|
import { authConfig } from "@/auth.config";
|
||||||
// import NextAuth from "next-auth";
|
|
||||||
// import { authConfig } from "@/auth.config";
|
|
||||||
//
|
|
||||||
// export const { auth: middleware } = NextAuth(authConfig);
|
|
||||||
|
|
||||||
// No-op replacement. The EMPTY MATCHER below is the actual kill switch — this
|
// Edge-runtime gate for the whole app. Uses the edge-safe config only —
|
||||||
// function is never invoked, and every route (including the three admin pages)
|
// src/auth.ts pulls in node:fs via lookupRole and must never be imported here.
|
||||||
// is open.
|
export const { auth: middleware } = NextAuth(authConfig);
|
||||||
export function middleware() {}
|
|
||||||
|
|
||||||
export const config = {
|
export const config = {
|
||||||
// Original matcher (restore with the lines above):
|
matcher: ["/((?!api/auth|_next/static|_next/image|favicon.ico|.*\\.).*)"],
|
||||||
// matcher: ["/((?!api/auth|_next/static|_next/image|favicon.ico|.*\\.).*)"],
|
|
||||||
matcher: [],
|
|
||||||
};
|
};
|
||||||
// --- END SSO DISABLED ---
|
|
||||||
|
|||||||
Reference in New Issue
Block a user