Technical plan referred to in my previous post.
Technical plan for HA Core devs: a hybrid authorization architecture (click to expand)
This technical plan was written with heavy help from Claude Fable 5.2 MAX (Anthropic) with a 1M token context window, which analyzed and searched a complete copy of the full core source tree at commit 5ef31b7, analyzed the permission related parts in detail. I decided the structure and the extent of the gap analysis myself, and I have reviewed the content. Please treat the architecture design parts as a starting point for discussion rather than finished work. [It cost me a full day of usage quota, so consider it my contribution to the Month of WTH.]
TL;DR
This is a purely technical proposal. It says nothing about priorities, funding or who should do the work. It only answers: if core wanted per-user access control, what could the architecture look like and how could it land without breaking anyone?
- Core already enforces entity policies on service calls and on most state reads. The work is closing a known list of gaps, not building from zero.
- One
authorize() function in front of the checks core already does. The natural place is ServiceRegistry.async_call plus the two admin decorators.
- Three evaluators behind it: relations (who may touch which entity), capabilities (what a script may do on a user’s behalf) and conditions (when a grant is valid).
- No policy configured means exactly today’s behaviour.
- Six small phases. Each can merge and ship alone. The first two change no behaviour for existing installs.
Two open problems could change this plan: user-aware template rendering and calls that carry no user. Both are described in their own section below and should be answered before phase 3 is promised.
All code references are to commit 5ef31b7 (dev, 2026-11-11).
Scope and threat model
The design protects against people with a valid login who use the normal clients: family members, guests, a cat sitter.
In scope: service calls, state reads and subscriptions, history and logbook, templates rendered for a user, WebSocket and REST commands, the companion app, scripts and automations as actors.
Out of scope: code running inside the core process. Integrations, custom components and apps stay trusted. Authorization is not a sandbox. Also out of scope: authentication, SSO, multi-tenant hosting and a finer split of admin rights (see the admin section).
What core has today
The entity policy model is real and enforced in more places than the developer docs suggest. The gaps are specific and listable.
Already in place
| What |
Where |
Behaviour |
| Policy format |
entities.py L15-L44 |
Keys entity_ids, device_ids, area_ids, domains, all. Values read, control, edit. Only True is valid |
| Precedence |
entities.py L100-L105, util.py L72-L77 |
Entity, then device, then area, then domain, then all. First answer wins |
| Group merge |
merge.py L26-L32 |
Most permissive wins |
| Entity services |
service.py L711-L718, L662-L681 |
Non-admin with a user_id: explicit target without control raises, “all” targets are filtered |
| Admin services |
service.py L1010-L1014 |
is_admin or Unauthorized |
| State reads |
commands.py L403-L414, L157-L170, api L219-L226 |
get_states, state events and REST states are filtered on read |
| History |
history/websocket_api.py L143 |
Filtered through filter_entity_ids_by_permission |
Verified gaps
Architecture
One decision function with three evaluators and today’s checks as the fallback. It is one pipeline and not three access control systems.
enforcement points
ServiceRegistry.async_call every service call, entity or not
websocket / http require_admin admin commands and views
read helpers states, events, history, logbook, templates
|
v
authorize(request)
|
+-- 1 relation evaluator who may touch this resource ALLOW / DENY / ABSTAIN
+-- 2 capability evaluator may this principal do this call ALLOW / ABSTAIN
+-- 3 condition evaluator is the grant valid right now can turn ALLOW into DENY
+-- 4 legacy adapter today's check_entity / is_admin used when all abstain
|
v
decision + reason code --> audit log
The request
@dataclass(frozen=True, slots=True)
class AuthzRequest:
actor: str | None # user_id that started the chain, None = system
principal: str | None # entity_id of the script or automation executing, None = the actor
action: str # "read", "control", "edit", "call:mqtt.publish", "admin:<op>"
resource: tuple[str, str] # ("entity", id), ("service", "domain.name"), ("config", key)
attrs: Mapping[str, Any] # rendered service data and resolved targets
Resolution rules
- A
DENY from any evaluator wins.
- If every evaluator abstains the legacy adapter decides. This is what makes “no policy” identical to today.
- A capability
ALLOW may lift an admin-only restriction only for services registered as delegable.
- Admins and the owner short-circuit to
ALLOW exactly as now.
- In enforced mode an evaluator error means
DENY. In shadow mode it means the legacy result plus a log entry.
Why ServiceRegistry.async_call
Every call builds its ServiceCall in one place (core.py L3012-L3014). A check there covers the 359 generic service registrations that have no check today, without touching one integration. The entity resolver keeps doing the per-entity filtering it already does.
The three evaluators in one line each
- Relations (ReBAC): the existing entity policy, extended with deny, labels and a services category. Details under policy semantics.
- Capabilities (CapBAC): a grant attached to a script or automation that names exactly which privileged call it may make. Details under carrying the principal.
- Conditions (ABAC):
valid_until on a group membership or a grant. Time windows later. No state based conditions in the first version because the state can change between check and execution.
Does the hybrid hold together?
Yes, on one condition: the three models are inputs to one function and share one request type. Built as three subsystems it would not be worth the cost. Relations cover nearly every request in the forum thread. Capabilities are the risky part, so they come late and only for services that opt in.
Carrying the principal
Recommendation: add an optional principal to ServiceCall and leave Context alone.
Today a service call knows only context.user_id and context.parent_id (core.py L1348-L1364). It cannot tell “Emma called this” from “a script Emma started called this”.
| Option |
How |
Verdict |
A. Field on Context |
Context.principal |
Rejected. A script reuses the caller’s Context object for all its actions, so it would need a child context per run. That changes the id chain the logbook uses for attribution, and Context is serialised into events |
B. Field on ServiceCall |
hass.services.async_call(..., principal="script.open_garage") |
Recommended. Never serialised, never accepted from a client, two call sites to change |
C. Infer from parent_id |
Walk the context chain |
Rejected. Ambiguous and forgeable by anything that can create a context |
What option B touches:
Rules:
actor is always context.user_id. principal defaults to the actor.
- A nested script sets its own principal. Nothing is inherited.
- Device actions and events fired by a script carry no principal and are judged on the actor alone. That is the safe default.
- In-process code can pass any principal. That is accepted: such code can already call with no user and skip every check.
Capabilities, in two steps
Step one is coarse and cheap: an admin marks a script as elevated. Its actions are then judged as if no user were present, which is exactly how automations behave today. It makes the existing input_button plus automation workaround explicit and auditable.
Step two is fine grained grants, for scripts that take input:
# stored per script entity, editable by admins only
grants:
- service: mqtt.publish
data:
topic: garage/door/set
payload: OPEN
retain: false
- Matched against the rendered service data at call time. Templates are never analysed statically.
- Needs an opt-in at registration, for example
async_register_admin_service(..., delegable=True).
- “May run the script” needs nothing new. It is
control on the script entity.
Policy semantics
Keep today’s allow logic byte for byte and add deny as a separate layer that always wins.
Today: each group has an allow policy, a user’s policy is the most permissive merge of their groups, and lookup goes entity, device, area, domain, all with the first answer winning. That cannot express a deny, and making False a value inside the same tree would fight the “most permissive wins” merge.
Proposed evaluation for a non-admin user:
- Collect
deny rules from all the user’s groups (union).
- If any deny rule matches the entity at any level for this permission:
DENY.
- Otherwise run the existing allow logic unchanged.
# group "kids"
policy:
entities:
area_ids:
emma_room: {read: true, control: true}
label_ids:
shared_lights: {read: true, control: true}
deny:
entities:
domains:
camera: {read: true, control: true}
services:
allow: [script.turn_on, light.turn_on, light.turn_off]
Design choices:
- Deny always wins. A narrow allow does not override a broad deny. It is order independent and easy to explain. The cost is that “deny the garage except one light” needs the light left out of the denied set.
- Two ways to scope. “Only her room” is a group with a narrow allow and no membership in Users. “Everything except cameras” is Users plus a group with a deny. Both are needed.
- Labels join areas and devices as a key. They are the only way to scope entities that have no device.
- Area lookup needs a fix.
_lookup_area returns nothing for an entity without a device and ignores an area set on the entity itself (entities.py L53-L69). Helpers placed in an area would be invisible to an area policy.
- Services category. Generic services have no entity to check. A scoped group lists the ones it may call. The Users group keeps “all” so nothing changes for existing users.
- New entities follow their scope. In a scoped group they stay invisible until placed in an allowed area or labelled.
- Admins are untouched. Deny rules never apply to an admin or the owner.
Read paths
Most state reads are already filtered. Four paths found so far are not, and templates are the hard one.
| Path |
Today |
Plan |
get_states, subscribe_entities, state events |
Filtered on read |
Route through the facade, no behaviour change |
REST /api/states |
Filtered |
Same |
| History (WebSocket and REST) |
Filtered |
Same |
| Logbook stream and query |
No permission check found |
Filter entries by entity read |
render_template over WebSocket |
No check |
See below |
| Entity registry list |
Unfiltered |
Filter to readable entities for non-admins |
| Camera and image proxy |
Any authenticated user |
Check read on the entity when the request is authenticated by user and not by token |
| Device and area registry, statistics, calendar, todo, media browsing, search |
Not surveyed |
Phase 0 inventory |
Templates. The frontend renders templates for ordinary users, so making the command admin only would break dashboards. The template engine has no notion of a user. The proposal is a read filter bound to the render: when a render is started on behalf of a non-admin user, state lookups for entities without read behave as if the entity did not exist. Templates rendered by scripts, automations and template entities are not affected because they run without a user. This is the largest unknown in the plan and needs a prototype before anyone commits to it.
Cost. The state stream check runs per event per connection. It is already there for non-admins (commands.py L157-L170) and uses the compiled function cached on the permissions object. Deny adds one more compiled predicate. Admins keep the short circuit.
Storage and migration
Put everything new in a separate store and leave .storage/auth at version 1.
Groups and their policies live in the auth store (auth_store.py L28-L29). A user holds a plain list of group ids.
| Data |
Where |
Why |
| Custom groups with allow policy |
Existing auth store, existing format |
Already supported on load. Only the API to create them is missing |
| Deny rules, labels key, services category |
New store, keyed by group id |
An older core never sees keys its schema would reject |
| Membership expiry |
New store, keyed by user id and group id |
The user record keeps its plain list |
| Elevated flag and grants |
New store, keyed by entity registry id |
Survives entity renames and keeps the script YAML schema untouched |
Consequences to accept:
- Downgrade fails open. An older core ignores the new store, so deny rules and expiry stop applying. This must be stated in the release notes. A repair issue on the next upgrade can remind the admin.
- Rollback inside one version is deleting the policy in the UI. No policy is today’s behaviour.
- Deleted entities, groups and users need a cleanup listener so the new store does not keep dangling ids.
The admin side and the frontend
Admin stays binary in this plan. Splitting it is a separate project. What the facade does is give every admin check a name instead of a bare boolean, for example admin:config_entries.edit. The HTTP decorator already accepts perm_category and permission (http/decorators.py L50-L53) and the config entries views use them. Naming the checks costs nothing now and is what a later “may edit dashboards” or “may edit automations in area X” would be built on.
What the frontend needs
| Need |
Today |
Proposal |
| Know who the user is |
auth/current_user returns is_admin (auth/__init__.py L616) |
Unchanged |
| Hide what cannot be read |
Filtered states mean the entity does not exist for that client |
Nothing new. Cards already handle a missing entity |
| Disable controls on read only entities |
Not possible |
New command auth/permissions returning the user’s compiled scope, or a can_control flag in the entity subscription |
| Explain a refusal |
Unauthorized without a reason |
Reason code from the facade in the error |
| Manage groups and policies |
Hand editing .storage/auth |
Admin only WebSocket commands for group and policy CRUD plus a settings page |
The companion apps use the same WebSocket API (mobile_app/helpers.py L125-L127 builds a context with the registration’s user) so they inherit the backend decisions. The frontend is never the control.
Worked examples
A child controls only her own room. Emma is in group “kids” and not in Users. The group allows read and control on area emma_room. light.emma_ceiling resolves to that area: ALLOW. light.noah_desk has no match: denied and filtered from her state stream, history and logbook.
Everything except the cameras. A teenager stays in Users and is added to a group with a deny on domain camera. The deny layer answers first. The camera proxy applies the same check.
A dashboard button that publishes MQTT.
Emma presses the button
actor=emma principal=- control script.open_garage ALLOW relation
script.open_garage runs
actor=emma principal=script call:mqtt.publish topic=garage/.. ALLOW grant matches, service delegable
Emma calls mqtt.publish herself
actor=emma principal=- call:mqtt.publish anything DENY legacy: admin only
A cat sitter for one week. The sitter’s membership in “cat care” has valid_until. After that date the condition evaluator turns every ALLOW from that group into DENY. The login still works and shows an empty home.
Two problems that could change this plan
The first is a technical risk: can it be built? The second is a design gap: what should the rule be? Neither is solved here.
1. Templates can read any state
- What the code shows. The WebSocket command
render_template has no admin check and no entity check (commands.py L804-L816). Its REST twin is admin only (api L503). A scoped user can send {{ states('camera.front_door') }} and read around every other filter.
- Why the easy fix is unlikely to work. Making the command admin only would probably break dashboards, since the frontend renders templates for ordinary users. How widely it does so is not verified here.
- What is needed. The template engine has to know on whose behalf it renders, and it has no such notion today. The proposal is a read filter bound to the render so that entities without
read behave as if they did not exist.
- What is unknown. Whether that can be done cleanly in the template state objects, what it costs per state access and what it breaks. It needs a prototype and a benchmark.
- If it cannot be done. Phase 2 has a hole that cannot be closed and scoped accounts are not safe to offer.
2. Calls without a user are fully trusted
- What the code shows. Both permission checks sit under
if call.context.user_id (service.py L711 and L1010). No user means no check.
- Who calls without a user. Automations always do (
automation/entity.py L486-L487). A voice satellite falls back to an empty context (assist_satellite/entity.py L499). Anything triggered from outside without a login, such as a webhook trigger, ends up in an automation.
- Why it matters. A scoped user who can trigger one of these acts with full rights. Emma may control only one input_button, but the automation behind it can do anything. Anyone in the room speaks to the satellite with full rights.
- What is defensible. Automations: an admin wrote them, so the admin granted it. The UI should still show which automations a scoped group can trigger.
- What is not. Voice. It needs a rule, for example a scope per satellite (“this device may control this area”), which fits the relation model but is not designed here.
- What is needed. A decision per source: does it map to a user, to a device scope or does it stay trusted? Until then per-user scoping is easy to walk around.
Rollout in phases
Each phase is useful alone and none depends on a later one being accepted.
| Phase |
Change |
Who notices |
Proof it is safe |
| 0. Inventory |
Complete the gap tables above for every component that returns state or media. Add a lint rule that flags new direct is_admin and check_entity calls |
Nobody, no runtime code |
The list itself |
| 1. Facade |
authorize() with only the legacy adapter. Call it from ServiceRegistry.async_call, both require_admin decorators and the read helpers. Reason codes and an audit hook |
Nobody |
Differential test: old and new decision compared across the whole test suite |
| 2. Close read gaps |
Logbook, entity registry list, camera and image proxy, template read filter |
Only users already in a hand made custom group |
Existing tests plus one test per closed path |
| 3. Relations |
Deny layer, labels, area lookup fix, services category, group and policy API, settings UI, shadow mode per group |
Only users an admin places in a custom group |
Shadow log shows what would be denied before it is enforced |
| 4. Capabilities |
principal on ServiceCall. Elevated flag first, grants and delegable second. Pilot: mqtt.publish |
Only scripts an admin marks |
Adversarial tests: templated data, nested scripts, parallel runs |
| 5. Conditions |
valid_until on memberships and grants |
Only where set |
Clock based tests |
Phases 0 to 2 add no new concept. They finish what the 2018 model started and are the part worth an external review. Phase 3 is where users first see a feature.
Phase 3 should not be promised until the two problems above have an answer. Phases 0 to 2 do not depend on them, except that the template filter in phase 2 is itself the first of the two.
Alternatives considered
| Alternative |
Why not |
| External engine as a service (OpenFGA, OPA) |
A network hop on every state event and service call. One more process to run on a Pi. If it is down the home either locks or opens |
| Embedded policy language (Rego, Cedar, Casbin) |
A new dependency and a language no user will write. HA’s graph is small and fixed: user, group, entity, device, area, label. The existing compiled dict policy already fits it |
| Reverse proxy in front of core (ha-rbac) |
Sees requests, not what a script does inside core. Must understand every WebSocket command, and an unknown new command passes by default. Good stopgap, wrong layer for the end state |
| Frontend only hiding |
Not access control. The companion app, shortcuts and the API still reach everything |
| More admin only services |
The mqtt.publish route. Safe but breaks legitimate dashboards because scripts run as the caller |
| All scripts run with the author’s rights |
Simple, and it is how automations work now. But every script becomes an escalation path and nothing records what was granted. Kept as the opt-in elevated flag in phase 4 |
| Replace the policy model with roles |
Roles do not say which lamps. Scope by area and label is what the use cases need and what core already models |
Gap analysis
What this plan still does not solve, ordered by how much it could hurt.
| # |
Gap |
Why it matters |
What would close it |
| 1 |
Template read filter is unproven |
Without it a scoped user reads any state through render_template. It is the one item that could sink phase 2 |
A prototype on the template state objects with a benchmark |
| 2 |
Read surface is not fully mapped |
Device and area registries, statistics, calendar, todo, media browsing, search, traces, diagnostics and notifications are unsurveyed. One missed path is a leak |
Phase 0 as a real deliverable with a test per path |
| 3 |
Calls without a user stay trusted |
Webhooks, voice satellites (assist_satellite/entity.py L499 falls back to an empty context) and automations all skip the checks. A scoped user who can trigger one of them acts with full rights |
Name system principals explicitly. Decide per source whether it maps to a user, a device owner or stays trusted |
| 4 |
Voice has no clear actor |
A satellite in a shared room speaks for whoever is nearby |
A per satellite scope (“this device may control this area”) would fit the relation model. Not designed here |
| 5 |
Automations amplify |
A user with control on one input_button can fire an automation that does anything |
By design, but the UI should show which automations a scoped group can trigger |
| 6 |
Generic services need curation |
359 registrations. A scoped group must list what it may call and nobody knows the safe set |
A reviewed default list shipped with core, or a safe_for_users flag at registration |
| 7 |
Deny always wins may be too blunt |
No exceptions inside a denied set |
Accept for version one. Revisit with real feedback |
| 8 |
Event allowlist leaks metadata |
Registry update events go to every user and carry entity ids (events.py L30-L50) |
Filter payloads for non-admins |
| 9 |
Downgrade fails open |
New restrictions vanish on an older core |
Documented behaviour plus a repair issue |
| 10 |
Grants and user input |
A granted script that forwards a field into the call is a confused deputy unless the grant pins the data |
Forbid wildcards in version one. Lint scripts whose granted call uses a field |
| 11 |
Admin stays all or nothing |
No “teenager may edit her own dashboard” |
Out of scope here. The named checks from phase 1 are the hook |
| 12 |
Apps and ingress |
Per user visibility of apps (post 4 in the thread) lives in the Supervisor integration |
Separate design |
| 13 |
Cost is unmeasured |
Deny adds a predicate on the state stream. The template filter adds a lookup per state access |
Benchmarks in phases 2 and 3 on a large install |
| 14 |
Authentication is untouched |
Trusted networks and shared tablets decide who the actor is before any of this runs |
Out of scope, but a scoped model is only as good as the login in front of it |
| 15 |
No effort estimate |
Deliberate. Any number here would be a guess |
Phase 0 output makes an estimate possible |
Verdict. Relations plus the closed read gaps are low risk and cover most real requests. Capabilities are sound in design but carry the security risk. Conditions are trivial once the rest exists. The two things that could change the plan are gap 1 and gap 3.