Memberships
A site’s groups are named in its content (qualifies on a page,
requires_group on a list, invite: { group } on a desk, grants on
a state). Who is in each group is kept in one of three places,
chosen by PEOPLE_BACKEND; the content and the policy are the same
whichever it is.
PEOPLE_BACKEND | who is in a group is kept | accounts are made by | choose it when |
|---|---|---|---|
memberships | in portal, as records in portal_memberships | the sign-in provider (Vipps Login, any OpenID provider), or a Kanidm or Rauthy beside it | people already have a way to sign in |
kanidm | in Kanidm’s groups | Kanidm, on portal’s invite | the site has a Kanidm of its own (Bringing your people in) |
rauthy | in Rauthy’s groups | Rauthy, on portal’s invite | you want sign-in pages in Norwegian and an admin to see the groups (below) |
This page is mostly about the first: groups kept by portal itself.
A person’s memberships count exactly as a groups claim from the
provider would.
A membership is a case
One record per group and person:
| state | means | how it gets there |
|---|---|---|
invited | a place is held for them | a desk invite, a state that grants, the first person, someone the content names as responsible |
active | they are in | they signed in, and the provider’s subject, phone number or address matched the record |
removed | a desk took them out | a button on the desk that lists the bucket; inviting them again reopens the record |
The record carries name, group, by (who or what put them there:
a username, seed, responsible, or the case as bucket:id), and
what is known of the person: phone, email, sub. At sign-in
everything the provider verified is written onto every record that
matched, so a record made from an address learns the phone number,
and the next sign-in matches on the subject before anything else.
Because it is a case, a desk lists it like any other bucket:
resource:
source: { bucket: portal_memberships }
requires_group: board
transitions:
- { from: invited, to: removed, label: Withdraw }
- { from: active, to: removed, label: Take out }
- { from: removed, to: invited, label: Invite again }
A person is their phone number first
A provider that verifies phone numbers (Vipps) makes the number the
surest thing a record can hold. So a person is known by, in order:
their phone number, their email address, the provider’s subject. A
form that collects phone, telefon, tel or mobil gives the
first; email or epost the second. Numbers are kept as +4791234567
whatever way they were typed; a bare national number gets the site’s
country (PHONE_COUNTRY, +47 unless set). Addresses are lowercased.
At sign-in a record matches a person on any one of the three, so a desk that invited by address and a decision that granted by number are talking about one person, and there is one record.
An address counts only if the provider stands behind it: one it says
it has not verified (email_verified: false) is left out of the
session, so it matches no record and makes nobody responsible for a
page.
A number is only sure when the sign-in proves it (a provider giving
phone_number). What someone types on a form proves nothing, and two
people may share a phone. So a grant that gives a number another record
in the group holds, with an address of its own, is another person: they
get a record of their own by that address. The number stays with the
record that had it, and theirs keeps it as phone_given, or a sign-in
with the number would be taken for them. Given with no address, or
matching a record with none, the number finds that record, and an
address given then is written on it.
Switching a site to memberships
PEOPLE_BACKEND=memberships
Unset, a KANIDM_API_TOKEN means Kanidm and no token means
memberships. With memberships:
- A desk invite writes an
invitedrecord and mails “log in at the site, and your place is there”. The provider makes people, portal makes members: with Vipps Login everyone can already sign in. A Kanidm still configured beside memberships (KANIDM_API_TOKEN) makes the account too (or Rauthy, see below), with no group and the one-time link in the mail, so a site can switch to memberships before its provider does. Someone whose account has nothing to sign in with yet missed their link, and gets a new one, in the mail and nowhere else; someone who can sign in only hears of the place.Invite againon a removed record sends the same. - An invite with no group (
invite: {}) writes nothing here: a membership is a place in a group. The account is all it asks for, so only a Kanidm beside memberships can meet it, with the account and the one-time link, tracked inportal_invites. With no Kanidm there is nothing it could mean: the provider makes people, and anyone who can sign in already can.iris checkrefuses it, when it can tell:PEOPLE_BACKEND=membershipswhere it runs with no Kanidm configured there, or, with the variable unset, a desk listingportal_memberships. (A site with a Kanidm beside its memberships lints withPEOPLE_BACKEND=kanidm.) The content does not otherwise say where people are kept, so should one get through, the site says so in its log at start, and the desk refuses the form. grantswrites a record for the person the case is about, from the form’s name and phone number or address, and goes the way a desk invite does: a Kanidm beside memberships makes the account too, with the one-time link in the mail. On a site with sign-in off (neitherOIDC_ISSUERnorKANIDM_URL) and no Kanidm to make an account, there is nothing for the person to do with an invite, so none goes to them: the site’s inbox (mail.reply_to, elsemail.from) gets a line saying who now has a place in which group, to tell them if they should know. A mail the content wrote for the invite (invite.mail, or site.yaml’smail.invite) that needs no link, naming none of{link},{username}and{expires}, still goes to the person.SEED_ADMIN_PHONEorSEED_ADMIN_EMAILwrites the first person’s.- The people the content names as responsible get theirs in
RESPONSIBLE_GROUP, and lose it when the content stops naming them. - The
groupsclaim, if the provider sends one, still counts: a person’s groups are the union.
Rauthy
Rauthy writes its sign-in pages,
its admin and its mail in Norwegian (nb) among a dozen languages,
which Kanidm does not. A site signs in through it and keeps its groups
in portal:
OIDC_ISSUER=https://id.example.no/auth/v1/
OAUTH2_CLIENT_ID=<the client made in Rauthy>
OAUTH2_CLIENT_SECRET=<its secret>
PEOPLE_BACKEND=memberships
RAUTHY_URL=https://id.example.no
RAUTHY_API_KEY=<name>$<secret>
RAUTHY_LANGUAGE=nb
The client wants the authorization_code flow, S256, the scopes
openid profile email (and groups with OIDC_EXTRA_SCOPES=groups,
if Rauthy should assert groups of its own), and
<PUBLIC_URL>/auth/callback as its redirect. The API key is one made in
Rauthy’s admin with read and create on users, nothing more.
With the key, Rauthy stands where a Kanidm beside memberships stands:
an invite, grants, the first person and the people the content names
as responsible get an account if they have none, by their address, in
no group. Rauthy, not portal, then mails them how to set a password,
in RAUTHY_LANGUAGE; portal’s own invite mail has no link in it and
says where to sign in. Portal cannot ask Rauthy for a new link (its
reset wants a proof of work from a browser), so Invite again mails
the place and the way to the sign-in page, where “Forgot password”
sends one. An invite counts as taken when Rauthy shows the account has
something to sign in with, or when the person signs in.
Groups in Rauthy
PEOPLE_BACKEND=rauthy moves the groups there too, as kanidm does
for Kanidm: Rauthy is where they are, with its admin to see and change
them, and portal still decides what each may do. The content does not
change: an invite, grants, revokes, the first person and the people
named as responsible put a person in a group in Rauthy (made if it is
not there), a removal from a desk takes them out, and the invite is a
case of its own in portal_invites, waiting for them to come.
- Sign-in asks for the
groupsscope, so the token carries them. - The chat’s question and a desk’s member list read Rauthy at the time they are asked, so a removal there counts at once for the chat; on the site, at the next sign-in, as with every backend.
- The key wants read, create and update on users and read and create on
groups, and, where records have groups of their own, read, create and
update on roles (a group that manages others comes with
rauthy_admin:<bucket>_<key>_..., see state machines). A group’s name in Rauthy is lowercase letters, digits and-_/,:*, 2 to 64: a name it would refuse is refused before any call. - Rauthy takes a person’s groups as one list, so two desks changing one person’s groups at the same moment could lose one change.
Without the key, Rauthy is a provider like any other: people register there themselves if it lets them, and an invite is the place in the group, waiting for them.
With OIDC_EXTRA_SCOPES=phoneNumber the sign-in asks the provider for
the number and reads phone_number from userinfo. Set it for Vipps;
not for Kanidm, which denies a sign-in that asks for a scope the
person does not hold. Without it, matching falls back to the address.
Asking who belongs
Other applications ask portal the same access question they always
could, over dhd/1 (May). A principal that names
a person and lists no groups is looked up. groups must be there, if
empty, or the question is refused:
{ "principal": { "kind": "user", "sub": "vipps:abc", "groups": [], "phone": "912 34 567" },
"action": "transition",
"resource": { "kind": "bucket", "name": "hazards" },
"context": { "from": "open", "to": "fixed" } }
The answer is Cedar’s, with the rule ids that granted it, for a person who may never have opened the site. That is the whole authorization engine: the provider says who, memberships say what they belong to, the policy compiled from content says what they may do.
What Kanidm still does
For a site on Kanidm nothing changes: invites make accounts and add to
Kanidm groups (an invite with no group makes the account and adds to
none), and portal_invites tracks the one-time links. The two backends
can be swapped by the one variable; the content and the policy are the
same either way, except that an invite with no group only means
something where a Kanidm can make the account.