Let Google Workspace groups grant admin access

Site settings → Access names a group for each of admin, editor and
viewer (migration 047). Someone in one who signs in with Google gets a
Google-only account with their highest group's role, and the role
follows the groups: at every sign-in, hourly while signed in, and on
Panel → Google groups → Re-sync now. Out of every group, the account
is disabled and signed out until they're back in one.

Group accounts' roles are locked in the Panel; a superadmin's Disable
sticks. Superadmins and admin-cli accounts are never changed. If
Google can't be asked, sign-ins are refused but the hourly check
leaves accounts alone. Panel → Check their groups tests an email.

Lookups use the service account through the Directory API as
GOOGLE_DIRECTORY_AS. Setup: docs/google-sign-in.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-09-29 17:44:04 -05:00
parent d7835dd5d4
commit 80877a4659
13 changed files with 563 additions and 36 deletions

View file

@ -6,7 +6,14 @@ off until the service has an OAuth client ID and secret.
## Who gets in
Only accounts that already exist. Create them as before with
Two kinds of account can sign in with Google:
- **Group accounts**, when access groups are set up (below): anyone in
one of the site's Workspace groups. Their account is made at their
first sign-in, and their role follows the group.
- **Accounts made with admin-cli**, as before.
Created with
`admin-cli.js add <email>` (the password it asks for stays as a way in
if Google is ever unavailable). The first time that person signs in with
Google, their Google account is linked to the admin account with the
@ -14,12 +21,79 @@ same email; after that it matches by the link, even if the email later
changes. `admin-cli.js list` shows which accounts are linked.
Refused, with a message on the login page: no admin account for that
email, an email already linked to a different Google account, a
email (and in no access group), an email already linked to a different Google account, a
disabled account, any account outside the Workspace domain (checked by
Google's `hd` claim, not just the email), an unverified email.
Code: `server/src/googleAuth.js` (the Google side) and
`server/src/routes/auth.js` (matching and linking accounts).
Code: `server/src/googleAuth.js` (the Google side),
`server/src/routes/auth.js` (matching and linking accounts) and
`server/src/accessGroups.js` (access groups).
## Access groups
Panel → Site settings → **Access (Google groups)** names a Workspace
group for each of Admin, Editor and Viewer, eg.
`web-admins@nextgenerationofunity.org`. Any of them may be blank.
- **First sign-in:** someone in one of the groups signs in with Google
and gets an account with the highest role their groups give (in both
the editors and viewers groups: editor). No password: Google only.
Groups inside groups count.
- **The role follows the group**, checked at every sign-in, about once
an hour while they're signed in, and whenever a superadmin presses
Panel → Google groups → **Re-sync now**. Moved to another group: the
role changes. Out of every group: the account is disabled and signed
out; put back in one, it's turned on again at the next sign-in or
re-sync.
- **In the Panel**, a group account says "Google group" and its role
can't be changed there (change the membership instead). Disable still
works, and sticks: no group check turns back on an account a
superadmin disabled.
- **Not affected:** superadmins (there's no superadmin group) and
accounts made with admin-cli, which keep the role set in the Panel
whatever groups they're in.
- **If Google can't be asked** (an outage, a setup mistake), a sign-in
is refused ("Couldn't check your Google groups"), but the hourly
check leaves accounts as they are and tries again; nobody is signed
out because Google was down. Password and admin-cli accounts still
get in.
Panel → Google groups → **Check their groups** shows what role an email
would get, changing nothing: the quickest check of the setup.
### Setting it up
Group lookups use the service account from
`docs/google-drive-and-mail.md` (step 1 there), through the Admin SDK
Directory API:
1. Cloud Console, the service account's project → APIs & Services →
Library → enable the **Admin SDK API**.
2. Admin console → Security → Access and data control → API controls →
Manage domain wide delegation → the service account's entry → Edit.
Add the scope (comma separated, beside `gmail.send`):
`https://www.googleapis.com/auth/admin.directory.group.member.readonly`
3. Pick a Workspace **user** who can see the groups' members: a super
admin, or an admin with a role that includes Groups → Read. The
lookups are made as them. Set it on the service:
```ini
Environment=GOOGLE_DIRECTORY_AS=<that user, eg. it-admin@nextgenerationofunity.org>
```
4. Make the groups in Google Admin (or Groups), add people, and put the
addresses in Site settings → Access. Restart `ngu-api` after the
`systemctl edit`.
`GOOGLE_SERVICE_ACCOUNT` and `GOOGLE_DIRECTORY_AS` without any groups
set changes nothing; groups set without them show a warning in the
Panel and Google sign-in works as before.
Errors in the Panel or journal (`grep access`): `groupKey` means a group
address in Site settings isn't a group Google knows; `unauthorized_client`
means the delegation or scope (step 2) is missing, or
`GOOGLE_DIRECTORY_AS` isn't a user; `Not Authorized to access this
resource` means that user can't read the group.
## Setting up the OAuth client