Skip to content

Managed user storage

The managed store gives the platform owner, for each account, a set of streams and events the platform controls: usage records of a paid service, budgets and limits, service secrets. The account holder cannot change them, sees only what the platform allows, and cannot delete them by deleting the account: they stay with the platform until it purges them.

Available from open-pryv.io 2.0.0-rc.97. Everything goes through the standard API: the store is an ordinary data store of the account, reached with stream ids that start with :_managed:. The platform reaches it with ordinary accesses of the account (the platform accesses), and the account holder gets the rights a platform-wide setting (the user policy) gives. The administration routes are in the System API reference.

This page is for operators (enabling it, where the data lives, deletion, backup) and for the integrators of platform services (minting the root access, creating streams and service accesses).

Words used here:

  • managed store: the store _managed, stream ids :_managed:<id>, root :_managed:.
  • platform access: an access of the account that the platform controls: the root (one per account, minted by an administration route) and its children (the service accesses the root creates). Not to be confused with a “managed” shared access, which is a shared access managed by the app access that created it.
  • user policy: the platform-wide setting managedStorage.userAccess.permissions.
managedStorage:
active: true
userAccess:
permissions: []
onUserDelete: keep
retentionDays: null
storages:
managed:
engine: null
postgresql: null
sqlite:
path: null
  • managedStorage.active (YAML only, read at boot: the same value on every core) mounts the store; changing it needs a restart of every core. While it is false the store does not exist: :_managed: ids are unknown, the administration routes answer 404 and service info does not advertise it.
  • userAccess.permissions is the user policy; [] (the default) means the holder sees nothing.
  • onUserDelete: keep (default) or erase, see account deletion.
  • retentionDays: null (default) keeps retained data until purged, see retention period.
  • storages.managed.engine: null uses the base engine; postgresql or sqlite.
  • When active, service info answers features.managedStorage: true (an explicit service.features.managedStorage in the configuration wins). Export tools read it to know they must ask for the store explicitly.
  • The administration capability managedStorage is offered (portal, role grants) only while the store is active.

The managed data is kept apart from the account’s own data, on the account’s core, so that an account erasure does not reach it and so that it can be backed up and restored on its own. Details and native dump commands are in the server’s README-DBs.md, “Managed store storage”.

Each core has its own managed location, never shared with another core (no two cores on the same managed database, tables or SQLite root). The retained routes and the retention sweep decide whether an account still exists by looking at this core’s accounts only: a location shared by two cores would make each see the other’s accounts as gone.

  • PostgreSQL: tables managed_streams, managed_events, managed_event_streams and managed_retained, created at boot when the store is active. In the engine database by default; in a database of its own (and a pool of its own) with storages.managed.postgresql, an object with the keys of storages.engines.postgresql (the ones not given are taken from there):

    storages:
    managed:
    postgresql: { database: pryv-managed }
  • SQLite: one file per account, <storages.managed.sqlite.path>/<userId>/managed-<version>.sqlite, default root var-pryv/managed-users. The boot refuses a root inside the users directory (storages.engines.sqlite.path) or containing it: an account erasure wipes that directory.

  • Docker: the default SQLite root /app/var-pryv/managed-users is on the container’s own filesystem, and the boot refuses it (as it refuses an ephemeral storages.engines.sqlite.path). With SQLite and the store active, set storages.managed.sqlite.path to a mounted path next to the users directory, for example /app/data/managed-users beside /app/data/users.

managedStorage.userAccess.permissions is a list in access-permission format, stream permissions of the managed store only:

managedStorage:
userAccess:
permissions:
- { streamId: ':_managed:ai-usage', level: read }
- { streamId: ':_managed:ai-budget', level: read }
  • It gives the account holder’s personal token its level on each listed stream and its descendants (the nearest listed ancestor wins, then the store root’s entry). A stream the policy does not cover does not exist for the holder.

  • It also caps every access the holder creates (apps, shares, OAuth grants, consent grants): such an access holds at most the narrower of its own grant and the policy, decided each time the access is used. Narrowing the policy narrows every one of them at once. Creating an access above the policy is refused (403), so an access never shows a grant it cannot use.

  • It is platform-wide: held in the platform store and written through the platform-configuration routes (or the portal), which need config:write and managedStorage:write at platform scope and a recent second factor:

    PUT /system/admin/platform-config/managedStorage.userAccess.permissions
    { "value": [ { "streamId": ":_managed:ai-usage", "level": "read" } ] }

    A value in the store replaces the configuration files’ on every core within platform.configPollSeconds; it applies at once to every account. The lockdown profile gitops marks it read-only for the API.

  • It is checked when written: at most 100 entries, each exactly { streamId, level }, streamId matching :_managed: followed by 0 to 100 lowercase letters, digits or dashes, level one of read, contribute, manage, create-only, none. A value that fails the check at use (a stream named twice) gives nothing: the holder sees nothing.

  • Any level is accepted, manage included. Give contribute or manage only for streams the holder is meant to change: the point of the store is that they usually cannot.

  • The store is not covered by a * permission. An app obtains a managed permission the standard way (requested permissions in an auth request, or create access), naming the :_managed: streams.

POST /system/admin/managed-storage/accounts/alice/root
-> 200 { "userId": "cm4...", "access": { "id": "cl9...", "token": "...",
"apiEndpoint": "https://<token>@alice.example.com/" } }
  • Called on the account’s core (Create the root platform access), with an administrator session (managedStorage:write, recent second factor) or the admin key (not in break-glass scope). An account of another core, or an unknown one, answers 404.

  • It creates the account’s root access, or answers the existing one (same id and token): the call is idempotent, and the account is “enabled” once it holds a root. The root is an app access named platform:root, without expiry, holding manage on :_managed:.

  • Keep userId from the answer: the retained data of an erased account is addressed by it.

  • The answer carries a token: it is never cached (Cache-Control: no-store); hand it to the platform service directly.

  • Get managed storage status (GET /system/admin/managed-storage/accounts/alice, managedStorage:read) answers { enabled, userId, streams, events } (counts of the account’s managed data).

  • Delete the root platform access (DELETE /system/admin/managed-storage/accounts/alice/root) deletes the root and every access it created; the data stays. It answers { userId, accessDeletion: { id }, relatedDeletions: [{ id }] }, or 404 when the account holds no root.

  • The same from a core’s shell, for accounts of the core it runs on:

    Terminal window
    node bin/admin.js managed-storage status <username>
    node bin/admin.js managed-storage root create <username>
    node bin/admin.js managed-storage root delete <username>

    root create prints the token: keep its output out of shared logs.

There is no token rotation: a leaked root is revoked by deleting it and minting a new one, which also revokes its children (re-issue them). A running core may still accept a deleted token until its access cache expires (caching.accessMaxAgeSeconds, 60 seconds by default).

With the root token, the standard create stream. The id carries the store prefix and the parent is the store root or a stream of the store:

POST https://alice.example.com/ Authorization: <root>
[ { "method": "streams.create", "params": { "id": ":_managed:ai-usage", "name": "AI usage", "parentId": ":_managed:" } },
{ "method": "streams.create", "params": { "id": ":_managed:ai-usage-llm", "name": "LLM calls", "parentId": ":_managed:ai-usage" } },
{ "method": "streams.create", "params": { "id": ":_managed:ai-budget", "name": "AI budget", "parentId": ":_managed:" } } ]
  • Without an id, { name, parentId: ':_managed:' } gets :_managed:<generated id>.
  • An unprefixed id with a managed parent, or a :_managed: id without parentId, is refused (invalid-request-structure).
  • The store starts empty: the server provisions no stream. Whoever holds manage on a parent may create streams under it.

The root creates the accesses of the platform’s services with the standard create access:

POST https://alice.example.com/accesses Authorization: <root>
{ "name": "ai-engine", "type": "shared", "expireAfter": 31536000,
"permissions": [ { "streamId": ":_managed:ai-usage", "level": "contribute" },
{ "streamId": ":_managed:ai-budget", "level": "read" } ] }
-> 201 { "access": { "id": "...", "token": "...", "name": "platform:ai-engine",
"clientData": { "managedStorage": { "role": "child", "rootId": "cl9..." } }, ... } }
  • Only shared accesses, within the root’s levels (the standard rule for an app access). The root lists, updates and deletes them with the standard access methods; deleting the root deletes them.
  • The server stamps the marker clientData.managedStorage and prefixes the name with platform:.
  • Stream permissions of the managed store only: a permission on any other stream (any spelling) is refused (invalid-operation), and so is randomAlias. A platform access never reads nor writes the account’s own data.
  • A platform access creates no webhook and no shared secret (they would live in the account holder’s space): it holds webhooks and secretSharing as forbidden.
  • Recommended: one access per service, each with expireAfter.

For any access that is not a platform access (the personal token included):

  • get accesses (with includeDeletions too) does not list platform accesses; get one, update and delete of one answer unknown-resource; check app authorization never matches one; no accessesChanged notification is sent for one.
  • A clientData.managedStorage key in a create or update body is refused (403), whoever sends it, and names starting with platform: (any letter case) are refused to every other creator.

Administrators still see platform accesses (GET /system/accesses/:accessId).

Services use their own token with the standard methods: events get, get one, create, update and delete; streams get, create, update and delete; batch calls; socket.io. No new method.

POST https://alice.example.com/events Authorization: <ai-engine>
{ "streamIds": [":_managed:ai-usage-llm"], "type": "count/generic", "content": 1532 }
GET https://alice.example.com/events?streams=[":_managed:ai-budget"]&limit=1 Authorization: <ai-engine>
  • Explicit only: get events without streams never includes the store, and get streams at the root does not list :_managed:. Ask for it by naming :_managed: streams (or the store root, :_managed:, for everything readable) and parentId: ':_managed:' for the stream tree.
  • Limits of this version, refused with invalid-operation: attachments, high-frequency series event types (series:*). An event’s streamIds all belong to the store, and a stream cannot move to or from another store (invalid-request-structure).
  • Stream ids written in another spelling (:local::_managed:x) are the same stream, judged as such.
  • Change notifications (eventsChanged, streamsChanged) fire as for any store.
  • Data is protected like any event (disk or volume encryption, backup cipher): there is no field-level sealing. A secret stored as an event content is readable in the database and in backups.

Walk-through: accounting the use of a paid AI service

Section titled “Walk-through: accounting the use of a paid AI service”
  1. Once for the platform: set managedStorage.active: true on every core, then the user policy (the holder reads usage and budget):

    PUT /system/admin/platform-config/managedStorage.userAccess.permissions
    { "value": [ { "streamId": ":_managed:ai-usage", "level": "read" },
    { "streamId": ":_managed:ai-budget", "level": "read" } ] }
  2. The subscription service enables an account: POST /system/admin/managed-storage/accounts/alice/root, and keeps userId and the root token.

  3. It creates the accounting streams with the root (:_managed:ai-usage, :_managed:ai-usage-llm, :_managed:ai-budget, the batch call above).

  4. It creates, with the root, a contribute access on :_managed:ai-usage (plus read on the budget) for the AI engine, and a contribute access on :_managed:ai-budget for the subscription manager.

  5. The subscription manager writes the budget; before serving, the AI engine reads the budget and the month’s usage with its own token, and records each use as an event.

  6. Alice’s app, which requested read on :_managed:ai-usage, shows her consumption:

    GET https://alice.example.com/events?streams=[":_managed:ai-usage"]&fromTime=... Authorization: <alice app>
    -> 200 { "events": [ ... ] }
    POST https://alice.example.com/events Authorization: <alice personal>
    { "streamIds": [":_managed:ai-budget"], "type": "money/chf", "content": 100000 }
    -> 403 forbidden (her app, holding nothing on the budget: 400, as for an absent stream)
    GET https://alice.example.com/accesses Authorization: <alice personal>
    -> 200 (no platform access listed)
  7. Alice deletes her account. Her managed data is retained (below); the three platform tokens stop working with the account. The platform reads it when closing its books, then purges it:

    POST /system/admin/managed-storage/retained/lookup { "userId": "cm4..." }
    GET /system/admin/managed-storage/retained/cm4.../events?streams=[":_managed:ai-usage"]
    DELETE /system/admin/managed-storage/retained/cm4...
  • With the personal token: exactly the user policy, on the listed streams and their descendants. Reading the store root gives the readable part only. A stream the policy does not cover (or covers with none) answers exactly as an absent one (unknown-referenced-resource or unknown-resource), so its existence is not told; a change to a stream the holder may see but not change is refused (403). The store root is not listed among the root streams.
  • The holder may hand on, to their own apps and shares, at most what the policy gives (see the user policy).
  • “Download my data”: an export made with the personal token holds what the policy lets the holder read and nothing else; platform accesses are not in it (they are not listed to the holder). Because the store is explicit-only, an export tool asks for it when service info advertises features.managedStorage: get streams with parentId: ':_managed:' (a refusal means nothing is visible), then get events on the streams listed.
  • Audit: calls made with platform accesses are recorded in the account’s audit, like those of any access (method, access id, query; never event content), and the holder reads them in :_audit: as usual. The administration routes are recorded in the platform trail, not in the account’s audit.

Every erasure (DELETE /{username} by the holder, DELETE /system/users/:username, the account auto-deletion) runs one more step, once the account’s accesses are gone (so that nothing can write to the store any more):

  • managedStorage.onUserDelete: keep (default): if the account holds managed data, it is kept under a retention record: user id, erasure time (deletedAt, seconds), core id, and the keyed hash of the username (the erasure ledger’s key and key id), never the username in clear. An account without managed data leaves nothing.
  • erase: the managed data is purged with the account.
  • The erasure ledger row of the account says what happened: managedData is none, erased or retained (List erasures, bin/erasures.js --list). The field is absent on rows written by a core without the store, or by an earlier release.
  • The platform accesses are accesses of the account: they are erased with it, so no token opens the retained data. Only the retained routes, on the core that held the account, reach it.
  • A call already past its checks when the step runs may still land a moment later: under keep it is retained with the rest; under erase it becomes orphan data, adopted into retention by the sweep, and retentionDays or the purge route clears it.
  • The step runs after the account is gone. If the managed storage fails at that point (for example a managed database of its own that is down), the erasure call answers an error, the erasure stays unfinished (no erasure ledger row yet) and the auto-deletion sweep completes it once the storage is back.
  • Turning the store off does not erase anything: an account erased while managedStorage.active is false keeps its managed data where it is, with no record; once the store is on again the sweep adopts it into retention.

Orphan data is managed data of an account id that is neither a live account of this core nor retained, and has no erasure in progress: an account erased while the store was off, a write that landed just after the erasure step, an old native dump restored. It is never purged because it looks orphaned. The pass that runs with the retention sweep (whenever the store is active) adopts it into retention the second time it sees it, so that a restore or an account creation in flight is not taken for an orphan:

  • it gets a retention record like any erased account’s, marked origin: "orphan". The erasure time comes from the erasure ledger row of the id when there is one, else it is the adoption time (the retention period then starts at adoption); deletedAtSource says which (ledger or adoption);
  • from then on it is ordinary retained data: listed, read and purged by the retained routes, expired by retentionDays;
  • each adoption is recorded in the platform trail as admin.managedStorage.orphanAdopted (account id and counts, never content). The erasure ledger row, if any, is not rewritten;
  • an id holding only deletion records (no live stream or event) is cleaned without a record.

On the core that held the account, with an administrator session or the admin key (not break-glass). Every call is recorded in the platform trail (account id and keyed username hash, never content); answers are never cached.

Route Permission Answer
List retained data: GET /system/admin/managed-storage/retained (limit 1 to 1000, default 200; skip) managedStorage:read { retained: [view], total }, oldest erasure first
Look up retained data: POST /system/admin/managed-storage/retained/lookup with { userId } or { username } managedStorage:read { retained: [view] }, 404 when none
Get retained streams: GET /system/admin/managed-storage/retained/:userId/streams managedStorage:read { streams }, the tree (trashed included), ids :_managed:...
Get retained events: GET /system/admin/managed-storage/retained/:userId/events managedStorage:read { events }
Purge retained data: DELETE /system/admin/managed-storage/retained/:userId managedStorage:delete, recent second factor { retainedDeletion: { userId } }: data and record purged
  • A view is { userId, deletedAt, retainedAt, coreId, usernameHash, usernameHashKeyId, origin, deletedAtSource, streams, events } (counts). origin is orphan for adopted orphan data, null for data retained by an account erasure; deletedAtSource (ledger or adoption) is set for orphans only.
  • The lookup is a POST so that the id or name stays out of URLs and access logs. A username is matched through the keyed hash under the current ledger key only (any letter case), and may match several erased accounts: the answer is a list.
  • Events query: streams (a JSON list or one id, alias spellings accepted; descendants included; the store root means the whole store; an id of another store is refused with 400), types, fromTime, toTime, limit (1 to 10000, default 1000), skip, sortAscending.
  • Retained data is read-only: it is never written again.
  • An id that is a live account of this core is never retained data (an account restored over data retained under its id): 404, as an unknown id. Every route answers 404 while the store is not active.

managedStorage.retentionDays is a whole number of at least 1, or null (the default: kept until purged). The pass that follows each account auto-deletion sweep (account.autoDeletion.sweepIntervalMs, every 6 hours by default) purges the retained data whose erasure is older than that, skipping live ids, and records each purge in the platform trail (admin.managedStorage.retentionExpired). The boot refuses a malformed onUserDelete or retentionDays.

Retained data survives an erasure request by design. Before turning the store on, the platform owner states the legal basis for keeping it (for example billing records) and its retention period, and sets retentionDays (or purges) accordingly.

The GDPR reading this page follows (it is not legal advice; check it for the jurisdictions you serve):

  • Roles: the platform owner is the controller of the managed data. The services that write it on the platform owner’s instructions are its processors (an Art.28 contract). A partner that determines its own purposes for the data is a separate controller, or a joint controller under Art.26, as each deployment states. Pryv, as software provider, is neither for this data.
  • Information (Art.13 / Art.14): records the platform’s own services observe during the holder’s use are collected from the holder, so the information is due at collection (Art.13): the notice says the store exists, its purposes, basis, periods and that it outlives an account deletion. Art.14 applies only to records a partner service supplies from its own collection.
  • Access (Art.15): what the user policy shows is not the answer to an access request. The controller provides all of the person’s personal data in the managed store, read with the account’s root access (or the retained routes after an erasure), withholding only items whose disclosure would adversely affect the rights and freedoms of others (Art.15(4): service credentials, keys, trade secrets); withholding never amounts to refusing all information.
  • Portability (Art.20): raw usage records observed from the person’s own activity are in scope when the processing rests on consent or contract; budgets, limits and other figures the platform derives or sets are not. The holder’s own export holds only the policy-visible part, so the platform completes it on request with the usage records (same means as for Art.15).
  • Erasure (Art.17): keeping managed data after an account’s erasure is lawful only under an Art.17(3) exception documented for each purpose, typically (b) a legal obligation (bookkeeping retention of billing records) or (e) legal claims (billing disputes). Managed data without such a ground is purged at the erasure (managedStorage.onUserDelete: erase) or within a documented period (retentionDays, or an explicit purge).
  • Native tools, for the store alone: pg_dump -t 'managed_*' (or the managed database), a copy of the SQLite root. See the server’s README-DBs.md.
  • bin/backup.js carries it, engine-agnostic (see backup):
    • per account, its managed streams and events (all rows, trashed and deletion records included), written only for an account holding managed data and restored with the account;
    • per core (a whole-core backup, not --user), the retained data: every retention record and its data. The restore puts it back without touching the users index and never creates an account; an account refused because it was erased after the backup still has its retained data restored. An id that is an account of the core, or one the core already holds managed data for (under a retention record or not), is skipped, even with --overwrite: retained data is final once retained, so the backup’s copy is never newer. To take the backup’s, purge the core’s through the retained route (recorded in the platform trail), then restore again;
    • data the core retains under a record is never cleared by a restore: an account restored over it (--restore-erased) keeps it, and the backup’s managed data of that account is not restored (said in the log; purge it through the retained route and restore again with --overwrite);
    • a core whose store is not active refuses a backup holding managed data; --skip-managed restores without it;
    • platform accesses travel with the account’s accesses, marker included.
  • A release without the managed store restores such a backup without the managed data.

bin/integrity-check.js checks the managed events of each account too (managed-events= in its report). Retained data is checked with --user <retained userId> (one erased account) or --retained (every retention record of the core): that check covers the managed data only, the account itself being gone. bin/backup.js --verify-integrity does not check the retained section.

Terminal window
node bin/integrity-check.js --user <retained userId>
node bin/integrity-check.js --retained
Permission Gives Step-up
managedStorage:read account status, retained listing, lookup and reads no
managedStorage:write root mint and deletion; with config:write, the user policy yes
managedStorage:delete purge of retained data yes
  • The owner role holds them. None is platform-only: a grant at core scope is meaningful (the data is per core). The routes are not break-glass.
  • A step-up permission needs a second factor younger than admin.session.stepUpMinutes: without it the call answers 403 with data.stepUp: true; renew it with POST /system/admin/session/step-up and repeat the call. Administrator sessions are described in the server’s setup and administrators guide.
  • Platform-trail method ids: system.managedStorage.getAccount, .createRoot, .deleteRoot, .listRetained, .lookupRetained, .getRetainedStreams, .getRetainedEvents, .deleteRetained; admin.cli.managedStorage.rootCreated and .rootDeleted for bin/admin.js; admin.managedStorage.retentionExpired for the retention pass, admin.managedStorage.orphanAdopted for each adoption of orphan data.

The managed data, the platform accesses and the retained data live on the account’s core; call the account and retained routes there (an account of another core answers 404, as DELETE /system/users/:username does). The on/off switch and the user policy are platform-wide. Moving a core to a new host moves its managed location with it (the SQLite root, or the managed database when it has its own). Moving one account between cores does not move its managed data.

  • No token rotation for the root (delete and mint again; children re-issued).
  • No webhooks, shared secrets or aliases for platform accesses; no attachments nor high-frequency series in the store.
  • No field-level sealing of event content.
  • The /system routes need an administrator session or the admin key in full scope: under auth.adminAccessKeyScope: break-glass a platform service needs an administrator session.