Skip to content

Support propagation of cert_info to authentication event#365

Merged
bittcrafter merged 3 commits intormqtt:masterfrom
cr-boaz:feature/propagate-cert-info-pr
Mar 2, 2026
Merged

Support propagation of cert_info to authentication event#365
bittcrafter merged 3 commits intormqtt:masterfrom
cr-boaz:feature/propagate-cert-info-pr

Conversation

@cr-boaz
Copy link
Copy Markdown
Contributor

@cr-boaz cr-boaz commented Feb 28, 2026

Summary

This PR adds the ability to propagate TLS client certificate information through the MQTT connect packet to the authentication layer. This enables plugins and authentication hooks to make authorization decisions based on client certificate attributes (e.g. common name, organization, serial number).

Changes

New: CertInfo struct in rmqtt-codec (rmqtt-codec/src/mtls.rs)

Moved the CertInfo struct from rmqtt-net into rmqtt-codec as a new mtls module, making it available across the entire crate ecosystem. The struct captures:

  • common_name — CN from the certificate subject
  • subject — Full subject distinguished name
  • serial — Certificate serial number
  • organization — Organization field

Added Serialize/Deserialize derives (previously only Debug/Clone/Default), enabling certificate info to be serialized through the protocol pipeline and into plugin hooks.

Extended MQTT Connect packets (v3 and v5)

Added an optional cert: Option<CertInfo> field to both:

  • rmqtt-codec::v3::Connect
  • rmqtt-codec::v5::Connect

This field is populated at the network layer before the connect packet is dispatched, and is not encoded/decoded from the wire protocol (it is transport-layer metadata, not part of the MQTT spec).

New collect_cert_info configuration option (rmqtt-net)

Added a collect_cert_info flag to the Builder/Listener configuration. When enabled, the server attaches the client's TLS certificate information to the connect packet. This is separate from the existing cert_cn_as_username option — collect_cert_info preserves the full certificate metadata rather than just mapping CN to the username field.

The propagation is implemented in both the v3 and v5 MqttStream::recv_connect() methods.

ConnectInfo::cert() accessor (rmqtt/src/types.rs)

Added a cert() method on ConnectInfo to retrieve Option<&CertInfo> from either a v3 or v5 connect packet, providing a unified API for authentication plugins.

Bugfix: cert_cn_as_username did not work in MQTT v5

The original implementation of cert_cn_as_username was only implemented in MQTT v3 and missed MQTT v5.

Misc

  • Fixed a stale year in rmqtt-utils doctests (20252026).

Motivation

When using mTLS (mutual TLS), the server verifies client certificates but previously had no way to pass certificate details to the authentication/authorization layer. The existing cert_cn_as_username option only covers a narrow use case (mapping CN → username). This change enables richer certificate-based policies for plugins — e.g. authorizing by organization, auditing by serial number, or implementing fine-grained ACL rules based on certificate attributes.

@cr-boaz cr-boaz force-pushed the feature/propagate-cert-info-pr branch from 6db59f0 to b8efa6c Compare March 1, 2026 00:04
@cr-boaz cr-boaz marked this pull request as ready for review March 1, 2026 00:05
…eners

- Add `collect_cert_info` configuration option to enable/disable TLS certificate metadata extraction
- Update TLS stream handling to conditionally extract certificate information based on config
- Bump versions: rmqtt-codec to 0.2.2, rmqtt-net to 0.3.3
- Add detailed documentation for the new configuration option in rmqtt.toml
- Fix import statements and code formatting
@bittcrafter
Copy link
Copy Markdown
Collaborator

Thanks a lot for the contribution and the improvements — really appreciate the effort here 👍

I’ve made a few minor adjustments on top of your changes to better align with the existing code structure and configuration style.

Thanks again for the great work!

@bittcrafter bittcrafter merged commit c249a01 into rmqtt:master Mar 2, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants