Eclipse Mosquitto Documentation

repository·master·Indexed 27 days ago

https://github.com/eclipse-mosquitto/mosquitto

An open source MQTT broker supporting versions 5.0, 3.1.1, and 3.1. It includes a server implementation, C/C++ client libraries, and command-line utilities. Documentation covers Docker deployment (including mount points for /mosquitto/config, /mosquitto/data, and /mosquitto/log), authentication and authorization configurations, persistence and logging setup, and the development of the Mosquitto Dashboard UI.

Tokens
33.3K
Snippets
66
Records
305
Agent score
92%

What's inside Eclipse Mosquitto

  1. Overview of Mosquitto components

    master

    Mosquitto is a standards-compliant implementation of the MQTT messaging protocol designed for lightweight messaging on constrained devices. The project consists of three primary components:

    1. The mosquitto server: The main MQTT broker.
    2. Client utilities: mosquitto_pub and mosquitto_sub for communicating with an MQTT server via the command line.
    3. Client library: An MQTT client library written in C, which includes a C++ wrapper.
  2. Understand Dynamic Security Plugin Concepts

    master

    The Dynamic Security plugin provides role-based authentication and access control that can be updated via a topic-based API while the broker is running. It is supported in Mosquitto 2.0+ but is not activated by default.

    The plugin manages three primary object types:

    1. Clients: Represents a device or user. Attributes include:

      • Username: Unique primary key used for authentication.
      • Password: Used during the CONNECT packet. Can be updated dynamically.
      • Client ID: Optional. If set, the username, password, and client ID must all match for a connection to succeed.
      • Groups: Membership in one or more groups.
      • Roles: Assignment of one or more roles.
      • Disabled: A boolean state. Disabling a client disconnects current sessions and prevents reconnection.
    2. Groups: Collections of clients. Groups can have roles assigned to them, making them useful for applying the same access rules to multiple clients.

      • Group name: Primary identifier used for modifications.
      • Roles: Roles assigned to the group.
    3. Roles: Containers for Access Control Lists (ACLs). Roles can be assigned to both clients and groups.

  3. Use the Mosquitto MQTT client libraries

    master

    Mosquitto provides three flavors of MQTT client libraries to interact with the broker:

    • C library: The primary library (libmosquitto).
    • C++ library: A binding to the C library (mosquittopp).
    • Python library: A binding to the C library.

    Note: As of version 0.8, the library interfaces are considered experimental. For C and C++ users, detailed function call overviews and examples are available in the libmosquitto.3 man page, while mosquitto.h and mosquittopp.h provide complete coverage and class details respectively.

  4. Enable SSL/TLS and TLS-PSK encryption

    master

    Mosquitto supports certificate-based SSL/TLS encryption for the broker, client libraries, and pub/sub clients. This allows clients to verify the server's identity and enables client certificate authentication.

    For constrained or embedded devices, TLS-PSK (Pre-Shared Key) is available as a simpler encryption interface. Note that TLS-PSK support is not available in the Python client library.

  5. Use authentication plugins

    master

    Authentication plugins provide more advanced control than password files. The configuration key depends on the plugin's compatibility with the Mosquitto version:

    • For Mosquitto 2.0 and up: Use the plugin option.
    • For Mosquitto 1.6.x and earlier (also supported in 2.0): Use the auth_plugin option.

    Available Plugins:

    • Dynamic security: (2.0+ only) Allows remote administration of clients, groups, and roles via in-broker clients.
    • mosquitto-go-auth: Supports various backends like MySQL, JWT, or Redis.
  6. Configure Listeners for Remote Access

    master

    In Mosquitto 2.0+, running the broker without a configuration file (e.g., mosquitto or mosquitto -p 1883) causes it to bind only to the loopback interfaces (127.0.0.1 and/or ::1). In this mode, anonymous access is allowed for local testing.

    To allow connections from remote machines, you must use a configuration file and define a listener. By default, defining a listener binds it to all interfaces (0.0.0.0 or ::).