Skip to content

First boot and administrators

A Pryv.io platform is administered by administrators: accounts of the platform that hold an administrator role. This page covers the first boot of a new platform, how an administrator signs in to the administration API, how more administrators get a role, and what the admin key (auth.adminAccessKey) still does. Roles, their scopes and each core’s local policy are in Roles, scopes and local policy; what administrators do is recorded in the administration audit trail. Every route is in the Admin API reference.

The setup step, administrator sessions, the owner role, claim codes and the break-glass key scope come with open-pryv.io 2.0.0-rc.91. The other roles, the grant scopes and role management over HTTP come with 2.0.0-rc.92. The refusal of delegate tokens and of accounts that have a delegate comes with 2.0.0-rc.95, the erasure of an account from an administrator session with 2.0.0-rc.96.

The platform store holds a setup state: pending (the platform waits for its first administrator) or ready.

  • A fresh platform (no account, no other core): the first core that boots writes pending and mints the setup code. The first writer wins, so only one core of a platform does it.
  • An existing platform upgraded to 2.0.0-rc.91 or later (it has accounts, or other cores): its first boot writes ready directly. No code is printed, and admin-key calls behave as before. Its first administrator gets the role from a claim code.
  • A core that joins a platform later (bin/master.js --bootstrap) never mints a code: it reads the state.

While setup is pending, registration is closed (setup.registrationWhilePending: closed, the default): POST /users answers 403, except for the first administrator’s account created through the setup session. This changes the first boot of a fresh install only.

Automated installs (CI rigs, images, infrastructure as code) that provision with the admin key and never open the setup page finish setup without a first administrator: node bin/admin.js setup finish on a core, or POST /system/setup/finish with the admin key. Registration opens; the first administrator comes later from a claim code. Or set setup.registrationWhilePending: open to keep registration open meanwhile.

  • 130 random bits, shown as 26 characters of Crockford base32 in groups (XXXXX-XXXXX-XXXXX-XXXXX-XXXXXX). Typing is lenient: case, dashes and spaces are ignored, O reads as 0, I and L as 1.
  • Printed once, in one marked block of the boot log (stdout), with the addresses of the setup page. Also written to setup-code.txt next to the configuration file (mode 0600), deleted once setup is done. setup.printCode: false leaves the block out of the log (the file is still written when possible). The code is never logged otherwise.
  • Only its SHA-256 is kept, in the platform store: a restart keeps a pending code valid but cannot show it again. The log says when it was issued and how to replace it.
  • Valid for setup.codeTtlHours (24). Redeeming it is limited to 10 tries per 15 minutes per core: past that the tries answer 429 until the window ends, and the code stays valid.
  • Replace it: node bin/admin.js setup-code --new on a core (shell access is the proof of being the operator; in a container, docker exec <container> node bin/admin.js setup-code --new), or POST /system/admin/setup/code with the admin key. The previous code stops working.
  • Choose it in advance (images, CI, marketplace): node bin/admin.js setup-code --hash prints a new code and its SHA-256. Put only the hash in setup.codeHash (environment variable pryv_setup__codeHash, or node bin/init.js --setup-code-hash=<sha256>): the first boot then accepts that code and prints none. The hash is the SHA-256 (hex) of the canonical code (the 26 characters, upper case, no separator); setup-code --hash <code> computes it. Generate the code with setup-code --hash: nothing checks the strength of a code you make up.

/system/setup/ is served by every core, on any host name and on the bare IP address (http://<ip>:3000/system/setup/, or https://<ip>/system/setup/ with TLS), in both topologies. It needs no hosted site, no DNS, no certificate and no outbound access: it is the way in when the administration portal cannot be reached yet. It answers 404 once setup is done.

The steps:

  1. Enter the setup code. The page opens a setup session (2 hours).
  2. Read the checks: configuration, public address, DNS delegation, certificates and how they are issued, migrations, second factor, registration, portal, admin key scope. Each check is ok, info, warn or blocking.
  3. Sign in with an account of the platform, or create one. When administrators need a second factor (services.mfa on and admin.session.requireMfa: true), enable a TOTP factor on that account, then sign in again with it.
  4. That account becomes the first administrator, with role owner at scope platform.
  5. Finish. Registration opens, the setup code and the setup session stop working.

The page is three static files of the release (HTML, one script, one style sheet), with no external resource. Every answer carries content-security-policy: default-src 'none'; script-src 'self'; style-src 'self'; connect-src 'self'; form-action 'self'; frame-ancestors 'none'; base-uri 'none' and cache-control: no-store. The setup session and the account’s token live in the page’s memory only: reloading the page ends the session, and a new code is then needed (the page asks before it is left).

The page’s registration asks for the basic fields only (username, email, password). A platform that requires more (extra account fields in custom.systemStreams, an invitation token, a proved email with account.emailVerification.requireAtRegistration) refuses it: create the account first with POST /system/create-user (admin key) or with the account app, then sign in with it on the page.

Signing in from the page uses the app id pryv-setup-page, which auth.trustedApps does not need to list: a sign-in with that app id is accepted when it comes from the core’s own origin (the request’s own host, core.url or dnsLess.publicUrl) and carries a valid setup session while setup is pending. Anywhere else the app id is checked against auth.trustedApps like any other.

The same steps can be scripted with the setup routes.

An administrator authenticates to the /system routes with an administrator session, opened from a sign-in to the account:

  1. The administrator signs in on the account’s home core as in any Pryv.io app (password, then the second factor). The sign-in gives a personal token.
  2. POST /system/admin/session with that personal token in the Authorization header and { "username": "<username>" } in the body opens the session (256 random bits, admin.session.ttlMinutes, default 60). Only its SHA-256 is stored, in the platform store, so every core of the platform accepts it.
  3. Calls carry Authorization: AdminSession <token>. On each request the core that serves it reads the account’s role row and computes the permissions the account holds on that core (see Roles, scopes and local policy).
  4. POST /system/admin/session/renew with { "personalToken": "..." } extends the session; DELETE /system/admin/session ends it.

A session opens for any account that holds an active grant, even a grant that gives no permission on this core. The answer lists what the session holds here (permissions) and the permissions of its roles it does not hold here, with the reason (denied: scope or local-policy). An app access or a shared access of an administrator opens nothing: only a personal access from a sign-in of the account itself does. From 2.0.0-rc.95 a delegate token of the account (account delegation) is personal but refused too (404, as a wrong token), on every route that takes a personal token (session, renewal, step-up, claim, first administrator): the delegate acts on the account’s data, never as its administrator. A personal token is accepted on its account’s home core only: elsewhere these routes answer an error with the home core’s URL (data.homeCoreUrl).

Second factor. With services.mfa on and admin.session.requireMfa: true (the default), the sign-in behind the personal token must have passed its second factor. The home core records the account’s latest second-factor sign-in in its local memory (one entry per account, lost at a restart: the administrator then signs in again). Without it the session is refused (403, data.mfaRequired: true).

Refused requests are limited. Any account’s personal token can ask for a session, so refused requests are counted: 10 per 15 minutes per account, then 429 with Retry-After (from 2.0.0-rc.92). From 2.0.0-rc.93 only the refusals of an account that holds no administrator grant are counted: an administrator refused for its second factor or while setup is pending always gets that answer, then its session.

Step-up. Granting or revoking roles, minting claim codes, deleting and erasing accounts (roles:grant, claimCodes:mint, users:delete, and from 2.0.0-rc.96 users:erase), and writing some platform configuration keys, need a second factor younger than admin.session.stepUpMinutes (default 5). Without it the call answers 403 with data.stepUp: true. The administrator signs in again and sends that new personal token to POST /system/admin/session/step-up, then repeats the call. A core accepts a second factor stamped up to 60 seconds in its future (the clock difference with the home core).

Ending sessions. Deleting the account’s role row, or node bin/admin.js sessions revoke <userId|username>, stops every session of the account at its next request, on every core. A session opened before the account’s role row was deleted stays refused if the account gets a role again.

Origin rule. A call to /system that carries an Origin header and is not authenticated by the admin key is accepted only from the core’s own origin, the portal’s origin (from portal.site and the topology, or portal.url) or an origin listed in portal.cors.allowedOrigins, and gets CORS headers for that origin only. Admin-key calls and calls without Origin keep the API-wide behaviour.

dnsLess and other hosted sites. In dnsLess every hosted site is served on the API’s origin, the portal’s too, and the portal keeps the administrator session in that origin’s sessionStorage: a page of another hosted site can read it. Host there only sites you would trust with an administrator session, or use the DNS topology, where each site has its own origin. bin/check-config.js warns when the portal shares its origin this way.

Refusals. A refused credential (no credential, an unknown or ended session, a permission not held, the admin key outside its scope) answers 404 unknown-resource, as an unknown route does.

From open-pryv.io 2.0.0-rc.95. A delegate acts as the account’s owner on its data, and can reach a sign-in of it (it can change the account’s email, then reset its password). So an account that has a delegate, as the controlled side of a delegation relationship in any status (a pending request, an active or a stale relationship, until it is detached), is not used for administration:

  • with the account’s own sign-in, POST /system/admin/session, .../session/renew, .../session/step-up, POST /system/admin/roles/claim and POST /system/setup/first-admin answer 400 invalid-operation with data.id: account-has-delegate: detach the delegates, or cancel the pending request, first (a wrong or delegate token still gets the uniform 404, so nothing is told to anyone but the account itself);
  • PUT /system/admin/roles/{userId} for such an account answers the same 400, nothing written;
  • an account holding an active administrator grant cannot ask for a delegate: POST /{username}/delegations/attach-request answers 400 invalid-operation with data.id: account-holds-admin-role (revoke its role first).

The relationship is read on the account’s own core, which is where these routes run. An administrator session opened before the account had a delegate stays valid until it expires (admin.session.ttlMinutes) but is not renewed; node bin/admin.js sessions revoke stops it at once. bin/admin.js roles grant (the operator’s tool, on a core’s shell) does not check delegation.

Before 2.0.0-rc.95 (from 2.0.0-rc.91), a delegate token was accepted on these routes: an accepted delegate of an account holding an administrator grant (or able to claim one) could open or renew that account’s administrator session, claim a role for it or make it the first administrator. The acts gated by step-up stayed out of its reach.

A claim code gives a role to the account that redeems it: same format as the setup code, role and scope fixed when it is minted, valid 15 minutes by default (24 hours at most), single use (of two concurrent claims exactly one wins).

  • Mint one with node bin/admin.js claim-code --role <role> --scope <scope> --ttl 15m on a core, or POST /system/admin/claim-codes { role, scope, ttlMinutes } with the admin key or an owner’s session (step-up). Not with the setup session: a code outlives it. Without role and scope the code gives owner at platform. The code is answered once and never stored (only its SHA-256 is).
  • Redeem it: the person signs in on the account’s home core and calls POST /system/admin/roles/claim with the personal token in Authorization and { username, code }. The same second-factor rule as for a session applies. An account may try 10 codes per 15 minutes (429 past that).
  • The grant records via: claim-code and who minted the code.

This is also how an upgraded platform, or one finished by automation, gets its first administrator: mint an owner code on a core’s shell and hand it to that person.

Roles are stored in the platform store under the account id, never a username or an email; no credential is in them. From 2.0.0-rc.95 a role is granted to an account of the core that answers only: any other id answers 404 unknown-resource and nothing is written, so on a multi-core platform send the grant to the account’s home core (GET /system/admin/roles/by-username/{username} names it when asked elsewhere). bin/admin.js roles grant takes the same rule; a stray row written before is still revoked with DELETE (or roles revoke). The last lasting owner grant (owner at scope platform, without expiry) cannot be revoked nor replaced by an expiring one: the call answers 400 invalid-operation with data.id: last-owner. node bin/admin.js roles revoke --force does it anyway, after which the platform is administered with the admin key and a claim code. Two revocations racing to remove the last two owners both fail.

Deleting an account deletes its role row (its sessions stop). The holder of the last lasting owner grant cannot delete that account with its own token (400 invalid-operation, data.id: last-owner); a deletion with the admin key goes through.

From open-pryv.io 2.0.0-rc.96, an administrator session erases an account for good (GDPR Art. 17 handled by the operator) with POST /system/admin/users/erase { username, userId?, dryRun? }: its data, attachments, series, its own audit trail (unless audit.onUserDelete: keep), its platform rows, its relationships with other accounts (delegations, consent grants, apps), then the erasure ledger row. It is the same erasure as DELETE /users/{username} with the admin key, resumed by the core when it stops midway. Before, a session reached only the registry-only DELETE /system/users/{username}?onlyReg=true, and a full erasure needed the admin key, which break-glass takes away.

DELETE /system/users/{username}?onlyReg=true POST /system/admin/users/erase DELETE /users/{username} (admin key)
Permission users:delete (support, owner) users:erase (owner only) admin key, full scope
Second factor recent (step-up), checked by the gate recent (step-up), checked by the method none
What goes the account’s unique and indexed platform rows only: the account stays hosted and usable everything, ledger row with trigger admin everything, ledger row with trigger admin
Core the core holding the account the account’s home core only (elsewhere 400 with data.homeCoreUrl) the core holding the account
Deletion guards (last owner, a controlled account left without a way in) not run run strict: an objection, a guard that fails or one that cannot decide refuses, also for the admin key; no override logged, the erasure goes on
An administrator’s account (an active role grant) its platform rows only only by a subject holding roles:grant (a platform owner) or the admin key; its roles are revoked erased, its roles revoked
auth.adminAccessKeyScope: break-glass key refused key refused, a session still erases key refused
admin.lockdown, capability users not editable refused refused (403 admin-lockdown-capability), key included refused
user-account.delete without adminToken not read refused (403, data.setting: user-account.delete) refused
  • Dry run first. dryRun: true runs every check (second factor, home core, the account exists, an administrator’s account, an erasure already in progress, the deletion guards) and erases nothing. Both answer { erasure: { userId, username, dryRun, roleGrants } }: the account’s id and canonical name (a former name or an alias resolves to it) and its active role grants. Send the dry run’s userId with the erasure: when the name resolves to another account by then, the erasure is refused (400 invalid-operation, data.id: account-changed). A done erasure adds userDeletion: { username }.
  • Lifting a guard’s objection (400 invalid-operation with the guard’s data and guard; there is no override on this route): id: last-owner, grant owner at scope platform to another account first; controlledAccountsWithoutEmail, set an email on those accounts (or erase them first); unavailable: true (a guard failed, or a controlled account’s core did not answer: uncheckedRelationships), try again later. With the admin key in full scope, DELETE /users/{username} still erases despite an objection, logged.
  • An administrator’s account: 400 invalid-operation with data.id: administrator-account when the caller cannot revoke roles (an owner scoped to a core, or a local owner grant). A platform owner erases it, or revokes its roles first.
  • Scope. users:erase is not a platform-only write: an owner grant scoped to a core, or a local owner grant of that core, gives it on that core, for the accounts that hold no role. admin.localPolicy.requireLocalScope: [users:erase] keeps it from replicated grants.
  • Audit. Each call, done or refused by the route’s method, is recorded in the platform trail (method system.users.erase) with the administrator, the account’s id and the keyed hash of its name (never the name), dryRun and the role grants revoked (result.rolesRevoked); a done erasure also in the acting administrator’s own trail when that account is on this core. The gate’s 404 and the lockdown’s 403 come first and are not recorded. The erasure ledger row remains the proof of the erasure.
  • Two owners erased at the same moment (each other, or each its own account) may both pass the last-owner check: the platform is then left without a lasting owner. Recover with the admin key and a claim code (node bin/admin.js claim-code --role owner).

From the same release, a deletion guard that fails and is checked fail-closed (the auto-deletion sweep, this route) answers the deletion check "<guard>" could not be done (see the server log), without the error text.

The admin key (auth.adminAccessKey, sent as the raw value in the Authorization header) still works beside administrator sessions. What it reaches depends on auth.adminAccessKeyScope, set in the configuration file of every core (the same value on each):

  • full (the default, unchanged behaviour): the admin key authenticates every route that takes it.
  • break-glass: on /system, the admin key reaches only the routes marked break-glass in the Admin API reference (calls between cores, the setup code, claim codes, role listing and revocation, status routes); a /system path not in the route table is refused too. Outside /system the key no longer deletes accounts (DELETE /users/{username}: the account’s own token still can, when user-account.delete allows it) and no longer reaches /reg/records (use bin/dns-records.js) nor the /reg/admin/* routes. The previews cache clean-up keeps the key. Everything else needs an administrator session. A refused admin-key call answers 404.

The key cannot be retired (other secrets are derived from it): keep it for recovery. Before switching to break-glass, check that no script provisions accounts or writes DNS records with the key.

Runs on a core’s shell and talks to the platform store directly, so it works while the API is down. Shell access to a core is the proof of being the operator.

node bin/admin.js setup-code
node bin/admin.js setup-code --new
node bin/admin.js setup-code --hash [<code>]
node bin/admin.js setup finish
node bin/admin.js claim-code [--role owner] [--scope platform] [--ttl 15m]
node bin/admin.js roles list
node bin/admin.js roles grant <userId|username> --role <role> --scope <scope> [--expires 90m|12h|30d|<ISO date>] [--force]
node bin/admin.js roles revoke <userId|username> [--role <role>] [--scope <scope>] [--force]
node bin/admin.js sessions revoke <userId|username>
node bin/admin.js audit tail [--method <id>] [--account <userId> | --username <name|->] [--since 90m|12h|30d|<ISO date>] [--limit <n>]

setup-code without option prints the setup state and the pending code’s times; --new replaces the code and prints it once; --hash prints a code and its SHA-256 for setup.codeHash (no store access). roles grant, roles list and audit tail come with 2.0.0-rc.92, audit tail --account and --username - with 2.0.0-rc.93. --config <file> layers a host configuration file, as for bin/master.js. A username is looked up on the core the tool runs on: give the user id for an account of another core. A name given on the command line lands in the shell history: prefer --account <userId>, or --username -, which reads the name from the standard input. A code is printed once: keep the output out of shared logs.

Each act of the tool (code replaced, setup finished, claim code minted, role granted or revoked, sessions revoked) is recorded in the core’s platform trail and, when audit.syslog.active, written as one line to the audit syslog channel: the act, the role and scope, the target account id, the operating-system user and the core id, never a code.

Run it as the server’s user. From 2.0.0-rc.93 an act whose platform-trail record the tool cannot write (the trail belongs to another operating-system user or is not writable, as with docker exec as root) is refused before it is done, with a message naming the fix: docker exec -u node <container> node bin/admin.js ... in the image.

Key Category Default Meaning
setup.codeTtlHours platform-wide 24 lifetime of a setup code
setup.codeHash bootstrap null SHA-256 of a setup code chosen by the deployer
setup.printCode per core true print the setup code block at boot
setup.registrationWhilePending platform-wide closed closed or open
auth.adminAccessKeyScope platform-wide (in each core’s file, never in the platform store) full full or break-glass
admin.session.ttlMinutes platform-wide 60 administrator session lifetime
admin.session.stepUpMinutes platform-wide 5 how recent the second factor must be for a sensitive act
admin.session.requireMfa platform-wide true administrators need a second factor whenever services.mfa is on
admin.localPolicy per core none see local policy
admin.lockdown per core none see lockdown
portal.site platform-wide null the hosted site that is the administration portal (the install wizard writes admin)
portal.url platform-wide null address of a portal hosted outside the platform (instead of portal.site)
portal.cors.allowedOrigins platform-wide [] other origins a portal may call /system from
portal.customCapabilities platform-wide [] from 2.0.0-rc.93: the platform’s own capability names (x-<name>, 1 to 40 of a-z 0-9 -, at most 50) offered in the portal context after the built-in ones, to gate the platform’s own portal modules; an invalid list stops the boot

Boot and bin/check-config.js check these keys (portal.site must name a configured hosted site and is not set together with portal.url). How the portal is exposed and upgraded: Serving the portal. The portal signs in with the app id pryv-platform-portal: auth.trustedApps must accept it from the portal’s origin. The install wizard adds pryv-platform-portal@<portal origin> when it writes a portal.site entry; with portal.url, add it yourself, or the portal’s sign-in is refused.

bin/migrate-platform.js copies every row, the setup state, the role rows and the live codes and sessions included. Codes and sessions are stored by their SHA-256 only, so no secret moves; a pending setup code, a claim code or an administrator session stays valid on the new engine until it expires.