Files
charging_station/wiki/concepts/authorization.md
T
julian a9b8436f2c refactor(backend): user app idTags validated against the user record, not the allowlist
'app token of <name>' synthetic allowlist entries are gone: decide()
recognizes a user's personal idTag directly, enforces the user's own
charger:<cp>:<gun> scopes at the charger-side gate, and attributes the
session (who=user, method=app). charger_start no longer auto-enrolls;
PUT /api/allowlist/<user-tag> returns 400; stale entries auto-drop at
startup. Zero-user open mode still authorizes 'app-remote' for
bootstrap. Smoke: 63 checks.
2026-07-12 09:50:27 +02:00

8.5 KiB
Raw Blame History

type, updated, tags
type updated tags
concept 2026-07-11
auth
requirements

Authorization Methods

The three planned ways to authorize a charging session. Architecturally they all collapse to one gate: decide(id_tag, connector) in the backend (backend/csms.py; formerly station.py in csms-toolkit) returns Accepted/Rejected against the allowlist in backend.db. Per 2026-07-09-findings-and-requirements. On top of these charger-side methods sits the per-user API permission system (last section).

1. RFID cards — ✅ verified live (2026-07-09)

First card tapped on the real charger: idTag 1000000000000393 → Authorize → StartTransaction on gun 2 → actual charging session started (tx 1, meter_start 3,513.857 kWh). Enrolled as "RFID card A". Second card captured the same session: 1000000000000395 → "RFID card B". The ids are sequential — the cards ship as a numbered batch.

[!warning] Session restarted after remote stop (❓ verify mechanism) ~65 s after a RemoteStop on gun 2 (cable left plugged), a new transaction began with the same card id. Either the owner re-tapped, or the charger auto-restarts from its authorization cache (AuthorizationCacheEnabled=true). Matters for app UX: "stop" may not stick while the cable stays in. Test: remote-stop and touch nothing for 5 min.

[!warning] Superseded (2026-07-11): learn mode removed — replaced by the pending-card review workflow An unknown card is now ALWAYS refused, but lands in pending_cards. The admin gets a notification (banner + badge in the frontend) and decides: approve (name it, link it to a user, optionally restrict guns — one step) or reject (goes to denied_cards, silently refused, never re-pends; un-rejectable). New-card flow: tap once on the charger → review in the panel’s Cards page. ✅ smoke-verified: unknown tap → Invalid + pending; approved card authorizes on next tap; rejected card stays silent.

Since 2026-07-11 a card can be linked to a user and restricted per gun:

  • "user": "julian" on the allowlist entry ties the card to a user account — sessions started with it attribute to that person in the history, and the owner sees their card's sessions even without gun-wide permissions (ownership is looked up live, so linking is retroactive for history visibility).
  • "guns": ["eu092025:2"] restricts the card to specific guns, charger-qualified (fnmatch patterns, so "eu092025:*" = all guns of one charger) — multi-charger-safe by construction. The check fires at StartTransaction (the only message that carries the connector); the preceding Authorize (tap) still says Accepted — harmless on this charger, because AuthorizeRemoteTxRequests=false makes StartTransaction the decisive call anyway (see the probe facts below). ✅ verified with a fake charge point: gun-2-only card → Invalid/tx 0 on gun 1, Accepted on gun 2.

Both are editable from the panel's Admin tab (owner dropdown + guns field).

2. By vehicle / chassis — ❌ CLOSED: not supported (2026-07-09)

Exhaustively tested on the real hardware; the charger never forwards any vehicle identifier as an OCPP idTag. Three escalating tests, all negative (full record in discovering/events.jsonl):

  1. Plain plug-in, no card (both cars, both guns, ~15:03Z and ~15:08Z): connector → Preparing, then silence. No Autocharge out of the box.
  2. MacEnabled=true live (ChangeConfiguration Accepted, no reboot; EU/CCS car replugged 15:22Z): no idTag in 5+ min.
  3. MacEnabled=true after a full power-cycle (setting confirmed persisted post-reboot via re-probe; EU car replugged 15:33:51Z): no idTag in ~3.5 min. This was the definitive variant, since this charger family applies some settings only on boot (troubleshooting #4).

MacEnabled reverted to false afterwards. Whatever that key does, it is not Autocharge-style idTag forwarding — despite the charger demonstrably holding a DC handshake with the car (it reports the car's SoC). The EVCCID/VIN exists inside the charger but firmware 1.24.0620.1 never surfaces it over OCPP.

[!note] Confirmed: the charger has the VIN (owner observation, 2026-07-09) The touchscreen displays the chassis number (VIN) of Chinese cars — direct proof the GB/T 27930 BRM handshake delivers the VIN to the charger. The identity dead-ends at the UI; it's purely an OCPP-mapping gap in the firmware, not a hardware limit. Two long-shot future leads: (1) a firmware update; (2) the writable, empty DataTransferVendorId config key — setting it might make the charger emit vendor-specific DataTransfer frames (which station.py already logs) that could include the VIN.

Consequence: vehicle-based auth is off the table. Households authorize via RFID cards ✅ and the app remote-start ✅ — both verified. (If a future firmware update changes this, retest with the same three steps.)

3. Mobile / web app — ✅ control path verified live (2026-07-09)

The exact calls the app will make were proven on the real charger with a car plugged in: RemoteStartTransaction(connector=1, idTag="app-remote") → Accepted → StartTransaction → Charging; RemoteStopTransaction(tx) → Accepted → StopTransaction (reason: Remote). Both guns ran simultaneous transactions (card on gun 2, remote on gun 1). The app-remote idTag is enrolled in the allowlist as kind:"app". What remains is only the UI:

A mobile-friendly web control panel (no app store):

  • Start/Stop via OCPP RemoteStartTransaction / RemoteStopTransaction
  • Live charger status
  • Clickable allowlist management
  • Bound to 0.0.0.0, reached only over netbird; optional PIN/token for defense-in-depth (❓ open decision, see overview)
  • Must be per-gun: the charger has two connectors (2026-07-09-discovery-eu092025)

Who may control what — API users & scopes (built 2026-07-11)

The backend now has real multi-user authorization on top of the three methods above, because not every household member may control everything. Requirement (owner, 2026-07-11): some users control gun 1 only, some gun 2, some only certain wifi-relays.

  • Users live in the settings table of backend.db: username + PBKDF2 password hash + scope list + a personal id_tag (app-<name>) used for their remote starts, so charging sessions are attributable per person. The app idTag is NOT an allowlist entry (2026-07-12): decide() validates it against the user record directly and enforces the user's gun scopes; the Cards page shows only physical cards.

  • Login: POST /api/login (username/password) → 30-day HMAC-signed session, delivered as an HttpOnly cookie (for the PWA) and as a bearer token (for curl). Stateless — survives backend restarts; deleting a user kills their sessions.

  • Scopes (fnmatch wildcards work):

    Scope Grants
    charger:eu092025:1 start/stop/unlock gun 1
    charger:eu092025:2 same for gun 2
    relay:<name> / relay:* switch those relays (others are invisible to the user)
    admin everything, incl. cards (pending review, allowlist), user CRUD, relay/charger registry, setconfig, events
  • Bootstrap: zero users = open API (startup warns loudly). First user: venv\Scripts\python -m backend.users add <name> --scopes admin.

  • Admins grant permissions in the panel’s Users page as a checkbox matrix (per gun, per relay, admin) rendered from GET /api/permissions — nobody types raw scope strings.

  • ✅ Verified by the 54-check smoke test (login, wrong password, cookie + bearer, per-scope 403s, relay visibility filtering, user CRUD, session invalidation on delete). ⚠️ Not yet exercised from a real phone browser.

This resolves the ❓ "web app auth" open decision in overview: username+password with per-resource scopes, chosen over plain tokens by the owner.

Audit: who charged, and how

Every session row records the method: card (physical RFID tap) or app (in-app button press), derived from the allowlist entry’s kind at StartTransaction, plus the resolved who (card owner / username). The panel’s History tab shows Who · Via · Gun · When · Duration · kWh. (2026-07-11, owner requirement.)

Facts from the live probe that shape this design

Per 2026-07-09-discovery-eu092025: AuthorizeRemoteTxRequests=false, so remote starts don't trigger a separate Authorize — the decide() gate fires when the charger sends StartTransaction. The on-charger offline allowlist (LocalAuthList) holds max 6 idTags and is currently disabled; enough for a household if we ever want tap-to-charge to survive CSMS downtime.