Skip to content
On this page

Services

MQTT broker

The MQTT broker carries Sparkplug and UNS traffic, authenticates Factory+ principals and enforces per-principal topic access built from permission templates.

10 min read Edit this page
Central services
ACS implementationACS MQTT brokerSee how the AMRC Connectivity Stack implements this.View on GitHub

The MQTT broker is the message bus of Factory+. Every Edge Agent, service and consumer publishes to it and subscribes from it.

Sparkplug B traffic and the Unified Namespace (UNS) both travel through the broker. The broker therefore decides who may publish or read which data. A plain MQTT broker lets any connected client read every topic, and that is not acceptable on a shared factory network. A Factory+ broker authenticates each client as a Factory+ principal and gives it access only to the topics its grants allow.

Requirements

A Factory+ MQTT broker:

  • MUST support MQTT version 5, because the Unified Namespace carries metadata in MQTT 5 user properties, and Kerberos login uses the MQTT 5 enhanced authentication fields.
  • MAY also accept MQTT 3.1.1 clients that log in with a username and password.
  • MUST authenticate every client as a Factory+ principal, using the methods in Authentication.
  • MUST refuse a connection it cannot authenticate.
  • MUST enforce an access control list (ACL) for each connection, built as described in Access control.
  • MUST deny every publish and subscribe that the ACL does not allow.
  • MUST be registered in the Directory under the MQTT service UUID. Clients then find the broker URL in the same way as any other service.

Clients find the broker by asking the Directory for the MQTT service UUID feb27ba3-bd2c-4916-9269-79a61ebc4a47. The URL uses the mqtt: or mqtts: scheme. A broker MAY also offer MQTT over WebSocket for browser clients.

Authentication

The broker accepts the same identities as the HTTP services, as described in Authentication. On MQTT the credentials travel in the CONNECT packet.

MethodCONNECT packetRequirement
Kerberos GSSAPIAuthentication Method GSSAPI, and Authentication Data holding the client’s initial GSSAPI token for the service principal mqtt/<broker hostname>MUST
Username and passwordMQTT username and password, where the broker checks the password against the Kerberos KDC for that usernameMUST
OIDC bearer tokenAn OIDC access token (a JWT) as the MQTT password, where the broker ignores the username and takes the identity from the fp_principal_uuid claimMAY

The GSSAPI exchange completes in one step. The broker accepts the client’s token from the CONNECT packet and returns its own token in the Authentication Data of the CONNACK. The client MUST check that token to confirm it reached the real broker. The broker does not take part in a multi-step AUTH exchange.

A client MUST build a new token for every connection attempt, including reconnects, because a Kerberos token cannot be replayed.

The broker SHOULD use the CONNACK reason code to tell a client whether to retry. This matches the way the HTTP services separate 401 from 503.

Reason codeMeaning
0x86 Bad User Name or PasswordThe credentials were wrong or could not be verified. Retrying with the same credentials will fail again.
0x89 Server busyThe broker could not reach the Auth service or the Configuration Store to build the ACL. The client SHOULD retry later.
0x8C Bad authentication methodThe client asked for an authentication method other than GSSAPI.

Access control

The broker keeps no list of users and topics of its own. It builds each client’s topic permissions from data held by two other Factory+ services. Topic access is therefore granted in the same way as every other Factory+ permission.

  • The Auth service holds grants. A grant says that a principal has a permission on a target, following the grant model.
  • The Configuration Store holds a permission template for each MQTT permission. The template lists the topics the permission covers.
  • The Configuration Store also holds a Sparkplug address for each principal or device. The address fills in the group and node parts of those topics.

MQTT permissions and the permission group

An MQTT permission is an ordinary Factory+ permission object that is a member of the MQTT permission group a637134a-d06b-41e7-ad86-4bf62fde914a. The broker considers only grants whose permission is in this group. A permission outside the group has no effect on MQTT access, whatever its template says. Every permission in the group MUST have a permission template.

Permission templates

The permission template application 1266ddf1-156c-4266-9808-d6949418b185 holds one Configuration Store entry per MQTT permission, keyed by the permission’s UUID. Each entry is a JSON object that maps an MQTT topic filter to an access string.

{
    "spBv1.0/%g/NDATA/%n": "w",
    "spBv1.0/%g/NBIRTH/%n": "w",
    "spBv1.0/%g/NDEATH/%n": "w",
    "spBv1.0/%g/NCMD/%n/#": "rs"
}

A topic filter MAY use the MQTT wildcards + and #. It MAY also contain the placeholders %g and %n, and the broker replaces these when it builds the ACL.

The access string gives the access that the entry grants.

Access stringEffect
contains r and wThe client may publish to, and subscribe to, topics that match the filter.
contains r onlyThe client may subscribe to topics that match the filter. It receives the messages published on them.
contains w onlyThe client may publish to topics that match the filter.
anything elseThe entry grants nothing and the broker ignores it.

Templates write read access as rs by convention. The r grants the access. An s on its own grants nothing, and a template entry with the access string s gives the client no access at all. A client may subscribe to any filter that falls inside a filter it holds read access to, for example spBv1.0/Plant-A/NBIRTH/+ inside spBv1.0/#.

Placeholders and the Sparkplug address

The placeholders let one template serve every Sparkplug node. %g stands for a Sparkplug Group ID and %n for a Sparkplug Edge Node ID. The broker takes both from the target of the grant.

The broker looks up the grant’s target in the Sparkplug address application 8e32801b-f35a-4cbf-a5c3-2af64d3debd7. An entry in this application gives the Sparkplug address of an object.

{
    "group_id": "Plant-A",
    "node_id": "Cell-3"
}

An entry MAY also carry a device_id for an object that is a Sparkplug device. Templates have no placeholder for it. Command Escalation uses the same application to resolve command targets. Edge Agents use their own addresses as described in the Sparkplug conventions.

When the broker expands a template:

  1. A topic filter with no placeholder is used as it is. The grant’s target is ignored for that entry.
  2. In a topic filter with placeholders, the broker replaces %g with the target’s group_id and %n with its node_id.
  3. If the target has no Sparkplug address entry, the broker skips every entry that contains a placeholder and keeps the rest.

Auth expands the special targets before the broker sees the grant. A grant whose target is Self (5855a1cc-46d8-4b16-84f8-ab3916ecb230) reaches the broker with the principal’s own UUID as its target. One grant to a group of Edge Agents therefore gives each agent access to its own Sparkplug topics only. Permissions whose templates have no placeholders are normally granted with the Wildcard target (the Null UUID, 00000000-0000-0000-0000-000000000000).

A worked example

An Edge Agent signs in as the principal 3b6a0c1e-9d1f-4e8a-a0d2-7f0b5c9e2a41. The Configuration Store holds this Sparkplug address entry for that UUID.

{ "group_id": "Plant-A", "node_id": "Cell-3" }

The agent holds two grants, Participate as Node and Represent Devices, both with the target Self. Their templates are listed under Well-known permissions. The broker builds this ACL for the connection.

Topic filterAccess
spBv1.0/Plant-A/NDATA/Cell-3publish
spBv1.0/Plant-A/NBIRTH/Cell-3publish
spBv1.0/Plant-A/NDEATH/Cell-3publish
spBv1.0/Plant-A/NCMD/Cell-3/#subscribe
spBv1.0/Plant-A/DCMD/Cell-3/+subscribe
spBv1.0/Plant-A/DDATA/Cell-3/+publish
spBv1.0/Plant-A/DBIRTH/Cell-3/+publish
spBv1.0/Plant-A/DDEATH/Cell-3/+publish

The agent can publish as node Cell-3 and as any device under it, and can receive the commands sent to them. It cannot publish as any other node, and an attempt to subscribe to spBv1.0/# is refused.

When the ACL is built

The broker MAY build a client’s ACL once, when the client connects, and keep it for the life of the connection. A broker that does this applies a change to grants, templates or Sparkplug addresses only when the client next connects. An administrator who changes MQTT access on such a broker SHOULD make the affected clients reconnect.

A broker MAY instead rebuild ACLs while clients stay connected. It can do this, for example, by watching the Configuration Store and Auth with change-notify.

The broker’s own principal needs these permissions to build ACLs:

  • read the ACLs of other principals for the permissions in the MQTT permission group
  • read entries in the permission template and Sparkplug address applications

Well-known permissions

These permissions are members of the MQTT permission group. Their templates are the entries listed here.

An implementation that grants Sparkplug or UNS access SHOULD use these UUIDs and templates. Grants then mean the same thing on every Factory+ installation. An implementation MAY define further MQTT permissions by adding them to the group and giving each a template.

An Edge Agent needs Participate as Node and Represent Devices. They are granted with the agent itself or Self as the target. A consumer that reads all Sparkplug traffic, such as a historian, needs Read whole Sparkplug namespace.

Sparkplug, whole namespace

These templates have no placeholders. The grant’s target does not matter.

PermissionRead whole Sparkplug namespace
81833dbb-1150-4078-b1db-978c646ba73e
Subscribe to every Sparkplug topic.
{ "spBv1.0/#": "rs" }
PermissionRead all BIRTHs
67dc4dd0-0939-42b1-b1f9-9049f4d91d40
Subscribe to the node and device BIRTH messages of every Sparkplug node.
{
    "spBv1.0/+/NBIRTH/+": "rs",
    "spBv1.0/+/DBIRTH/+/+": "rs"
}
PermissionIssue CMDs
50f1e694-7e18-4930-aa59-97cc90a6a1ec
Publish a node or device command to any Sparkplug node.
{
    "spBv1.0/+/NCMD/+": "w",
    "spBv1.0/+/DCMD/+/+": "w"
}

Sparkplug expects only the Primary Application to send commands. This permission therefore belongs to Command Escalation. Other clients ask Command Escalation to send a command for them.

PermissionSubscribe to whole Sparkplug namespace
21000098-3a53-48da-8d3e-cc0650603d8e
Grants no access. Use Read whole Sparkplug namespace instead.
{ "spBv1.0/#": "s" }

The access string s grants nothing on its own. A principal that holds only this permission cannot subscribe to any Sparkplug topic.

Sparkplug, one group

These templates use %g. The grant’s target MUST have a Sparkplug address entry. The permission covers the group in that entry.

PermissionRead own Group
d617e37c-3908-41b1-8820-d3f8d41a4280
Subscribe to every Sparkplug topic in the target's group.
{ "spBv1.0/%g/#": "rs" }
PermissionPublish all from Group
64c019f8-6754-4270-8917-6659a5628b86
Publish to any Sparkplug topic in the target's group.
{ "spBv1.0/%g/#": "w" }
PermissionIssue Group CMDs
cff45682-f2f0-4c72-91f3-7dda20d43509
Publish a node or device command to any node in the target's group.
{
    "spBv1.0/%g/NCMD/+": "w",
    "spBv1.0/%g/DCMD/+/+": "w"
}

Sparkplug, one node

These templates use %g and %n. The permission covers the one Sparkplug node in the target’s address entry.

PermissionParticipate as Node
a1314953-8226-44f4-8a3e-e87b09310579
Publish as the target node and receive the commands sent to it.
{
    "spBv1.0/%g/NDATA/%n": "w",
    "spBv1.0/%g/NBIRTH/%n": "w",
    "spBv1.0/%g/NCMD/%n/#": "rs",
    "spBv1.0/%g/NDEATH/%n": "w"
}
PermissionRepresent Devices
e82456b3-a7d9-4971-9d8c-fd0be4545ab4
Publish as any device under the target node and receive the commands sent to those devices.
{
    "spBv1.0/%g/DCMD/%n/+": "rs",
    "spBv1.0/%g/DDATA/%n/+": "w",
    "spBv1.0/%g/DBIRTH/%n/+": "w",
    "spBv1.0/%g/DDEATH/%n/+": "w"
}
PermissionRead Node
046d6603-fa62-4208-9400-65d61f8b1ec4
Subscribe to the BIRTH, DATA and DEATH messages of the target node and its devices.
{
    "spBv1.0/%g/NBIRTH/%n": "rs",
    "spBv1.0/%g/NDATA/%n": "rs",
    "spBv1.0/%g/NDEATH/%n": "rs",
    "spBv1.0/%g/DBIRTH/%n/+": "rs",
    "spBv1.0/%g/DDATA/%n/+": "rs",
    "spBv1.0/%g/DDEATH/%n/+": "rs"
}

Read Node lets a consumer follow one node and its devices without the right to publish or to read the rest of the namespace.

Sparkplug STATE (legacy)

These permissions cover the STATE topics of Sparkplug B 2.2. Those topics have the form STATE/<host id>. Sparkplug 3.0 moved STATE to spBv1.0/STATE/<host id>, and none of these templates match it.

A Factory+ installation does not need STATE messages to work. Factory+ consumers ask for rebirths through Command Escalation rather than through a Primary Host STATE exchange.

PermissionRead all STATEs
8790cf3d-b793-423c-b373-8cfcf9f63529
Subscribe to every legacy STATE topic.
{ "STATE/+": "rs" }
PermissionWrite Group STATE
9a32f195-a8cc-4562-a87a-d4653279474f
Publish to the legacy STATE topic named after the target's group.
{ "STATE/%g": "w" }
PermissionWrite own STATE
bdc96a3e-d6fb-48ed-b790-0aa95cf826f0
Publish to the legacy STATE topic named after the target's node.
{ "STATE/%n": "w" }

Unified Namespace

The Unified Namespace lives under the topic prefix UNS/v1/. These templates have no placeholders.

PermissionWrite to entire UNS
9fa6ff20-9d2a-4444-960c-40ebcf56f5b4
Publish to any UNS topic. Held by the service that republishes Sparkplug data to the UNS.
{ "UNS/v1/#": "w" }
PermissionRead entire UNS
ffa40b36-3a61-4545-832a-2d1e8b860d63
Subscribe to every UNS topic.
{ "UNS/v1/#": "rs" }

Well-known UUIDs

ServiceMQTT
feb27ba3-bd2c-4916-9269-79a61ebc4a47
The service UUID the broker is registered under in the Directory.
Permission groupMQTT permissions
a637134a-d06b-41e7-ad86-4bf62fde914a
The broker only considers grants of permissions in this group.
ApplicationMQTT permission template
1266ddf1-156c-4266-9808-d6949418b185
Holds the topic template for each MQTT permission, keyed by permission UUID.
ApplicationSparkplug address
8e32801b-f35a-4cbf-a5c3-2af64d3debd7
Holds the Sparkplug group, node and device IDs of an object. Used to expand %g and %n.
Esc