Per-person, per-item command permissions for openHAB — client certs + reverse proxy + ACL gateway

Why I built this

I wanted to open the openHAB Main UI to the whole family, but only let the kids switch a handful of items. Seeing everything is fine; switching the heating, the front door or a sibling’s lights is not.

openHAB core has two roles (administrator and user) and no per-item permissions; custom roles with visibleTo only hide widgets. Anyone with the user role — or anonymous clients when implicitUserRole is on — can send commands to every item, update states, run rules via /rest/rules/{uid}/runnow and talk to the voice interpreters. There is also no record of who sent a command; the event log only says it came from the UI.

So I put the permission check in front of openHAB instead of inside it: a small ACL gateway between the reverse proxy and openHAB. Every family device already has its own TLS client certificate, so the proxy knows who is calling and passes that on. The gateway logs every UI command per person and, optionally, blocks commands an item does not allow.

My setup: openHAB 5.2.0 and everything around it in Docker, nginx for TLS/mTLS, Traefik as path router. The ideas should carry over to other proxies.

Related work

This is not the first proxy-based approach. Detailed access control and user management by reverse proxy started in 2019 with Apache and per-sitemap filtering. Later in that thread, florian-h05 introduced openhab-multiuser-proxy (nginx + mTLS + NodeJS), now continued as davek145’s fork for openHAB 3/4 and the Main UI. It identifies users by client cert and grants access with acl: tags on items and pages — the same basic idea as mine.

The difference is scope. The multiuser-proxy filters what each user can see: items, pages, sitemaps and the SSE stream, which means covering a long list of API paths. I deliberately let everyone read everything and gate only writes. That keeps the gateway small and leaves room for a few things I needed:

  • allowed commands and numeric ranges per item, not just allowed items
  • every other write path (rule runnow, state updates, voice, WebSockets) blocked outright
  • an audit-only mode and a per-person command log, with the person passed to openHAB as the command source

How the request flows

Only writes from family devices take a detour through the ACL gateway; reads, the SSE live updates and everything else go straight to openHAB as before.

  1. nginx terminates TLS with ssl_verify_client optional. Two maps turn the client-cert fingerprint into a person and an access class: admin (the parents’ devices), user (any other valid cert, i.e. the kids), trusted (internal IPs), none. Both go upstream as X-Access-Class / X-Access-User and are always overwritten, so a client cannot set them. For class user, nginx also drops the Authorization header, so a kid cannot smuggle in an API token.
  2. Traefik has two extra routers just above the openHAB catch-all. Family devices: every non-GET/HEAD request and every WebSocket upgrade goes to the gateway. Admin devices: only POST /rest/items/<item> goes to the gateway, for logging.
  3. The ACL gateway checks the request and forwards allowed commands to openHAB with ?source=org.openhab.ui$<person>.
  4. openHAB has no published ports. Like everything else it runs in a container and is reachable from outside only through nginx and Traefik, so the gateway cannot be bypassed.

What the ACL gateway does

The gateway is an allow-list: a family device may send item commands only where the item’s acl metadata names that person, and nothing else that writes.

Implementation detail: mine is a HABApp rule of under 200 lines on a small aiohttp webserver I had already added to my HABApp setup for webhooks and views, so it was the quickest place to put it. Nothing in the concept depends on it. A small sidecar container in any language would do the same job: take the HTTP request, read the item’s metadata from the REST API, forward or refuse.

For each request it does this:

  • POST /rest/items/<item> — an item command. Admin devices always pass. For family devices it reads the item’s acl metadata and checks the person, then the allowed commands or numeric range. Allowed commands go to openHAB with source=org.openhab.ui$<person>, so the event bus shows who sent them.
  • POST /rest/events/states/<connectionId> — the Main UI uses this to tell openHAB which items it wants on its SSE stream. It is read-only, so it passes.
  • Everything else — rule runnow, state updates (PUT /rest/items/<item>/state), WebSockets, voice, any admin API — gets a 403 and an ui_blocked log line.

Denied commands come back as a 403 in openHAB’s own error JSON, so the Main UI shows a normal error toast. The gateway fails closed: if it is down, family devices cannot switch anything, but they can still see everything.

Permissions live on the item, in a metadata namespace acl:

# value: people or groups, comma-separated, or "*" for every family member
# config (optional): allowed commands, or a numeric range
value: "kid1"                    # only kid1 may switch this light

value: "kids"
config: { commands: "ON,OFF" }   # no dimming, just on/off

value: "*"
config: { min: 16, max: 23 }     # any family member, setpoint 16–23 °C

Groups and the audit switch are plain config (in my case a HABApp params file):

openhab_gate:
  enforce: false        # false = audit only: denials are logged, the command still passes
  openhab_url: http://openhab:8080
  groups:               # people as named by nginx's $cert_person map
    kids: [kid1, kid2]
    parents: [parent1, parent2]

The core of the check, in Python. The only HABApp-specific call is self.async_oh.get_item, which fetches the item with its metadata from openHAB:

async def _check_acl(self, person: str, item_name: str, command: str) -> str | None:
    """Return why a family member may not send this command, or None if allowed."""
    if not person:
        return "unknown device"
    oh_item = await self.async_oh.get_item(item_name)
    if oh_item is None:
        return "unknown item"
    acl = (getattr(oh_item, "metadata", None) or {}).get("acl")
    if acl is None:
        return "no acl metadata"

    principals = {p.strip().lower() for p in str(acl.get("value", "")).split(",") if p.strip()}
    if not ("*" in principals or person in principals
            or any(person in self._groups.get(p, ()) for p in principals)):
        return f"{person} not in acl '{acl.get('value', '')}'"

    config = acl.get("config") or {}
    # ... then the optional `commands` list and `min`/`max` range
    return None

Two things keep the identity headers honest. nginx always overwrites them, and clears them on port 80 and on the public tunnel ingress. The gateway also answers 403 to any request that carries X-Access-* headers but does not come from the Traefik container.

Audit mode first. I ran with enforce: false first. Every command is logged with decision=allowed|would_deny|denied, but nothing was blocked yet. That showed me what the kids actually use before I write the ACLs, instead of guessing and breaking their favourite switch.

Seeing who switched what

Every UI command now ends up as one logfmt line, which turned out to be the most useful part so far. The gateway logs it, HABApp ships it to Loki via GELF, and a Grafana dashboard shows it per person. Three made-up example lines:

ui_command person=kid1 access_class=user item=LivingRoom_Light label="Wohnzimmer Licht" command=ON decision=would_deny reason="no acl metadata" status=200
ui_command person=parent1 access_class=admin item=Heating_Mode label=Heizung command=AUTO decision=allowed status=200
ui_blocked person=kid2 access_class=user method=POST path=/rest/rules/abc123/runnow reason="not an allowed write request"

The dashboard has four panels: commands per person for the selected range, commands over time, a table of every command (person, item, label, command, decision), and the blocked non-command requests. Its Loki query is short, because logfmt does the parsing:

{host="HABApp", logger="RuleLoggers.OpenhabGate"} |= "ui_command"
  | json msg="short_message"
  | line_format `{{ trimPrefix "ui_command " .msg }}`
  | logfmt
  | person=~"$person" | decision=~"$decision"

The source=org.openhab.ui$<person> parameter also puts the person into openHAB’s own event log, so any rule that looks at the command source can tell who it was.

Lessons learned and limits

  • Everything runs in containers, nginx is the only way in. openHAB, the gateway, Traefik and the rest run in Docker. openHAB has no published ports; from outside, the only entry point is nginx with mTLS. That is what makes the gateway a real checkpoint.
  • Know the write surface. I traced what the clients actually use. The Main UI and the native iOS app get live updates via SSE (/rest/events/states) and send commands only as POST /rest/items/<item>. WebSockets (/ws) were only used by HABApp, my MCP tooling and the admin log viewer. That made a short allow-list possible.
  • implicitUserRole is wider than it sounds. Without a login, the user role can send commands, update states, run rules and use the voice interpreters — with an LLM-backed interpreter, that is quite a lot. With the gateway in front, none of that is reachable from a family device.
  • The identity is only as good as the cert. A lost phone carries that person’s rights until I remove its fingerprint. Internal IPs (trusted) and admin devices are never restricted, only logged.
  • It fails closed. If the gateway is restarting, the kids cannot switch for a few seconds. That is the trade-off I want.
  • The UI does not know about the ACLs. A kid still sees every switch, and a denied tap shows an error toast. For us that is fine; reading is explicitly allowed.

Next steps: watch the audit dashboard for a week or two, write the acl metadata from what the kids actually use, then switch to enforce: true.

Questions for you

  • To the people behind openhab-multiuser-proxy: is gating only writes enough in your households, or what made you filter reads as well?
  • Did I miss a write path the user role has? Basic UI and sitemaps are the ones I have not traced.
  • visibleTo with custom roles was suggested for hiding widgets. Does that work for clients that are not logged in to openHAB, where the identity comes only from the proxy?
  • Is per-item authorization planned anywhere in openHAB core?
  • Would a cleaned-up, standalone version of the gateway (a small sidecar container plus example proxy configs) be useful to anyone?

Happy to share more config or answer questions.

Just a hint:
The OpenHabItem already carries the metadata.
So there is no additional request needed, you can just look it up on the local item.

Yes. When the implicit user role is enabled access without credentials is under the user role. When that is disabled no access is allowed until a user logs in. So if you set visibleto to not show something to the user role, it won’t appear to non-logged in users.

There is an issue an PR open to implement RBAC in core. I don’t know it’s status but as of a month or so ago there was activity on it.

Hi Dominik,

someone in my own thread pointed me here, and I’m glad they did. We’ve been working on the same problem from two sides.

You limit what family members may switch; I limit what AI agents may do in a home.

I wrote that down as an open spec:
https://github.com/home-mandate/spec/blob/v0.1.0-rc.2/SPEC-v0.md

The overlap is striking: allowed commands per item, a numeric range per command, deny everything else, fail closed, and above all your lesson that the gate only works because it’s the only way in. That last point was an unwritten assumption in my spec until this week; it’s now an issue (Security considerations: the PEP must be the agent's only path; writing scripts and automations bypasses every mandate · Issue #26 · home-mandate/spec · GitHub), and your list of write paths in openHAB (item commands, state updates, `runnow` for rules, WebSockets, voice) is the best description of that surface I’ve seen.

Two things that might be interesting for your setup:

  • Ask instead of deny. Besides allow and deny, my rules have a third answer: a parent confirms on their phone first. “The kids may raise the heating, but only after one of us says yes” would fit that.
  • Audit mode. Your enforce: false is a good idea that I don’t have yet. I’ll take it for my gateway, letting a new rule set run in “would deny” mode before it blocks.

And a question back, if you have a minute: could your acl metadata (people or groups, allowed
commands, min/max) be expressed as a mandate in the spec (section 3), and where wouldn’t it fit?
The answer would tell me a lot about whether the format really works outside Home Assistant.

Full disclosure: the spec and a gateway for Home Assistant are mine, both open source. No pressure to answer here; my thread or GitHub (Review v0.1 · home-mandate · Discussion #24 · GitHub) work just as well.

@Spaceman_Spiff thanks, good point. The rule now looks up the metadata on the local item instead of making an extra request.

Hi Markus,

thanks for getting in touch, and for the credit in #26. I read the spec (mostly §3–5 and §9) and your thread with Rich.

Agents as just another principal. I hadn’t seen my gateway this way before, but it fits. The gateway doesn’t care who sits behind a client cert. An LLM-backed voice interpreter or an MCP server could get its own cert and its own entry in nginx’s person map. It would land in the restricted class, and acl metadata would name it like a family member. I’d like to try that. In my own setup I’m also an example for #26: my MCP tooling talks to openHAB with its own API token, past the gateway. That’s fine for an admin tool I sit in front of, but it’s exactly the “path past the PEP” you describe.

Can my acl be written as a mandate? I went through the ACLs I actually have. Most fit, some don’t.

Fits well:

  • Plain per-item permissions (“kid1 may switch this light”, “the kids may switch the ground-floor lights group”) → entity_id plus turn_on/turn_off, allow.
  • On/off only, no dimming → allow turn_on/turn_off, leave out set.
  • A reading-light dimmer that must never go fully off → light.set with brightness 1–100 and no turn_off. Nice fit.
  • Door opener, smart lock and garage door that the kids may use → works with allow_critical and explicitly listed actions. In my case that’s a deliberate choice: the kids come home on their own.
  • My “room lights” helper item, which switches a list of target items in one command: I check every target, and one denial blocks the whole command. That’s your §4.4.
  • Deny by default, allow-list, fail closed: identical.

Doesn’t fit:

  1. Lists of allowed values. Several of my ACLs are lists of allowed commands, not ranges:

    • a String item for the EV charge mode (PV,BOOST)
    • a scene Number item (0,1,2)
    • a WLED preset

    In the spec these all end up in other.set or scene.activate, which are critical and take no parameters. Even climate.set_mode can’t be limited to particular modes. In my experience, “this item, but only these values” is the most common case after plain on/off.

  2. Ranges outside the vocabulary. I limit a price threshold (0–60 ct/kWh) and a minimum battery SoC (5–100 %). Neither has a vocabulary parameter, and the price can have fractions. In openHAB almost anything is a Number item, so a generic “numeric value of this item” parameter would cover much of this.

  3. Groups of people. My ACLs name kids, parents or * far more often than single people. A mandate is per (agent, principal), only one applies at a time, and nothing is inherited from household to person. So my ACLs would have to be compiled into one complete mandate per kid, or per device if the device is the agent. That works, but people write and read their ACLs on the item. That’s partly a tooling question, but groups of principals would help.

  4. Audit mode and the log format. If you adopt enforce: false, the audit schema needs a place for it. Right now result.status only allows executed, denied and failed. I log decision=would_deny and the command still runs. If that should go into the log format, it would need to happen before the freeze.

  5. Profile details (you may have these from Rich already):

    • openHAB Rollershutter 0 means fully open, while position is “percent open”, so the gateway has to invert it.
    • Dimmer INCREASE/DECREASE and Player NEXT/PREVIOUS have no matching action.
    • Colour items are missing (I see #29).

“Ask”. I don’t need it right now. For kids, a confirmation per tap would wear us out quickly. And the Main UI can’t wait 10+ seconds for an answer anyway, so it would have to answer “waiting for approval” and switch later. What I would find useful is a request for a standing permission. A kid taps “may I use this?” on an item, a parent approves on their phone, and the item’s ACL gets that kid added for good, or until a set date. That’s a more convenient way to edit ACLs than me doing it by hand. In mandate terms it would be a principal requesting a rule change that a human approves and the log records as a mandate update, rather than a single approved command. I don’t know if that belongs in the spec, but it might fit the template/mandate-update part of §9.

I’m happy to keep comparing as the format settles. If a more detailed mapping of the openHAB command types (Switch/Dimmer/Rollershutter/Player/String/Number) to the vocabulary would help the profile, I can write that up on the PR.

Hi Dominik,

first of all: thank you. You didn’t just read the spec, you went through your real ACLs one by one and checked each against it. That’s the most valuable kind of feedback I could get, and I really appreciate the time and care you put into it.

It’s already changed things. Two of your findings go into the format before I freeze it:

I’d planned the freeze for the end of October, but that’s a date I set myself. With input like yours I’d rather move it than freeze something that’s half right.

Two more ideas of yours are now issues for the next version:

Your MCP tooling with its own API token is a perfect real-world example of #26, by the way. I’ll use it there, if you don’t mind.

On groups of people: in the spec the principal is the household and the agents are what gets limited, so “kids” and “parents” would mostly be a question of how a tool compiles and shows the rules. I agree that people want to read their permissions on the item, not in a separate document per person. That’s a good point for anyone building an editor.

Your offer on the profile: yes, please, I’d be very glad. A short word on what a profile is, because the name doesn’t say much: it isn’t part of the specification itself. It’s a description of how Home-Mandate connects to another product, in this case openHAB: which openHAB identifier becomes which identifier in a mandate, how Items, Equipment and tags map to the categories, and which openHAB command stands for which action. Someone building a Home-Mandate gateway for openHAB would read it to know how to translate between the two. The draft is here, already with Rich’s review: docs: openHAB profile (draft) by markusmazurczak · Pull Request #30 · home-mandate/spec · GitHub. A mapping of the command types (Switch, Dimmer, Rollershutter, Player, String, Number) to the vocabulary is exactly what it needs. Comments or suggestions on the PR are perfect.

One detail where you and Rich might see it differently: you wrote that a Rollershutter at 0 means fully open, Rich that it isn’t consistent across bindings and integrations. My guess is that openHAB defines 0 as open and some bindings or integrations invert it. If that’s right, the profile would follow openHAB’s definition and treat an inverted Item as a misconfiguration. Does that match what you see?

Thanks again, really.
Markus

Hi Dominik,

a short update, because two of your findings are now in the specification: release candidate v0.1.0-rc.3 is out (Release v0.1.0-rc.3 · home-mandate/spec · GitHub).

  • Permitted values (#32): a rule can now say “only these values”, one_of, for numbers and for strings. Parameters can be strings now, and the vocabulary checks them: climate.set_mode can be limited to, say, heat and auto, never off (section 4.5).

  • Audit mode (#33): a mandate with "enforce": false is tried. What its rules would deny is carried out anyway and logged as not enforced, so you see what it would block before it does (section 4.6). On your question, I went with yes: critical actions stay enforced in audit mode, and so do confirmations, the rate limit and the emergency stop. A trial never unlocks a door the mandate doesn’t allow. Switching audit mode on also needs a human to confirm exactly that version, and the approvers are told, because it weakens the mandate.

Your other examples, the charging mode, scenes and the WLED values, need one more piece:

a generic value for items without a category of their own (#35, Vocabulary: a generic numeric value for other.set · Issue #35 · home-mandate/spec · GitHub). That’s planned for v0.2, together with next and previous for media players (#49). The string parameters of rc.3 are the groundwork for it.

Thanks again for the careful look. It made the format better.

Markus

Hi Dominik,

the Home-Mandate specification reached v0.1.0 today, so the formats are frozen: a mandate that is valid now stays valid and is evaluated the same way by every later v0 release.

Two things in that frozen format exist because you went through your real ACLs and told me what didn’t fit:

  • Lists of permitted values: a rule can say “only these values” with one_of, for numbers and for strings.
  • Audit mode: a mandate can be tried first, and the log records what it would have denied. It got one more fix after rc.3: if a rule would deny a request and another rule says “ask”, the request now asks first instead of simply running. Critical actions stay enforced in audit mode.

The generic value for items without a category of their own (#35) didn’t make this release. It’s still planned for the next version, along with your standing-permission idea (#34).

Moving the freeze for feedback like yours was the right call. Thank you for the time and the care.
Spec: Release v0.1.0 · home-mandate/spec · GitHub
Markus