Update hivegrid-cloud reference to latest main
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e98d38e716
commit
7b21524c86
3781 files changed
+373484
-225607
No files matched your search
+3
-3
@@ -3,10 +3,10 @@
|
||||
*
|
||||
* Centralises action names + metadata sanitization for the login / logout
|
||||
* / fallback / mfa-challenge paths. Sits on top of
|
||||
* `@toolctrl/db/audit-events.server` which already handles redaction.
|
||||
* `@hivegrid/db/audit-events.server` which already handles redaction.
|
||||
*/
|
||||
import { createAuditEvent } from "@toolctrl/db/audit-events.server";
|
||||
import type { Prisma } from "@toolctrl/db/prisma-browser";
|
||||
import { createAuditEvent } from "@hivegrid/db/audit-events.server";
|
||||
import type { Prisma } from "@hivegrid/db/prisma-browser";
|
||||
|
||||
export type AdminSsoAuditAction =
|
||||
| "admin.login.sso.success"
|
||||
|
||||
+13
-13
@@ -2,16 +2,16 @@ import { describe, expect, it } from "vitest";
|
||||
import { extractAdminSsoClaims, hasAllowedAdminGroup, isAllowedAdminGroup, mapGroupsToRole } from "./claims.server";
|
||||
|
||||
describe("mapGroupsToRole", () => {
|
||||
it("maps toolctrl-admin to super_admin", () => {
|
||||
expect(mapGroupsToRole(["toolctrl-admin"])).toBe("super_admin");
|
||||
it("maps hivegrid-admin to super_admin", () => {
|
||||
expect(mapGroupsToRole(["hivegrid-admin"])).toBe("super_admin");
|
||||
});
|
||||
|
||||
it("maps toolctrl-staff to staff", () => {
|
||||
expect(mapGroupsToRole(["toolctrl-staff"])).toBe("staff");
|
||||
it("maps hivegrid-staff to staff", () => {
|
||||
expect(mapGroupsToRole(["hivegrid-staff"])).toBe("staff");
|
||||
});
|
||||
|
||||
it("prefers super_admin when both groups are present", () => {
|
||||
expect(mapGroupsToRole(["toolctrl-staff", "toolctrl-admin"])).toBe("super_admin");
|
||||
expect(mapGroupsToRole(["hivegrid-staff", "hivegrid-admin"])).toBe("super_admin");
|
||||
});
|
||||
|
||||
it("returns null for an unknown group", () => {
|
||||
@@ -30,9 +30,9 @@ describe("mapGroupsToRole", () => {
|
||||
|
||||
describe("isAllowedAdminGroup / hasAllowedAdminGroup", () => {
|
||||
it("recognizes the two allowlisted groups", () => {
|
||||
expect(isAllowedAdminGroup("toolctrl-admin")).toBe(true);
|
||||
expect(isAllowedAdminGroup("toolctrl-staff")).toBe(true);
|
||||
expect(isAllowedAdminGroup("toolctrl-rando")).toBe(false);
|
||||
expect(isAllowedAdminGroup("hivegrid-admin")).toBe(true);
|
||||
expect(isAllowedAdminGroup("hivegrid-staff")).toBe(true);
|
||||
expect(isAllowedAdminGroup("hivegrid-rando")).toBe(false);
|
||||
});
|
||||
|
||||
it("returns false when claim list has no allowed group", () => {
|
||||
@@ -42,7 +42,7 @@ describe("isAllowedAdminGroup / hasAllowedAdminGroup", () => {
|
||||
});
|
||||
|
||||
it("returns true when at least one allowed group is present", () => {
|
||||
expect(hasAllowedAdminGroup(["other", "toolctrl-staff"])).toBe(true);
|
||||
expect(hasAllowedAdminGroup(["other", "hivegrid-staff"])).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -52,7 +52,7 @@ describe("extractAdminSsoClaims", () => {
|
||||
email: "Admin@Example.test",
|
||||
email_verified: true,
|
||||
name: "Admin Person",
|
||||
groups: ["toolctrl-admin"],
|
||||
groups: ["hivegrid-admin"],
|
||||
};
|
||||
|
||||
it("extracts and normalizes a valid claim set", () => {
|
||||
@@ -62,7 +62,7 @@ describe("extractAdminSsoClaims", () => {
|
||||
expect(result.claims.subject).toBe("auth-uid-123");
|
||||
expect(result.claims.email).toBe("admin@example.test");
|
||||
expect(result.claims.name).toBe("Admin Person");
|
||||
expect(result.claims.groups).toEqual(["toolctrl-admin"]);
|
||||
expect(result.claims.groups).toEqual(["hivegrid-admin"]);
|
||||
expect(result.claims.emailVerified).toBe(true);
|
||||
}
|
||||
});
|
||||
@@ -105,9 +105,9 @@ describe("extractAdminSsoClaims", () => {
|
||||
});
|
||||
|
||||
it("filters non-string entries from groups", () => {
|
||||
const result = extractAdminSsoClaims({ ...validClaims, groups: ["toolctrl-admin", null, 7, "ok"] });
|
||||
const result = extractAdminSsoClaims({ ...validClaims, groups: ["hivegrid-admin", null, 7, "ok"] });
|
||||
expect(result.ok).toBe(true);
|
||||
if (result.ok) expect(result.claims.groups).toEqual(["toolctrl-admin", "ok"]);
|
||||
if (result.ok) expect(result.claims.groups).toEqual(["hivegrid-admin", "ok"]);
|
||||
});
|
||||
|
||||
it("returns missing-sub for null claims", () => {
|
||||
|
||||
+4
-4
@@ -2,18 +2,18 @@
|
||||
* Phase 09 Task #82 — OIDC ID-token claim extraction + group→role mapping.
|
||||
*
|
||||
* The "role" returned here is the *current* AdminUser identity layer in the
|
||||
* Toolctrl boilerplate. Today the only durable AdminUser concept is "exists
|
||||
* HiveGrid boilerplate. Today the only durable AdminUser concept is "exists
|
||||
* or not"; the spec adds two granular roles (`super_admin`, `staff`) that
|
||||
* we persist as `ssoGroups` snapshots while we wait for the permissions
|
||||
* matrix to grow first-class role columns. Callers should treat the role
|
||||
* as advisory + future-proof.
|
||||
*/
|
||||
|
||||
export type AuthentikGroup = "toolctrl-admin" | "toolctrl-staff";
|
||||
export type AuthentikGroup = "hivegrid-admin" | "hivegrid-staff";
|
||||
export type AdminSsoRole = "super_admin" | "staff";
|
||||
|
||||
export const ADMIN_GROUP: AuthentikGroup = "toolctrl-admin";
|
||||
export const STAFF_GROUP: AuthentikGroup = "toolctrl-staff";
|
||||
export const ADMIN_GROUP: AuthentikGroup = "hivegrid-admin";
|
||||
export const STAFF_GROUP: AuthentikGroup = "hivegrid-staff";
|
||||
|
||||
export const ALLOWED_ADMIN_GROUPS: readonly AuthentikGroup[] = [ADMIN_GROUP, STAFF_GROUP];
|
||||
|
||||
|
||||
+5
-5
@@ -3,17 +3,17 @@ import { AdminSsoConfigError, isAdminSsoConfigured, readAdminSsoEnv } from "./cl
|
||||
|
||||
describe("readAdminSsoEnv", () => {
|
||||
const baseEnv = {
|
||||
AUTHENTIK_ISSUER_URL: "https://auth.example.test/application/o/toolctrl-admin-panel/",
|
||||
AUTHENTIK_ADMIN_CLIENT_ID: "toolctrl-admin-panel",
|
||||
AUTHENTIK_ISSUER_URL: "https://auth.example.test/application/o/hivegrid-admin-panel/",
|
||||
AUTHENTIK_ADMIN_CLIENT_ID: "hivegrid-admin-panel",
|
||||
AUTHENTIK_ADMIN_CLIENT_SECRET: "shh",
|
||||
AUTHENTIK_ADMIN_REDIRECT_URI: "https://admin.example.test/auth/admin/callback",
|
||||
};
|
||||
|
||||
it("returns trimmed values when all required keys are present", () => {
|
||||
const env = readAdminSsoEnv({ ...baseEnv, AUTHENTIK_ADMIN_POST_LOGOUT_REDIRECT_URI: "https://admin.example.test/admin/login?logged_out=1" });
|
||||
const env = readAdminSsoEnv({ ...baseEnv, AUTHENTIK_ADMIN_POST_LOGOUT_REDIRECT_URI: "https://admin.example.test/login?logged_out=1" });
|
||||
expect(env.issuerUrl).toBe(baseEnv.AUTHENTIK_ISSUER_URL);
|
||||
expect(env.clientId).toBe("toolctrl-admin-panel");
|
||||
expect(env.postLogoutRedirectUri).toBe("https://admin.example.test/admin/login?logged_out=1");
|
||||
expect(env.clientId).toBe("hivegrid-admin-panel");
|
||||
expect(env.postLogoutRedirectUri).toBe("https://admin.example.test/login?logged_out=1");
|
||||
});
|
||||
|
||||
it("throws when a required key is missing", () => {
|
||||
|
||||
+7
-7
@@ -99,7 +99,7 @@ function buildClaims(overrides: Partial<AdminSsoClaims> = {}): AdminSsoClaims {
|
||||
email: "admin@example.test",
|
||||
emailVerified: true,
|
||||
name: "Admin Person",
|
||||
groups: ["toolctrl-admin"],
|
||||
groups: ["hivegrid-admin"],
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
@@ -111,7 +111,7 @@ describe("jitProvisionAdmin", () => {
|
||||
env = buildFakeDb();
|
||||
});
|
||||
|
||||
it("creates User+AdminUser for a brand new toolctrl-admin claim and returns super_admin", async () => {
|
||||
it("creates User+AdminUser for a brand new hivegrid-admin claim and returns super_admin", async () => {
|
||||
const result = await jitProvisionAdmin({ claims: buildClaims() }, env.db);
|
||||
expect(result.ok).toBe(true);
|
||||
if (result.ok) {
|
||||
@@ -124,11 +124,11 @@ describe("jitProvisionAdmin", () => {
|
||||
const admin = [...env.adminRows.values()][0]!;
|
||||
expect(admin.ssoProvider).toBe(ADMIN_SSO_PROVIDER);
|
||||
expect(admin.ssoSubjectId).toBe("authentik-sub-1");
|
||||
expect(admin.ssoGroups).toEqual(["toolctrl-admin"]);
|
||||
expect(admin.ssoGroups).toEqual(["hivegrid-admin"]);
|
||||
});
|
||||
|
||||
it("maps toolctrl-staff to staff role", async () => {
|
||||
const result = await jitProvisionAdmin({ claims: buildClaims({ groups: ["toolctrl-staff"] }) }, env.db);
|
||||
it("maps hivegrid-staff to staff role", async () => {
|
||||
const result = await jitProvisionAdmin({ claims: buildClaims({ groups: ["hivegrid-staff"] }) }, env.db);
|
||||
expect(result.ok).toBe(true);
|
||||
if (result.ok) expect(result.admin.role).toBe("staff");
|
||||
});
|
||||
@@ -156,7 +156,7 @@ describe("jitProvisionAdmin", () => {
|
||||
// Second login with same sub but new groups + later timestamp.
|
||||
const t1 = new Date("2026-02-01T00:00:00Z");
|
||||
const result = await jitProvisionAdmin(
|
||||
{ claims: buildClaims({ groups: ["toolctrl-staff"] }), now: t1 },
|
||||
{ claims: buildClaims({ groups: ["hivegrid-staff"] }), now: t1 },
|
||||
env.db,
|
||||
);
|
||||
expect(result.ok).toBe(true);
|
||||
@@ -166,7 +166,7 @@ describe("jitProvisionAdmin", () => {
|
||||
expect(result.admin.role).toBe("staff");
|
||||
}
|
||||
const refreshed = [...env.adminRows.values()][0]!;
|
||||
expect(refreshed.ssoGroups).toEqual(["toolctrl-staff"]);
|
||||
expect(refreshed.ssoGroups).toEqual(["hivegrid-staff"]);
|
||||
expect(refreshed.lastSsoLoginAt).toEqual(t1);
|
||||
// No new user row.
|
||||
expect(env.userRows.size).toBe(1);
|
||||
|
||||
+2
-2
@@ -7,9 +7,9 @@
|
||||
* session cookie or persisting tokens in the DB.
|
||||
*/
|
||||
import { createHmac, timingSafeEqual } from "node:crypto";
|
||||
import { loadRequiredWebConfig } from "@toolctrl/config";
|
||||
import { loadRequiredWebConfig } from "@hivegrid/config";
|
||||
|
||||
export const ADMIN_SSO_ID_TOKEN_COOKIE = "admin_sso_id_token";
|
||||
export const ADMIN_SSO_ID_TOKEN_COOKIE = "hivegrid_admin_sso_id_token";
|
||||
export const ADMIN_SSO_ID_TOKEN_TTL_MS = 12 * 60 * 60 * 1000; // mirror app-session lifetime
|
||||
const COOKIE_PATH = "/auth/admin";
|
||||
|
||||
|
||||
+2
-2
@@ -17,10 +17,10 @@
|
||||
* server-side (cookie Max-Age is best-effort; clients lie).
|
||||
*/
|
||||
import { createHmac, randomBytes, timingSafeEqual } from "node:crypto";
|
||||
import { loadRequiredWebConfig } from "@toolctrl/config";
|
||||
import { loadRequiredWebConfig } from "@hivegrid/config";
|
||||
import { generators } from "openid-client";
|
||||
|
||||
export const ADMIN_SSO_CHALLENGE_COOKIE = "admin_sso_challenge";
|
||||
export const ADMIN_SSO_CHALLENGE_COOKIE = "hivegrid_admin_sso_challenge";
|
||||
export const ADMIN_SSO_CHALLENGE_TTL_MS = 10 * 60 * 1000;
|
||||
const COOKIE_PATH = "/auth/admin";
|
||||
const PAYLOAD_VERSION = "v1";
|
||||
|
||||
Reference in new issue
Block a user