Skip to content

The operator: access, keys and credentials

What the people who run a LeanCPMS instance need to know about access: the operator and its membership, the admin pages, operator keys, the full rules for keys and revoking them, and the credentials that are not for people. It applies to LeanCPMS Cloud, run by Forsslund Systems AB, and to an instance you host yourself (Running your own instance).

An organization's administrator needs none of this; their guide is Users and access, which this page builds on. The design and its reasons are in docs/architecture.md §3 and §11. The examples use a made-up organization acme and addresses at example.com.

Contents

  1. The operator and organizations
  2. API keys
  3. Keys with no person in their chain
  4. Other credentials
  5. The actions journal

1. The operator and organizations

An instance holds several organizations. An organization is a company that owns charging stations: its sites, charge points, price list, sessions, receipts and monthly settlements belong to it, and it cannot see anyone else's.

The operator is whoever runs the instance. On LeanCPMS Cloud that is Forsslund Systems AB. The operator is not an organization; it stands above all of them and sees every organization.

The operator membership is the admin

A membership connects a person to one organization, or to the operator. A membership without an organization is an operator membership. It is the instance's "superuser":

  • In the portal it shows every organization.
  • It is the only way into the Django admin pages at /admin/, which are a read-only view of every table (cpms/portal/admin_site.py).
  • With cpms login it can get an operator key, which reaches every organization and the operator-only commands (opening the gateway to unknown charge points, the organization document, the balancer).

Django's own is_staff and is_superuser flags decide nothing about access: nobody gets into /admin/ or sees an extra organization because of them, and they are never needed. Their one effect is protective: an organization's key cannot add, change or remove an account that has one of those flags, and losing a membership never switches such an account off (cpms/actions/members.py). Operator memberships are given by the operator only; an organization can never create one.

The admin pages

An operator member also sees an Admin button in the portal, which leads to /admin/ on the portal's host (https://portal.leancpms.com/admin/ on LeanCPMS Cloud). Opened directly without a login, it sends you through the same code login first. Organization members get "403 Forbidden" there, whatever their role. The admin pages are read-only: changes are made with cpms and an operator key, never in the admin.

Members of an organization, and of the operator

There is no page for adding members. They are added from the command line, or through the API it uses:

  1. The operator adds the organization's first administrator, with an operator key:

    cpms members add anna@example.com --org acme --role write
    
  2. That administrator adds colleagues, with their own personal write key (Users and access).

An operator member is added the same way, with --operator in place of --org and an operator key:

cpms members add ops@example.com --operator --role write

Nothing is e-mailed when a member is added; tell the person yourself. An organization can manage only its own members. It cannot see or change an operator member, and it learns nothing about a person's memberships elsewhere. With an operator key, cpms members list shows everyone.


2. API keys

Everything that is not a person in a browser talks to the instance's JSON API with an API key, sent as Authorization: Bearer <key>. The command line cpms is one such client.

A key looks like lcp_3f9a1c2e_<43 more characters>. The part after lcp_, here 3f9a1c2e, is its prefix: it is not secret, it names the key in lists and logs, and it is what you revoke. The rest is the secret. The instance stores only a hash of the whole key, so a key is shown exactly once, when it is made, and can never be shown again.

Every key has three properties:

  • Who it is for. An organization key reaches one organization. An operator key reaches every organization and the operator-only commands.
  • Its scope. A read key may only look (HTTP GET). A write key may also act. A read key may do one thing besides looking: revoke itself (cpms logout).
  • Whose it is. A personal key belongs to a person: cpms login gets it after the person approved it in the portal, and it is named after the computer, such as cpms on anna-laptop. A machine key belongs to no person: it is made with cpms keys issue for a script, a CI pipeline, a dashboard or an agent, and it records which key issued it.

The rules, and how revoking cascades

  • A role caps personal keys. A read member gets only read keys from cpms login. A write member may choose either.
  • A key never makes a wider key. An organization's write key may issue keys for its own organization, read or write; never an operator key, never a key for another organization. A read key issues nothing, and may not list keys or members either, since lists of keys and members are part of managing them.
  • Removing a member revokes their keys, and every key made from them. When a person loses a membership, their personal keys for it stop working, and so does every machine key issued with one of those keys, and every key issued with those, however far down. A personal key the person had already revoked (with cpms logout, say) still counts: the keys made from it go too.
  • Lowering a role does the same for write. Lowered from write to read, a member's personal write keys are revoked, together with every key issued from them, including read keys issued from them.
  • A switched-off account's keys stop working. A person whose last membership is removed is switched off: they can no longer log in, their portal login ends, and any personal key of theirs still left is refused. The exception is a person who is also some organization's customer (a driver with an account): that account stays on. The portal then sends them no login code and shows them nothing, and their personal keys were revoked with the memberships.
  • Revoking one key revokes only that key. cpms keys revoke and cpms logout do not cascade: machine keys issued with the revoked key keep working. They still die with their maker's membership, as above.
  • Removing a person does not remove the members they added. Each membership records who added it; when someone leaves, decide about the people they brought in separately.

The consequence to remember: a machine key lives only as long as the membership of the person whose key issued it. That is deliberate, so that nobody leaves behind working keys when they leave. A key that must keep working when people come and go is issued from a key with no person in its chain (below).

Who owns or issued a key, and who added a member, is shown as an e-mail address only to those who may see that person in the members list: the operator, and the organization the person is a member of now. Others see "operator" or "former member".

What each kind of key may do

organization read key organization write key operator key
Live state, sessions, energy per quarter-hour, events, monthly settlements own organization own organization every organization
Export manifests, history, diff own organization own organization every organization
Plan and apply the price list and site documents no own organization every organization
Plan and apply the organization document no no yes
Stop or close a session, rekey a charge point no own organization every organization
OCPI connections look own organization every organization
List, add, remove members, change roles no own organization's members (never an operator member) everyone
List, issue, revoke keys no own organization's keys every key
The gateway's admission window for unknown charge points (cpms admission) no no yes (opening it needs write)
Revoke itself (cpms logout), cpms whoami yes yes yes

An operator key also has a scope: an operator read key looks at everything and changes nothing.


3. Keys with no person in their chain

A key the operator issues with their own personal operator key would in turn die with their operator membership. A key that must outlive every person (an organization's dashboard, an accounting export, an agent, the instance's own services) is issued from a key with no person anywhere in its chain: a key made on the server with manage.py issue_key, or a key issued from such a key.

On the server (leancpms-manage is manage.py on an installed instance; deploy/README.md):

sudo leancpms-manage issue_key --operator --name integrations   # prints an operator key once

With that person-free operator key in its environment, the operator issues an organization's integration key:

CPMS_API_KEY=lcp_… cpms keys issue --org acme --name accounting-export --scope read

or makes it directly on the server:

sudo leancpms-manage issue_key --org acme --name accounting-export --scope read

It appears in the organization's cpms keys list with "operator" as its issuer (or nothing, if it was made directly on the server). The organization can still revoke it. Keep the person-free key itself out of any one person's config file: in a secret store, or on the server.


4. Other credentials

These are not for people and not for the API, but they exist and it helps to know who handles them.

  • OCPI tokens. A roaming partner (an eMSP, or a registry such as Nobil) talks to the instance over OCPI with tokens of its own, one connection per organization and partner. cpms ocpi connect acme --name partner makes the connection and prints Token A once, to send to the partner; the partner registers, and the tokens are exchanged automatically. cpms ocpi disconnect ends it. An organization's write key may do this for its own organization; on LeanCPMS Cloud the operator usually does.
  • Charge point passwords. Each charge point declared with auth: basic in its site document has its own password for its OCPP connection. The gateway sets it on the box over OCPP; it is in no file and nobody sees it. cpms chargepoints rekey <key> replaces it.
  • Driver session tokens. A driver who pays by card at the QR code gets a link to their own session (/s/<token>). The token is the only key to that one charge. Drivers hold these; nobody at the organization needs them.
  • Driver logins. On an organization's own driver host (driver_hosts) a driver may log in with a one-time code by e-mail and see her own charges and receipts there (cpms/driver/README.md, "Driver accounts"). Anyone may: the first login makes her that organization's customer. It is the same login mechanism as the portal's and the same user table, one user per e-mail address, but a driver login opens nothing in the portal, and the portal still sends a code only to a member. A login made at one organization does not count at another.
  • Instance secrets. The balancer's own operator key, the key between LeanCPMS and its gateway, the payment provider's keys: these live on the server and are the operator's (deploy/README.md).

5. The actions journal

Every change (adding a member, issuing or revoking a key, applying a manifest, approving a cpms login) writes a row to the actions journal: who, when, what, and the result. It never stores a secret or an e-mail address; it stores the key's prefix. That is what answers "who did this, and when" afterwards.


In the code: people and roles cpms/portal/models.py, cpms/portal/access.py; the login for members and drivers cpms/identity.py; the admin cpms/portal/admin_site.py; member actions cpms/actions/members.py; key actions cpms/actions/keys.py and cpms/core/keys.py; cpms login cpms/actions/login.py, cpms/api/login.py, cpms/portal/cli.py, cpms/cli/login.py; scopes on every request cpms/api/auth.py.