Users & roles¶
Roles¶
Three roles are built in and created at startup:
| Role | Content | Publish | Media library | Admin area (/admin/*: content model, agents, users, tokens, settings) |
|---|---|---|---|---|
admin |
read, create, update, delete | ✓ | ✓ | ✓ |
editor |
read, create, update, delete | ✓ | ✓ | |
viewer |
read (published content) |
You can add custom roles with permissions per content type: for example, a writer who drafts articles but can't publish, a reviewer who publishes but doesn't edit, or a team that only sees its own collections. The REST API and GraphQL enforce the same rules.
Custom roles¶
A role's permissions list actions by content type:
{
"name": "writer",
"description": "Drafts articles and news; publishing is left to editors",
"permissions": {
"content": {
"articles": ["create", "update"],
"news": ["create", "update", "delete"],
"singleton:homepage": ["read"],
"*": ["read"]
},
"media": ["read", "create"]
}
}
| Key | Means | Actions |
|---|---|---|
| a collection name | items of that collection | read, create, update, delete, publish |
singleton:<name> |
a singleton's content | read, update |
* |
every type not listed | as above |
media |
the media library | read (browse), create (upload), update, delete |
- Unlisted types: a type that isn't listed uses
*. If*isn't listed either, the role can't reach that type: it gets403, and the type doesn't appear in/api/schema/*. - Read is implied: any other action includes
read, and the server adds it. - Drafts are visible to roles that can
updateorpublishthe type, both directly and throughstatus=all. Other roles see published content only. - Publishing:
publishcoversPOST …/publishand…/unpublish, and"status"in a create or update body. In draft-and-publish collections it is also needed to change an item that is published, because that changes live content. Withoutpublish, a role writes and edits drafts only, which suits a writer whose work is reviewed before going live. It can still delete published items if it hasdelete. - No review step without draft and publish: in collections without draft and publish, every item is live, so
createandupdatepublish directly. - History: reading history and restoring versions need
updateon the type. Restoring also needscreatewhen it brings back a deleted item, andpublishwhen the item is published or would come back published. The change feed lists only the types the role can update. - Related entries of a type the role can't read are left out of populated relations: they're returned as
null, or dropped from lists, including bare IDs atlevel=0. Drafts of a related type are only shown to roles that can see drafts of that type. - Linking by ID: relation and media values are IDs. A role that can write a type can link any existing item or file by ID, so a missing ID is reported in the validation error. The linked content stays hidden when the role can't read it, except media, which is shown with the content that uses it. Keep content that must stay private out of reach of roles that can write the types linking to it.
- Reserved for admins: the admin area stays admin-only, for every custom role. That covers the content model, agents (and reverting their runs), users, tokens, webhooks, locales and roles.
Manage roles as an admin, from a user session, or in the admin UI under Settings → Roles:
| Method | Path | Body |
|---|---|---|
GET |
/admin/roles |
|
GET |
/admin/roles/{name} |
|
POST |
/admin/roles |
name (2–32 lowercase letters, digits, -, _), description, permissions |
PUT |
/admin/roles/{name} |
description, permissions (replaced; the name can't change) |
DELETE |
/admin/roles/{name} |
409 while users or active API tokens still use the role |
Built-in roles can't be changed or deleted. Assign a custom role like any other: role_name for users, role for API tokens. That makes it easy to give a front-end a token limited to the collections it displays. A permission change, or giving a user another role, applies to existing sessions and tokens within a few seconds, with no new login needed.
GET /auth/me returns the caller's permissions in this format. The built-in roles are expanded into it, so a client can show or hide actions.
Public access¶
Requests without a token act with the public role. It grants nothing at first, so
anonymous requests get 401. Grant it read on the types your website or app shows, and
browsers, mobile apps and static site builds can read them without a token:
curl -X PUT $GOHEAD/admin/roles/public -H "$JSON" -H "$AUTH" -d '{
"description": "Website visitors",
"permissions": {
"content": { "articles": ["read"], "categories": ["read"], "singleton:homepage": ["read"] }
}
}'
curl $GOHEAD/api/collections/articles # no Authorization header
In the admin UI: Settings → Roles → Public. In a content model file,
the public key sets it.
- Read only, published only. The role only holds
read, type by type; visitors never see drafts, history or proposals, and never write. - Listed types only.
*is refused, so a type created later stays private until you add it. Types withpasswordattributes (or components that have one) can't be public; a type that gains one is closed again. - Files used by public content are returned with it (their URLs are public anyway).
Browsing the media library (
/api/media) is not available to visitors. - What stays private: related entries of types the role can't read are left out, as for
any role. The content model (
/api/schema/*,/api/openapi.jsonunlessopenapi.publicis on), GraphQL introspection and the admin area need a token. A missing type and a type that isn't public answer the same401, so visitors can't list your types. - Limits: relations are populated at most 2 levels deep (
levelis capped). GraphQL queries are limited to 4 levels and 200 fields, mutations need a token, and error messages don't name types. Anonymous requests are rate limited per client IP (rate_limit.public_per_minute, 600 a minute). Behind a load balancer or CDN, settrusted_proxiesso each visitor is counted separately, and give static site builds an API token, which is not limited this way. - A request that sends a token always acts as that token, even with public access on, and
a forbidden anonymous request gets
401, so a client knows a token may help. - The
publicrole can't be deleted or given to users and API tokens. A custom role namedpublicfrom an earlier version is renamedpublic-legacywhen upgrading, with its users and tokens.
Anything granted here is readable by anyone on the internet. For content that only your own servers should read, keep public access off and use an API token.
Registration and the first admin¶
The first administrator never comes from the public API. Create it either way:
- Configuration: set
admin.username,admin.emailandadmin.password(GOHEAD_ADMIN_USERNAME,GOHEAD_ADMIN_EMAIL,GOHEAD_ADMIN_PASSWORD). The API creates that account at startup when the database has no users, and ignores the settings afterwards, so they can stay in place (or be removed). -
Command line, at any time:
Administrator passwords need at least 12 characters.
Other accounts are created by an admin (POST /admin/users, or the admin UI). Public
self-registration is controlled by auth.registration (GOHEAD_AUTH_REGISTRATION):
| Value | POST /auth/register |
|---|---|
disabled (default) |
403 |
open |
creates a viewer account; the caller cannot choose a role |
curl -X POST $GOHEAD/auth/register -H "$JSON" \
-d '{"username":"alice","email":"alice@example.com","password":"at-least-6-chars"}'
Logging in¶
curl -X POST $GOHEAD/auth/login -H "$JSON" -d '{"username":"alice","password":"at-least-6-chars"}'
# {"data":{"token":"eyJhbGciOiJIUzI1NiIs..."}}
Send the token as Authorization: Bearer <token>. Tokens are HS256 JWTs that expire after
72 hours (for front-ends and CI, use a long-lived API token); they are signed with jwt_secret.
Changing the secret invalidates every token.
A wrong username or password returns 401 with the same message either way. After 5 failed
attempts for a username from one IP, that IP gets 429 with a Retry-After header for 15
minutes; a successful login clears the count. Limits are
configurable.
Sign in with Google¶
People can sign in with their Google account, next to (not instead of) passwords: the login page shows Sign in with Google.
- Linking it yourself: anyone signed in with a password links their Google account from the account menu (Sign in with Google too), as long as the Google address is the account's email. Administrators link their account this way: it is never linked automatically.
- Automatic link: another existing account is linked on its first Google sign-in when its
email is the Google account's address and Google vouches for it, meaning a Google Workspace
account of that domain or a Gmail address. A personal Google account created with someone's
work address proves nothing, so it is refused. The account keeps its role. With
auth.registration: open, nothing is linked automatically: anyone could have registered an account with that email. - New accounts: with
allowed_domains, people of your Google Workspace domain (yourstudio.com) get an account on their first sign-in, withdefault_role(viewerunless set, neveradmin: promote people under Settings → Users). Google must vouch for the domain: a personal account whose address happens to match is not enough. - Anyone else is told to ask an administrator for an account.
Accounts created this way have no password: they sign in with Google, and an admin can set
one. Settings → Users marks linked accounts with google; an admin unlinks one with
DELETE /admin/users/{id}/sso, after which it signs in with its password.
Set it up¶
- In the Google Cloud console, open APIs & Services → OAuth consent screen (or Google Auth Platform) and configure it: Internal if only your Workspace domain signs in, External otherwise.
- Under Credentials → Create credentials → OAuth client ID, choose Web application and
add the Authorized redirect URI
https://cms.example.com/auth/sso/google/callback(GoHead's address, with/auth/sso/google/callback). -
Give GoHead the client:
GOHEAD_AUTH_SSO_GOOGLE_CLIENT_ID=1234-abcd.apps.googleusercontent.com GOHEAD_AUTH_SSO_GOOGLE_CLIENT_SECRET=GOCSPX-… GOHEAD_AUTH_SSO_GOOGLE_ALLOWED_DOMAINS=yourstudio.com # optional, comma-separated GOHEAD_AUTH_SSO_GOOGLE_DEFAULT_ROLE=editor # optional, default viewer GOHEAD_AUTH_SSO_PUBLIC_URL=https://cms.example.com # recommended in production -
Restart GoHead. The login page now offers Sign in with Google.
When the admin UI runs on another address than the API (the gohead-admin image), set
GOHEAD_AUTH_SSO_UI_URL to it: GoHead sends people back there after signing in.
How it works¶
The sign-in uses OpenID Connect's authorization code flow with PKCE. The login page keeps a random value
for this sign-in in the browser's session storage and calls GET /auth/sso/google/start, which
stores a signed, short-lived state (with that value) in an HttpOnly cookie and sends the
browser to Google; Google sends it back to /auth/sso/google/callback, which checks the state,
exchanges the code for the ID token directly with Google, checks its issuer, audience, expiry
and nonce, and finds or creates the account. The browser then lands on the admin UI's login
page with a GoHead token in the URL fragment (#sso_token=…), which the UI keeps and removes
from the address bar; fragments are never sent to servers. The UI accepts the token only with
the value it kept, so a crafted link cannot sign someone into another account. GET /auth/sso
lists the enabled providers; /auth/sso/google/start and /callback count toward the
authentication rate limit.
Managing users (admin)¶
| Method | Path | Body |
|---|---|---|
GET |
/admin/users |
|
GET |
/admin/users/{id} |
|
POST |
/admin/users |
username, email, password, optional role_name (default viewer) |
PUT |
/admin/users/{id} |
any of username, email, password, role_name |
DELETE |
/admin/users/{id} |
# invite an editor
curl -X POST $GOHEAD/admin/users -H "$JSON" -H "$AUTH" \
-d '{"username":"bob","email":"bob@example.com","password":"temporary-pass","role_name":"editor"}'
# promote alice
curl -X PUT $GOHEAD/admin/users/2 -H "$JSON" -H "$AUTH" -d '{"role_name":"editor"}'
Rules:
- passwords are hashed with bcrypt and never returned;
PUTrejects any field not listed above;- duplicate usernames or emails return
409; - an admin cannot delete their own account.
Role changes apply at the user's next login (the role is embedded in the token).