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.
This commit is contained in:
+5
-4
@@ -159,11 +159,9 @@ async def charger_start(connector: int = 1, cp: Optional[str] = None,
|
||||
user: dict = Depends(current_user)):
|
||||
target = _cp(cp)
|
||||
need(user, f"charger:{target.id}:{connector}")
|
||||
# remote starts run under the caller's own idTag so sessions are attributable
|
||||
# remote starts run under the caller's own idTag so sessions are
|
||||
# attributable; decide() validates it directly against the user record
|
||||
id_tag = user.get("id_tag") or f"app-{user['name']}"
|
||||
if id_tag not in CONFIG["authorized"]:
|
||||
CONFIG["authorized"][id_tag] = {"name": f"app token of {user['name']}", "kind": "app"}
|
||||
save()
|
||||
status = await _ocpp(csms.remote_start(target.id, id_tag, connector))
|
||||
return {"remote_start": status, "id_tag": id_tag}
|
||||
|
||||
@@ -272,6 +270,9 @@ async def allowlist_put(id_tag: str, entry: AllowlistEntry,
|
||||
need(user, "admin")
|
||||
if entry.user is not None and entry.user not in CONFIG["users"]:
|
||||
raise HTTPException(400, f"cannot link card to unknown user {entry.user!r}")
|
||||
if csms.user_for_tag(id_tag) is not None:
|
||||
raise HTTPException(400, f"{id_tag!r} is a user's app token — it authorizes "
|
||||
"through the user's own permissions, not the allowlist")
|
||||
CONFIG["authorized"][id_tag] = entry.model_dump(exclude_none=True)
|
||||
save()
|
||||
log.info("allowlist: added/updated %r (%s)", id_tag, entry.name)
|
||||
|
||||
Reference in New Issue
Block a user