Repository navigation
Description
Why
DupeZero staff need the operator console (tenants, impersonation, the audit log) without anyone hand-granting is_super_admin in the database. The owner's rule is that a dupezero.com Google Workspace account is a super admin.
Super admin is the most powerful role in the product, so the check has to rest on something Google asserts about the organization, not on what the address looks like.
What the user sees
- A staff member signs in with their @dupezero.com Google account and lands on
/admin. - A former staff member whose Workspace account was suspended or removed can't sign in. Any session they already had expires within 12 hours.
- Everyone else is unaffected.
How
-
The staff test. All three must hold:
- the ID token's
hdclaim equalsERWEB_STAFF_GOOGLE_DOMAIN(dupezero.com); - the email's domain equals the same value;
email_verifiedis true.
A Gmail account has no
hd, so it can never pass. An address that merely ends in@dupezero.comwithouthddoesn't pass either. - the ID token's
-
First sign-in (the router's step 2 in First-sign-in router: join an existing workspace vs found a new one #1400):
- Create the user with no password,
is_super_admin = trueandsuper_admin_source = google_domain. - Create the identity.
- Call
createSessionand land on/admin.
- Create the user with no password,
-
Every sign-in after that. Re-run the test in the callback.
- If the user has
super_admin_source = google_domainand no longer passes, setis_super_admin = falseand clear the source. They land wherever their memberships take them, or on "no workspace". - A
manualgrant is never changed by this rule. That covers[email protected]today.
- If the user has
-
Session lifetime. A session created through the staff path gets a 12-hour absolute expiry, with no sliding.
frontend/src/lib/auth/session.tscurrently gives every session a 30-day sliding expiry; add an absolute-expiry option and use it here.- This bounds how long a removed staff member keeps access, because Google won't tell us about offboarding.
-
Audit. Write
user.super_admin.grantedanduser.super_admin.revoked, withreason: google_domain. -
Copy.
/adminshows a small line: "Signed in as staff through dupezero.com Google Workspace".
Acceptance criteria
These are mock-IdP tests:
-
hd=dupezero.com, an @dupezero.com email and verified: super admin, landing on/admin. -
hdmissing (Gmail): not staff. They take the normal router path. -
hd=other.com: not staff. - An @dupezero.com email with no
hd: not staff. -
hd=dupezero.comwith an email on another domain: not staff. - A user granted through
google_domainwho then signs in withouthdloses/admin. It returns 404, the house rule. - A
manualsuper admin is never demoted by this rule. - A staff session is refused 12 hours after creation, even with activity in between. Use a fake clock in a unit test.
- Impersonation still works for a super admin granted by domain, and the impersonation banner still shows.
- Grant and revoke both appear in the audit log.
Out of scope
- Super admins on more than one domain.
- Dropping
[email protected], which keeps its password and its manual grant.
Depends on
#1398 (for super_admin_source), #1399 and #1400.
Where to start
frontend/src/lib/bff/admin.ts:requireSuperAdminat L11-18.frontend/src/lib/auth/session.tsL12-13, L71-76.frontend/src/app/(admin)/admin/layout.tsx.
Estimate: 0.5 engineer-weeks.
Part of the E31 epic (#1396) (linked as parent). Decisions recorded 2026-11-28 with the owner.
Activity