# Who may publish and read what on the Edge broker. One user per service;
# start.sh makes the password file from .env. A user with no line for a topic
# has no access to it.
#
# Write access is the point of this file. Only ChirpStack may publish an
# application event, and only the gateway bridge a gateway event. Nothing on
# the Edge sends a device command over MQTT (downlinks go through the
# ChirpStack API), so no user may write application/+/device/+/command/+.
#
# Mosquitto does not report a refused action to the client: it accepts a
# SUBSCRIBE and acks a QoS 1 PUBLISH that this file denies, then delivers
# nothing. Test a change by the messages that arrive, not by the acks.
#
# The broker reads this file at start. After a change to this file alone,
# run: docker compose restart mosquitto

# Every user may READ application events, unless a `topic deny` line of that
# user says no (gateway-bridge, health). Do not remove this line, and do not
# replace it with per-user lines only. A session made before the broker had
# passwords has no user name. Until its owner logs in once, only a `pattern`
# line matches it; without one the broker silently drops every event
# published for that session in the minutes after the upgrade.
# (.claude/learnings/bugs/mosquitto-acl-drops-events-for-old-sessions.md)
# Mosquitto warns at start that this pattern has no %c or %u. That is meant.
pattern read application/+/device/+/event/+

# ChirpStack: the integration publishes application events and listens for
# commands; the gateway backend reads gateway events and sends commands.
user chirpstack
topic write application/+/device/+/event/+
topic read application/+/device/+/command/+
topic read us915_0/gateway/+/event/+
topic read us915_0/gateway/+/state/+
topic write us915_0/gateway/+/command/+

# The gateway bridge (UDP 1700): its gateway topics and nothing else. The
# deny line takes back what the pattern line gives.
user gateway-bridge
topic write us915_0/gateway/+/event/+
topic write us915_0/gateway/+/state/+
topic read us915_0/gateway/+/command/#
topic deny application/#

# Readers of application events. Each line repeats the filter its service
# subscribes; the pattern line above already allows it.
user lora
topic read application/+/device/+/event/up

user flo-ingest
topic read application/+/device/+/event/up
topic read application/+/device/+/event/txack

user outlets
topic read application/+/device/+/event/+

# cloud-link also watches gateway stats to list the gateways it hears.
user cloud-link
topic read application/+/device/+/event/up
topic read +/gateway/+/event/stats

user modbus
topic read application/+/device/+/event/up

user bacnet
topic read application/+/device/+/event/up

# The container health check.
user health
topic read $SYS/broker/uptime
topic deny application/#

# For the customer's own programs (README section "MQTT"). Read only.
user reader
topic read application/+/device/+/event/+
