Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f53f2f6309 | |||
| 03cd5ee028 | |||
| fff4b994e1 | |||
| 13c399133c | |||
| 940a41669f | |||
| e9b43da768 | |||
| c14b628558 | |||
| a502aa0128 | |||
| e0b7ead458 | |||
| b5dcf2d815 | |||
| 1d33b8d3f3 | |||
| d592dc6db0 | |||
| bc4d7fea39 | |||
| 5b7d8c3927 | |||
| edb2a6df1d | |||
| bea370dca2 | |||
| 7772e489e0 | |||
| 2e50696bb4 | |||
| 25f3a40402 | |||
| 2bfe130d3b | |||
| 3cd04e3263 | |||
| 00cc2beec7 |
@@ -21,15 +21,29 @@
|
|||||||
# tag's commit is actually part of main's history (see check-branch job).
|
# tag's commit is actually part of main's history (see check-branch job).
|
||||||
|
|
||||||
name: build-and-push
|
name: build-and-push
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
- "v*"
|
- "mqtt-cert-manager/v*"
|
||||||
|
- "visquitto/v*"
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
addon:
|
||||||
|
description: "Which add-on to build"
|
||||||
|
required: true
|
||||||
|
type: choice
|
||||||
|
options:
|
||||||
|
- mqtt-cert-manager
|
||||||
|
- visquitto
|
||||||
|
version:
|
||||||
|
description: "Version (e.g. 0.4.0) — leave empty to read from config.yaml"
|
||||||
|
required: false
|
||||||
|
default: ""
|
||||||
|
|
||||||
env:
|
env:
|
||||||
REGISTRY_HOST: gitea.viratak.com
|
REGISTRY_HOST: gitea.viratak.com
|
||||||
REGISTRY_OWNER: bitopa
|
REGISTRY_OWNER: bitopa
|
||||||
IMAGE_NAME: mqtt-cert-manager
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
check-branch:
|
check-branch:
|
||||||
@@ -42,12 +56,17 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Make sure we have main's history too
|
- name: Make sure we have main's history
|
||||||
run: git fetch origin main:refs/remotes/origin/main
|
run: git fetch origin main:refs/remotes/origin/main
|
||||||
|
|
||||||
- name: Is this tag's commit part of main?
|
- name: Is this tag's commit part of main?
|
||||||
id: check
|
id: check
|
||||||
run: |
|
run: |
|
||||||
|
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
||||||
|
echo "on_main=true" >> "$GITHUB_OUTPUT"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
if git merge-base --is-ancestor HEAD origin/main; then
|
if git merge-base --is-ancestor HEAD origin/main; then
|
||||||
echo "on_main=true" >> "$GITHUB_OUTPUT"
|
echo "on_main=true" >> "$GITHUB_OUTPUT"
|
||||||
else
|
else
|
||||||
@@ -55,17 +74,56 @@ jobs:
|
|||||||
echo "Tag $GITHUB_REF_NAME points to a commit that is not on main — skipping build."
|
echo "Tag $GITHUB_REF_NAME points to a commit that is not on main — skipping build."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
build:
|
prepare:
|
||||||
needs: check-branch
|
needs: check-branch
|
||||||
if: needs.check-branch.outputs.on_main == 'true'
|
if: needs.check-branch.outputs.on_main == 'true'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
addon: ${{ steps.meta.outputs.addon }}
|
||||||
|
version: ${{ steps.meta.outputs.version }}
|
||||||
|
image: ${{ steps.meta.outputs.image }}
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Determine add-on and version
|
||||||
|
id: meta
|
||||||
|
run: |
|
||||||
|
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
||||||
|
ADDON="${{ inputs.addon }}"
|
||||||
|
VERSION="${{ inputs.version }}"
|
||||||
|
else
|
||||||
|
# tag format: mqtt-cert-manager/v0.3.0 or visquitto/v0.4.0
|
||||||
|
ADDON=$(echo "${{ github.ref_name }}" | cut -d/ -f1)
|
||||||
|
VERSION=$(echo "${{ github.ref_name }}" | cut -d/ -f2 | sed 's/^v//')
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Fallback: read version from config.yaml if not provided
|
||||||
|
if [ -z "$VERSION" ]; then
|
||||||
|
VERSION=$(grep '^version:' "$ADDON/config.yaml" | head -1 | sed -E 's/.*"([^"]+)".*/\1/')
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$ADDON" ] || [ -z "$VERSION" ]; then
|
||||||
|
echo "Could not determine add-on or version"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "addon=$ADDON" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "image=${{ env.REGISTRY_HOST }}/${{ env.REGISTRY_OWNER }}/$ADDON" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
echo "Building $ADDON version $VERSION"
|
||||||
|
|
||||||
|
build:
|
||||||
|
needs: prepare
|
||||||
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- arch: amd64
|
- arch: amd64
|
||||||
platform: linux/amd64
|
platform: linux/amd64
|
||||||
# TEMPORARY: only building amd64 while developing against a
|
# Uncomment when you are ready for multi-arch:
|
||||||
# single Dell thin client — restore these before publishing.
|
|
||||||
# - arch: aarch64
|
# - arch: aarch64
|
||||||
# platform: linux/arm64
|
# platform: linux/arm64
|
||||||
# - arch: armv7
|
# - arch: armv7
|
||||||
@@ -78,24 +136,8 @@ jobs:
|
|||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Read add-on version
|
# - name: Set up QEMU
|
||||||
id: version
|
# uses: docker/setup-qemu-action@v3
|
||||||
# Plain shell instead of python3+PyYAML: the runner's Python has
|
|
||||||
# no yaml module installed, and this value is a simple one-liner
|
|
||||||
# anyway (version: "0.1.0"), so there's no need for a real YAML
|
|
||||||
# parser or an extra apt/pip install step just for this.
|
|
||||||
run: |
|
|
||||||
VERSION=$(grep '^version:' mqtt-cert-manager/config.yaml | cut -d'"' -f2)
|
|
||||||
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
|
|
||||||
|
|
||||||
- name: Read base image for this arch from build.yaml
|
|
||||||
id: base
|
|
||||||
run: |
|
|
||||||
BUILD_FROM=$(grep -E "^[[:space:]]*${{ matrix.arch }}:" mqtt-cert-manager/build.yaml | cut -d'"' -f2)
|
|
||||||
echo "build_from=$BUILD_FROM" >> "$GITHUB_OUTPUT"
|
|
||||||
|
|
||||||
- name: Set up QEMU (needed to build non-amd64 targets on an amd64 runner)
|
|
||||||
uses: docker/setup-qemu-action@v3
|
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
@@ -108,13 +150,12 @@ jobs:
|
|||||||
password: ${{ secrets.REGISTRY_TOKEN }}
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
||||||
|
|
||||||
- name: Build and push
|
- name: Build and push
|
||||||
uses: docker/build-push-action@v5
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
context: ./mqtt-cert-manager
|
context: ./${{ needs.prepare.outputs.addon }}
|
||||||
platforms: ${{ matrix.platform }}
|
platforms: ${{ matrix.platform }}
|
||||||
push: true
|
push: true
|
||||||
build-args: |
|
# No BUILD_FROM needed anymore — modern Dockerfiles have a direct FROM
|
||||||
BUILD_FROM=${{ steps.base.outputs.build_from }}
|
|
||||||
tags: |
|
tags: |
|
||||||
${{ env.REGISTRY_HOST }}/${{ env.REGISTRY_OWNER }}/${{ env.IMAGE_NAME }}-${{ matrix.arch }}:${{ steps.version.outputs.version }}
|
${{ needs.prepare.outputs.image }}-${{ matrix.arch }}:${{ needs.prepare.outputs.version }}
|
||||||
${{ env.REGISTRY_HOST }}/${{ env.REGISTRY_OWNER }}/${{ env.IMAGE_NAME }}-${{ matrix.arch }}:latest
|
${{ needs.prepare.outputs.image }}-${{ matrix.arch }}:latest
|
||||||
@@ -17,6 +17,13 @@ This repository contains the following apps
|
|||||||
|
|
||||||
_Application to use as a certificate manager for Home Assistant._
|
_Application to use as a certificate manager for Home Assistant._
|
||||||
|
|
||||||
|
### [Visquitto](./visquitto)
|
||||||
|
|
||||||
|
<!-- ![Supports aarch64 Architecture][aarch64-shield] -->
|
||||||
|
![Supports amd64 Architecture][amd64-shield]
|
||||||
|
|
||||||
|
_Application to use as a Second MQTT broker._
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
|
|
||||||
Notes to developers after forking or using the github template feature:
|
Notes to developers after forking or using the github template feature:
|
||||||
|
|||||||
@@ -1,6 +1,19 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 0.5.2
|
||||||
|
|
||||||
|
- Improved logging and error handling
|
||||||
|
|
||||||
|
## 0.5.1 - 2026-10-11
|
||||||
|
|
||||||
|
- Bug fix
|
||||||
|
|
||||||
|
## 0.5.0 - 2026-10-11
|
||||||
|
|
||||||
|
- Upgraded image build precedure
|
||||||
|
|
||||||
## 0.4.2
|
## 0.4.2
|
||||||
|
|
||||||
- Certificate Common Name (CN) is now taken from each device's own
|
- Certificate Common Name (CN) is now taken from each device's own
|
||||||
CSR instead of being forced to equal its `device_id`. Enables
|
CSR instead of being forced to equal its `device_id`. Enables
|
||||||
deployments where many devices intentionally share one CN per
|
deployments where many devices intentionally share one CN per
|
||||||
@@ -10,11 +23,14 @@
|
|||||||
CN alongside `device_id` for each entry.
|
CN alongside `device_id` for each entry.
|
||||||
|
|
||||||
## 0.4.1
|
## 0.4.1
|
||||||
|
|
||||||
- Changed SAN default for generating server certificate
|
- Changed SAN default for generating server certificate
|
||||||
- Added two new options for organizations
|
- Added two new options for organizations
|
||||||
|
|
||||||
## 0.4.0
|
## 0.4.0
|
||||||
|
|
||||||
- Replaced RSA algorithm with EC for encryption.
|
- Replaced RSA algorithm with EC for encryption.
|
||||||
|
|
||||||
## 0.3.0
|
## 0.3.0
|
||||||
|
|
||||||
- Initial release.
|
- Initial release.
|
||||||
@@ -20,6 +20,7 @@ step 2.
|
|||||||
|
|
||||||
The private key never leaves the device. Generate an RSA-2048 (or EC
|
The private key never leaves the device. Generate an RSA-2048 (or EC
|
||||||
P-256) key pair and a PKCS#10 CSR with:
|
P-256) key pair and a PKCS#10 CSR with:
|
||||||
|
|
||||||
- Common Name = whatever identity you want written into the issued
|
- Common Name = whatever identity you want written into the issued
|
||||||
certificate. This does NOT have to be `device_id` and does NOT have to
|
certificate. This does NOT have to be `device_id` and does NOT have to
|
||||||
be unique per device — a common pattern is to share one CN across a
|
be unique per device — a common pattern is to share one CN across a
|
||||||
@@ -39,6 +40,7 @@ Topic: `cert/enroll/<device_id>/request`
|
|||||||
QoS: 1, retain: false
|
QoS: 1, retain: false
|
||||||
|
|
||||||
Payload (JSON):
|
Payload (JSON):
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"csr": "-----BEGIN CERTIFICATE REQUEST-----\n...\n-----END CERTIFICATE REQUEST-----\n",
|
"csr": "-----BEGIN CERTIFICATE REQUEST-----\n...\n-----END CERTIFICATE REQUEST-----\n",
|
||||||
@@ -48,6 +50,7 @@ Payload (JSON):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
`meta` is optional and only shown to the human approving the request — put
|
`meta` is optional and only shown to the human approving the request — put
|
||||||
anything there that helps you recognize the device in the UI.
|
anything there that helps you recognize the device in the UI.
|
||||||
|
|
||||||
@@ -69,26 +72,31 @@ device has its own dedicated topics here — no filtering needed, unlike
|
|||||||
setups where many devices might share one topic.
|
setups where many devices might share one topic.
|
||||||
|
|
||||||
- `cert/enroll/<device_id>/issued` — retained. Payload:
|
- `cert/enroll/<device_id>/issued` — retained. Payload:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"cert": "-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----\n",
|
"cert": "-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----\n",
|
||||||
"ca": "-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----\n"
|
"ca": "-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----\n"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Because this is retained, if the device subscribes *after* a cert was
|
Because this is retained, if the device subscribes *after* a cert was
|
||||||
already issued (e.g. after a reboot), it will receive it immediately
|
already issued (e.g. after a reboot), it will receive it immediately
|
||||||
without needing to re-request.
|
without needing to re-request.
|
||||||
|
|
||||||
- `cert/enroll/<device_id>/rejected` — not retained. Payload:
|
- `cert/enroll/<device_id>/rejected` — not retained. Payload:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{ "reason": "human-readable reason" }
|
{ "reason": "human-readable reason" }
|
||||||
```
|
```
|
||||||
|
|
||||||
- `cert/enroll/<device_id>/revoked` — not retained, best-effort only.
|
- `cert/enroll/<device_id>/revoked` — not retained, best-effort only.
|
||||||
Payload:
|
Payload:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{ "reason": "human-readable reason" }
|
{ "reason": "human-readable reason" }
|
||||||
```
|
```
|
||||||
|
|
||||||
Sent if you revoke a device's cert after it was issued. This is
|
Sent if you revoke a device's cert after it was issued. This is
|
||||||
informational — actual enforcement happens at the TLS layer via
|
informational — actual enforcement happens at the TLS layer via
|
||||||
Mosquitto's CRL check, which a revoked device will hit on its *next*
|
Mosquitto's CRL check, which a revoked device will hit on its *next*
|
||||||
@@ -117,6 +125,7 @@ Topic: `cert/enroll/<device_id>/renew`
|
|||||||
QoS: 1, retain: false
|
QoS: 1, retain: false
|
||||||
|
|
||||||
Payload (JSON):
|
Payload (JSON):
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"csr": "-----BEGIN CERTIFICATE REQUEST-----\n...\n-----END CERTIFICATE REQUEST-----\n",
|
"csr": "-----BEGIN CERTIFICATE REQUEST-----\n...\n-----END CERTIFICATE REQUEST-----\n",
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
ARG BUILD_FROM
|
FROM ghcr.io/home-assistant/base:3.24
|
||||||
FROM ${BUILD_FROM}
|
|
||||||
|
|
||||||
RUN apk add --no-cache python3 py3-pip
|
RUN apk add --no-cache python3 py3-pip
|
||||||
|
|
||||||
@@ -12,8 +11,8 @@ COPY run.sh /run.sh
|
|||||||
RUN chmod a+x /run.sh
|
RUN chmod a+x /run.sh
|
||||||
|
|
||||||
LABEL \
|
LABEL \
|
||||||
io.hass.version="0.1.0" \
|
io.hass.name="MQTT Certificate Manager" \
|
||||||
io.hass.type="addon" \
|
io.hass.type="addon" \
|
||||||
io.hass.arch="armhf|armv7|aarch64|amd64|i386"
|
io.hass.arch="amd64"
|
||||||
|
|
||||||
CMD ["/run.sh"]
|
CMD ["/run.sh"]
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ self-signed CA — no external CA or internet dependency.
|
|||||||
Full device-side wire protocol: see `DEVICE_PROTOCOL.md`.
|
Full device-side wire protocol: see `DEVICE_PROTOCOL.md`.
|
||||||
|
|
||||||
## Installing this application
|
## Installing this application
|
||||||
|
|
||||||
1. Add [virarepo repository](https://gitea.viratak.com/bitopa/virarepo) in applications section
|
1. Add [virarepo repository](https://gitea.viratak.com/bitopa/virarepo) in applications section
|
||||||
2. Look for this project, and click install
|
2. Look for this project, and click install
|
||||||
|
|
||||||
@@ -46,10 +47,8 @@ Full device-side wire protocol: see `DEVICE_PROTOCOL.md`.
|
|||||||
|
|
||||||
## What's included in this scaffold
|
## What's included in this scaffold
|
||||||
|
|
||||||
- `config.yaml` / `build.yaml` — add-on manifest, current (2026) HA base
|
- `config.yaml` — add-on manifest, current (2026) HA base
|
||||||
image convention. **Double check `build.yaml` against
|
image convention.
|
||||||
https://github.com/home-assistant/docker-base if your Supervisor
|
|
||||||
version is very new or old** — base image tags do change.
|
|
||||||
- `app/ca.py` — root CA generation + CSR signing (RSA-4096 root, 20-year
|
- `app/ca.py` — root CA generation + CSR signing (RSA-4096 root, 20-year
|
||||||
validity; issued certs default to 825 days, matching common CT/browser
|
validity; issued certs default to 825 days, matching common CT/browser
|
||||||
practice, though these are just client certs so it's a soft ceiling you
|
practice, though these are just client certs so it's a soft ceiling you
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import datetime
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from flask import Flask, jsonify, render_template, request
|
from flask import Flask, jsonify, render_template, request
|
||||||
@@ -14,6 +15,16 @@ from mqtt_worker import MqttWorker
|
|||||||
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(name)s %(message)s")
|
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(name)s %(message)s")
|
||||||
log = logging.getLogger("main")
|
log = logging.getLogger("main")
|
||||||
|
|
||||||
|
|
||||||
|
def _log_uncaught(exc_type, exc, tb):
|
||||||
|
# Python prints uncaught exceptions straight to stderr, bypassing
|
||||||
|
# logging entirely -- which is why a crash traceback had no timestamp
|
||||||
|
# while every other line did. Route it through the logger instead.
|
||||||
|
log.critical("uncaught exception, add-on is exiting", exc_info=(exc_type, exc, tb))
|
||||||
|
|
||||||
|
|
||||||
|
sys.excepthook = _log_uncaught
|
||||||
|
|
||||||
OPTIONS_PATH = "/data/options.json"
|
OPTIONS_PATH = "/data/options.json"
|
||||||
SSL_DIR = "/ssl"
|
SSL_DIR = "/ssl"
|
||||||
BROKER_CERT_FILENAME = "mosquitto-server.crt"
|
BROKER_CERT_FILENAME = "mosquitto-server.crt"
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ See DEVICE_PROTOCOL.md for the full spec devices should implement.
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import threading
|
import threading
|
||||||
|
import time
|
||||||
|
|
||||||
import paho.mqtt.client as mqtt
|
import paho.mqtt.client as mqtt
|
||||||
|
|
||||||
@@ -38,23 +39,65 @@ class MqttWorker:
|
|||||||
if username:
|
if username:
|
||||||
self.client.username_pw_set(username, password or None)
|
self.client.username_pw_set(username, password or None)
|
||||||
self.client.on_connect = self._on_connect
|
self.client.on_connect = self._on_connect
|
||||||
|
self.client.on_disconnect = self._on_disconnect
|
||||||
self.client.on_message = self._on_message
|
self.client.on_message = self._on_message
|
||||||
|
|
||||||
self.host = host
|
self.host = host
|
||||||
self.port = port
|
self.port = port
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
self.client.connect(self.host, self.port, keepalive=60)
|
# Returns immediately: the connect (and its retries) happen in the
|
||||||
thread = threading.Thread(target=self.client.loop_forever, daemon=True)
|
# background, so a broker that isn't reachable YET -- e.g. Home
|
||||||
|
# Assistant just booted and Mosquitto hasn't started -- doesn't
|
||||||
|
# crash the whole add-on or block the web UI from coming up.
|
||||||
|
thread = threading.Thread(target=self._run, daemon=True, name="mqtt-worker")
|
||||||
thread.start()
|
thread.start()
|
||||||
|
|
||||||
|
def _run(self):
|
||||||
|
self.client.reconnect_delay_set(min_delay=1, max_delay=30)
|
||||||
|
delay = 1
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
# This is the plain TCP connect. MQTT itself (CONNECT /
|
||||||
|
# CONNACK, auth) only starts once this succeeds.
|
||||||
|
self.client.connect(self.host, self.port, keepalive=60)
|
||||||
|
except OSError as exc:
|
||||||
|
# ConnectionRefusedError (nothing listening), gaierror
|
||||||
|
# (hostname doesn't resolve), timeouts, etc. all land here.
|
||||||
|
log.warning(
|
||||||
|
"cannot reach MQTT broker at %s:%s (%s: %s) - retrying in %ss. "
|
||||||
|
"Check the mqtt_host / mqtt_port options, and that Mosquitto is running.",
|
||||||
|
self.host, self.port, type(exc).__name__, exc, delay,
|
||||||
|
)
|
||||||
|
time.sleep(delay)
|
||||||
|
delay = min(delay * 2, 30)
|
||||||
|
continue
|
||||||
|
# Connected at the TCP level. From here paho handles drops and
|
||||||
|
# reconnects itself (using reconnect_delay_set above); this only
|
||||||
|
# returns if disconnect() is ever called explicitly.
|
||||||
|
self.client.loop_forever()
|
||||||
|
return
|
||||||
|
|
||||||
def _on_connect(self, client, userdata, flags, rc):
|
def _on_connect(self, client, userdata, flags, rc):
|
||||||
|
if rc != 0:
|
||||||
|
# The TCP connection worked but the BROKER said no -- a different
|
||||||
|
# failure from "connection refused". Usually bad credentials.
|
||||||
|
log.error(
|
||||||
|
"MQTT broker rejected the connection: %s "
|
||||||
|
"(check the mqtt_username / mqtt_password options)",
|
||||||
|
mqtt.connack_string(rc),
|
||||||
|
)
|
||||||
|
return
|
||||||
request_topic = f"{self.topic_prefix}/+/request"
|
request_topic = f"{self.topic_prefix}/+/request"
|
||||||
renew_topic = f"{self.topic_prefix}/+/renew"
|
renew_topic = f"{self.topic_prefix}/+/renew"
|
||||||
client.subscribe(request_topic, qos=1)
|
client.subscribe(request_topic, qos=1)
|
||||||
client.subscribe(renew_topic, qos=1)
|
client.subscribe(renew_topic, qos=1)
|
||||||
log.info("connected to broker, subscribed to %s and %s", request_topic, renew_topic)
|
log.info("connected to broker, subscribed to %s and %s", request_topic, renew_topic)
|
||||||
|
|
||||||
|
def _on_disconnect(self, client, userdata, rc):
|
||||||
|
if rc != 0:
|
||||||
|
log.warning("lost connection to MQTT broker (rc=%s); retrying automatically", rc)
|
||||||
|
|
||||||
def _on_message(self, client, userdata, msg):
|
def _on_message(self, client, userdata, msg):
|
||||||
parts = msg.topic.split("/")
|
parts = msg.topic.split("/")
|
||||||
if len(parts) < 2:
|
if len(parts) < 2:
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
# As of Supervisor 2026.04+, HA no longer injects BUILD_FROM automatically,
|
|
||||||
# so we pin it explicitly here. If your Supervisor is older/newer and this
|
|
||||||
# fails to build, check https://github.com/home-assistant/docker-base for the
|
|
||||||
# current recommended base image tag and update the line below.
|
|
||||||
build_from:
|
|
||||||
amd64: "ghcr.io/home-assistant/base:latest"
|
|
||||||
aarch64: "ghcr.io/home-assistant/base:latest"
|
|
||||||
armv7: "ghcr.io/home-assistant/base:latest"
|
|
||||||
armhf: "ghcr.io/home-assistant/base:latest"
|
|
||||||
i386: "ghcr.io/home-assistant/base:latest"
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
name: "MQTT Certificate Manager"
|
name: "MQTT Certificate Manager"
|
||||||
version: "0.4.2"
|
version: "0.5.2"
|
||||||
slug: "mqtt_cert_manager"
|
slug: "mqtt_cert_manager"
|
||||||
description: "Local CA that issues and manages TLS client certificates for MQTT nodes"
|
description: "Local CA that issues and manages TLS client certificates for MQTT nodes"
|
||||||
url: "https://gitea.viratak.com/bitopa/mqtt-cert-manager"
|
url: "https://gitea.viratak.com/bitopa/virarepo/src/branch/main/mqtt-cert-manager"
|
||||||
# Points Supervisor at a pre-built image instead of building locally on
|
# Points Supervisor at a pre-built image instead of building locally on
|
||||||
# install. {arch} is substituted with each entry in "arch:" below (amd64,
|
# install. {arch} is substituted with each entry in "arch:" below (amd64,
|
||||||
# aarch64, ...) — Supervisor then pulls
|
# aarch64, ...) — Supervisor then pulls
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
## 0.5.4
|
||||||
|
|
||||||
|
- Minor bug fix
|
||||||
|
|
||||||
|
## 0.5.1 - 2026-10-11
|
||||||
|
|
||||||
|
- Minor bug fixed
|
||||||
|
|
||||||
|
## 0.5.0 - 2026-10-11
|
||||||
|
|
||||||
|
- Added pre-built docker image
|
||||||
|
- Fixed some translation issues
|
||||||
|
|
||||||
|
## 0.4.1 - 2026-10-11
|
||||||
|
|
||||||
|
- Fixed Translation indentation issue
|
||||||
|
|
||||||
|
## 0.4.0
|
||||||
|
|
||||||
|
- Added descriptions in configuration
|
||||||
|
- Added Persian support in configuration
|
||||||
|
|
||||||
|
## 0.3.3
|
||||||
|
|
||||||
|
- Minor bug fix
|
||||||
|
|
||||||
|
## 0.3.2
|
||||||
|
|
||||||
|
- Minor bug fix
|
||||||
|
|
||||||
|
## 0.3.1
|
||||||
|
|
||||||
|
- Minor bug fix
|
||||||
|
|
||||||
|
## 0.3.0
|
||||||
|
|
||||||
|
- Added separated ACL's
|
||||||
|
- Improved logging capabilities
|
||||||
|
|
||||||
|
## 0.2.5
|
||||||
|
|
||||||
|
- Minor bug fix
|
||||||
|
|
||||||
|
## 0.2.4
|
||||||
|
|
||||||
|
- Minor bug fix
|
||||||
|
|
||||||
|
## 0.2.3
|
||||||
|
|
||||||
|
- Minor bug fix
|
||||||
|
|
||||||
|
## 0.2.2
|
||||||
|
|
||||||
|
- Minor bug fix
|
||||||
|
|
||||||
|
## 0.2.1
|
||||||
|
|
||||||
|
- Fixed app icon
|
||||||
|
|
||||||
|
## 0.2.0
|
||||||
|
|
||||||
|
- Added app icon
|
||||||
|
- Improved app configuration
|
||||||
|
|
||||||
|
## 0.1.0
|
||||||
|
|
||||||
|
- Initializing the Application
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
FROM eclipse-mosquitto:2
|
||||||
|
|
||||||
|
# Install jq (needed by run.sh for config parsing)
|
||||||
|
RUN apk add --no-cache jq
|
||||||
|
|
||||||
|
# Copy and prepare the entrypoint
|
||||||
|
COPY run.sh /run.sh
|
||||||
|
RUN chmod a+x /run.sh
|
||||||
|
|
||||||
|
# Optional but recommended labels
|
||||||
|
LABEL \
|
||||||
|
io.hass.name="Visquitto" \
|
||||||
|
io.hass.description="Second private Mosquitto broker for bitopa nodes" \
|
||||||
|
io.hass.type="addon" \
|
||||||
|
io.hass.arch="amd64"
|
||||||
|
|
||||||
|
CMD [ "/run.sh" ]
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
# Visquitto
|
||||||
|
|
||||||
|
Visquitto is a simple Mosquitto broker setup intended to run on a separate port and be used alongside [mqtt-cert-manager](https://gitea.viratak.com/bitopa/virarepo/src/branch/main/mqtt-cert-manager) and custom MQTT nodes.
|
||||||
|
|
||||||
|
This is not a full certificate-management platform or a Home Assistant-only app. It is a lightweight broker instance for local MQTT traffic, designed to coexist with [mqtt-cert-manager](https://gitea.viratak.com/bitopa/virarepo/src/branch/main/mqtt-cert-manager) and custom client code.
|
||||||
|
|
||||||
|
## What it is
|
||||||
|
|
||||||
|
- A standard Mosquitto broker
|
||||||
|
- Configured for a dedicated port, separate from the default broker
|
||||||
|
- Meant to be used alongside [mqtt-cert-manager](https://gitea.viratak.com/bitopa/virarepo/src/branch/main/mqtt-cert-manager) and custom MQTT nodes
|
||||||
|
- Intended for local/private network use
|
||||||
|
|
||||||
|
## Why use it
|
||||||
|
|
||||||
|
If you want a second MQTT broker for a specific project, workflow, or device group, Visquitto gives you:
|
||||||
|
|
||||||
|
- a clean, separate broker port
|
||||||
|
- a simple local MQTT endpoint for custom nodes and devices
|
||||||
|
- isolation from your main broker traffic
|
||||||
|
- an easy way to pair it with your own app logic
|
||||||
|
|
||||||
|
## Typical setup
|
||||||
|
|
||||||
|
Visquitto is designed to be used like this:
|
||||||
|
|
||||||
|
- Your main app runs normally
|
||||||
|
- Custom nodes or devices connect to the Visquitto broker
|
||||||
|
- The broker listens on its own port instead of the default Mosquitto port
|
||||||
|
- Traffic is kept separate from the primary broker environment
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
- A machine/container/environment capable of running Mosquitto
|
||||||
|
- A separate port for the broker
|
||||||
|
- Your own app and custom MQTT clients/nodes
|
||||||
|
- Local or private network access as needed
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
Common settings include:
|
||||||
|
|
||||||
|
- broker port
|
||||||
|
- listener configuration
|
||||||
|
- allow/deny rules if needed
|
||||||
|
- persistence settings
|
||||||
|
- logging options
|
||||||
|
- TLS settings if you choose to enable them
|
||||||
|
|
||||||
|
This project is intentionally minimal: it provides a broker for your other app and custom nodes rather than trying to manage a larger certificate or onboarding system.
|
||||||
|
|
||||||
|
## Notes
|
||||||
|
|
||||||
|
- This is a plain Mosquitto-based broker setup
|
||||||
|
- It is meant to complement another app, not replace it
|
||||||
|
- It is best suited for local experiments, custom node integrations, and paired app workflows
|
||||||
|
- If you are using TLS or custom auth, configure it explicitly for your environment
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
Please check the repository license file for usage terms if one is included in the project.
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
name: Visquitto
|
||||||
|
version: "0.5.4"
|
||||||
|
slug: visquitto
|
||||||
|
description: Second private Mosquitto broker for bitopa nodes
|
||||||
|
url: "https://gitea.viratak.com/bitopa/virarepo/src/branch/main/visquitto"
|
||||||
|
image: "gitea.viratak.com/bitopa/visquitto-{arch}"
|
||||||
|
arch:
|
||||||
|
- amd64
|
||||||
|
init: false
|
||||||
|
startup: services
|
||||||
|
boot: auto
|
||||||
|
ports:
|
||||||
|
1883/tcp: 1993
|
||||||
|
8883/tcp: 9993
|
||||||
|
ports_description:
|
||||||
|
1883/tcp: MQTT (plain)
|
||||||
|
8883/tcp: MQTT over TLS
|
||||||
|
map:
|
||||||
|
- addon_config:rw
|
||||||
|
- share:rw
|
||||||
|
- ssl:ro
|
||||||
|
options:
|
||||||
|
users: []
|
||||||
|
log_dest: []
|
||||||
|
log_type: []
|
||||||
|
require_certificate: false
|
||||||
|
cafile: mqtt-cert-manager-ca.crt
|
||||||
|
certfile: mosquitto-server.crt
|
||||||
|
keyfile: mosquitto-server.key
|
||||||
|
schema:
|
||||||
|
users:
|
||||||
|
- username: str
|
||||||
|
password: password
|
||||||
|
log_dest:
|
||||||
|
- list(none|stdout|stderr|topic)?
|
||||||
|
log_type:
|
||||||
|
- list(none|debug|error|warning|notice|information|subscribe|unsubscribe|websockets|all)?
|
||||||
|
require_certificate: bool
|
||||||
|
cafile: str
|
||||||
|
certfile: str
|
||||||
|
keyfile: str
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
@@ -0,0 +1,157 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
umask 077
|
||||||
|
|
||||||
|
CONFIG=/config
|
||||||
|
SHARE=/share/visquitto
|
||||||
|
DATA=/data/mosquitto
|
||||||
|
PASSWD=/data/passwd
|
||||||
|
CERTDIR=/data/certs
|
||||||
|
|
||||||
|
mkdir -p "$SHARE" "$DATA" "$CERTDIR"
|
||||||
|
chown -R mosquitto:mosquitto "$DATA"
|
||||||
|
|
||||||
|
CAFILE=$(jq -r '.cafile' /data/options.json)
|
||||||
|
CERTFILE=$(jq -r '.certfile' /data/options.json)
|
||||||
|
KEYFILE=$(jq -r '.keyfile' /data/options.json)
|
||||||
|
|
||||||
|
# ---- Check plugins exist ----
|
||||||
|
for p in /usr/lib/mosquitto_acl_file.so /usr/lib/mosquitto_password_file.so; do
|
||||||
|
[ -f "$p" ] || { echo "Missing plugin $p" >&2; exit 1; }
|
||||||
|
done
|
||||||
|
|
||||||
|
# ---- Certificates: copied at every start, readable by mosquitto ----
|
||||||
|
for f in "$CAFILE" "$CERTFILE" "$KEYFILE"; do
|
||||||
|
[ -f "/ssl/$f" ] || { echo "Missing /ssl/$f" >&2; exit 1; }
|
||||||
|
done
|
||||||
|
|
||||||
|
cp "/ssl/$CAFILE" "$CERTDIR/ca.pem"
|
||||||
|
cp "/ssl/$CERTFILE" "$CERTDIR/cert.pem"
|
||||||
|
cp "/ssl/$KEYFILE" "$CERTDIR/key.pem"
|
||||||
|
chown -R mosquitto:mosquitto "$CERTDIR"
|
||||||
|
chmod 644 "$CERTDIR/ca.pem" "$CERTDIR/cert.pem"
|
||||||
|
chmod 600 "$CERTDIR/key.pem"
|
||||||
|
|
||||||
|
# ---- Defaults in /config (regenerated at every start) ----
|
||||||
|
cat > "$CONFIG/mosquitto.conf" <<EOF
|
||||||
|
log_dest stdout
|
||||||
|
log_type error
|
||||||
|
log_type warning
|
||||||
|
log_type notice
|
||||||
|
log_timestamp_format %Y-%m-%d %H:%M:%S
|
||||||
|
|
||||||
|
persistence true
|
||||||
|
persistence_location $DATA/
|
||||||
|
max_queued_messages 8192
|
||||||
|
|
||||||
|
plugin_load acl_file /usr/lib/mosquitto_acl_file.so
|
||||||
|
plugin_load password_file /usr/lib/mosquitto_password_file.so
|
||||||
|
|
||||||
|
include_dir $SHARE
|
||||||
|
|
||||||
|
# Plain listener (host port 1993): password users only
|
||||||
|
listener 1883
|
||||||
|
protocol mqtt
|
||||||
|
allow_anonymous false
|
||||||
|
plugin_use password_file
|
||||||
|
plugin_opt_password_file $PASSWD
|
||||||
|
plugin_use acl_file
|
||||||
|
plugin_opt_acl_file $DATA/acl_plain
|
||||||
|
|
||||||
|
# TLS listener (host port 9993): client certificate required
|
||||||
|
listener 8883
|
||||||
|
protocol mqtt
|
||||||
|
allow_anonymous false
|
||||||
|
cafile $CERTDIR/ca.pem
|
||||||
|
certfile $CERTDIR/cert.pem
|
||||||
|
keyfile $CERTDIR/key.pem
|
||||||
|
tls_version tlsv1.2
|
||||||
|
require_certificate true
|
||||||
|
use_identity_as_username true
|
||||||
|
plugin_use password_file
|
||||||
|
plugin_opt_password_file $PASSWD
|
||||||
|
plugin_use acl_file
|
||||||
|
plugin_opt_acl_file $DATA/acl_tls
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# plain ACL
|
||||||
|
cat > "$CONFIG/acl_plain" <<EOF
|
||||||
|
# ============================================================
|
||||||
|
# Not certified devices
|
||||||
|
# ============================================================
|
||||||
|
user hamqtt
|
||||||
|
|
||||||
|
# Test topic
|
||||||
|
topic readwrite test
|
||||||
|
# Initial enrollment
|
||||||
|
topic write cert/enroll/+/request
|
||||||
|
topic read cert/enroll/+/issued
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# Certificate manager
|
||||||
|
# ============================================================
|
||||||
|
user viracert
|
||||||
|
|
||||||
|
topic read cert/enroll/+/request
|
||||||
|
topic write cert/enroll/+/issued
|
||||||
|
topic read cert/enroll/+/renew
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# TLS ACL
|
||||||
|
cat > "$CONFIG/acl_tls" <<EOF
|
||||||
|
# Default rule for every certificate client. %u is the certificate CN.
|
||||||
|
pattern readwrite clients/%u/#
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# ---- User customization in /share (created once, never overwritten) ----
|
||||||
|
if grep -qE '^\s*(listener|port|bind_address)\b' "$SHARE/mosquitto.conf"; then
|
||||||
|
echo "ERROR: $SHARE/mosquitto.conf must not define listeners (listener/port/bind_address)." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f "$SHARE/mosquitto.conf" ]; then
|
||||||
|
echo "# Extra global Mosquitto options (loaded with include_dir, before the listeners)" > "$SHARE/mosquitto.conf"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f "$SHARE/acl_plain" ]; then
|
||||||
|
cat > "$SHARE/acl_plain" <<EOF
|
||||||
|
# Extra ACL rules for the plain listener, appended to the default, for example:
|
||||||
|
# user enroll
|
||||||
|
# topic write certs/request/#
|
||||||
|
# topic read certs/response/#
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f "$SHARE/acl_tls" ]; then
|
||||||
|
cat > "$SHARE/acl_tls" <<EOF
|
||||||
|
# Extra ACL rules for the TLS listener (user = certificate CN), appended to the default, for example:
|
||||||
|
# user hamt
|
||||||
|
# topic read broadcast/#
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
|
|
||||||
|
chmod 644 "$SHARE/mosquitto.conf"
|
||||||
|
chmod 600 "$SHARE/acl_plain" "$SHARE/acl_tls"
|
||||||
|
|
||||||
|
# ---- Merge defaults + user ACLs into the files Mosquitto reads ----
|
||||||
|
{ cat "$CONFIG/acl_plain"; echo; cat "$SHARE/acl_plain"; echo; } > "$DATA/acl_plain"
|
||||||
|
{ cat "$CONFIG/acl_tls"; echo; cat "$SHARE/acl_tls"; echo; } > "$DATA/acl_tls"
|
||||||
|
|
||||||
|
for f in "$DATA/acl_plain" "$DATA/acl_tls"; do
|
||||||
|
chown mosquitto:mosquitto "$f"
|
||||||
|
chmod 600 "$f"
|
||||||
|
done
|
||||||
|
|
||||||
|
# ---- Users from the panel ----
|
||||||
|
rm -f "$PASSWD"
|
||||||
|
touch "$PASSWD"
|
||||||
|
jq -r '.users[] | [.username, .password] | @tsv' /data/options.json |
|
||||||
|
while IFS="$(printf '\t')" read -r user pass; do
|
||||||
|
mosquitto_passwd -b "$PASSWD" "$user" "$pass"
|
||||||
|
done
|
||||||
|
chown mosquitto:mosquitto "$PASSWD"
|
||||||
|
chmod 0700 "$PASSWD"
|
||||||
|
|
||||||
|
[ -s "$PASSWD" ] || echo "Warning: no users defined, nobody can log in on the plain listener" >&2
|
||||||
|
|
||||||
|
exec mosquitto -c "$CONFIG/mosquitto.conf"
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
configuration:
|
||||||
|
users:
|
||||||
|
name: Users
|
||||||
|
description: List of MQTT users (username + password)
|
||||||
|
fields:
|
||||||
|
username:
|
||||||
|
name: Username
|
||||||
|
description: MQTT username
|
||||||
|
password:
|
||||||
|
name: Password
|
||||||
|
description: MQTT password
|
||||||
|
log_dest:
|
||||||
|
name: Log destinations
|
||||||
|
description: Where Mosquitto should send log messages (none, stdout, stderr, topic)
|
||||||
|
log_type:
|
||||||
|
name: Log types
|
||||||
|
description: Which log levels/events to enable (none, debug, error, warning, notice, information, subscribe, unsubscribe, websockets, all)
|
||||||
|
require_certificate:
|
||||||
|
name: Require client certificate
|
||||||
|
description: If enabled, clients must present a valid certificate signed by the CA
|
||||||
|
cafile:
|
||||||
|
name: CA certificate file
|
||||||
|
description: Filename of the CA certificate (relative to the ssl folder)
|
||||||
|
certfile:
|
||||||
|
name: Server certificate file
|
||||||
|
description: Filename of the Mosquitto server certificate (relative to the ssl folder)
|
||||||
|
keyfile:
|
||||||
|
name: Server private key file
|
||||||
|
description: Filename of the Mosquitto server private key (relative to the ssl folder)
|
||||||
|
|
||||||
|
network:
|
||||||
|
1883/tcp: MQTT (plain)
|
||||||
|
8883/tcp: MQTT over TLS
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
configuration:
|
||||||
|
users:
|
||||||
|
name: کاربران
|
||||||
|
description: لیست کاربران MQTT (نام کاربری + رمز عبور)
|
||||||
|
fields:
|
||||||
|
username:
|
||||||
|
name: نام کاربری
|
||||||
|
description: نام کاربری MQTT
|
||||||
|
password:
|
||||||
|
name: رمز عبور
|
||||||
|
description: رمز عبور MQTT
|
||||||
|
log_dest:
|
||||||
|
name: مقصدهای لاگ
|
||||||
|
description: محل ارسال پیامهای لاگ توسط برنامهی ماسکیتو (none، stdout، stderr، topic)
|
||||||
|
log_type:
|
||||||
|
name: انواع لاگ
|
||||||
|
description: سطوح و رویدادهای لاگ که باید فعال شوند (none، debug، error، warning، notice، information، subscribe، unsubscribe، websockets، all)
|
||||||
|
require_certificate:
|
||||||
|
name: نیاز به گواهی کلاینت
|
||||||
|
description: در صورت فعال بودن، کلاینتها باید گواهی معتبر امضا شده توسط CA ارائه دهند
|
||||||
|
cafile:
|
||||||
|
name: فایل گواهی CA
|
||||||
|
description: نام فایل گواهی CA (نسبت به پوشه ssl)
|
||||||
|
certfile:
|
||||||
|
name: فایل گواهی سرور
|
||||||
|
description: نام فایل گواهی سرور برنامهی ماسکیتو (نسبت به پوشه ssl)
|
||||||
|
keyfile:
|
||||||
|
name: فایل کلید خصوصی سرور
|
||||||
|
description: نام فایل کلید خصوصی سرور برنامهی ماسکیتو (نسبت به پوشه ssl)
|
||||||
|
|
||||||
|
network:
|
||||||
|
1883/tcp: پورت MQTT (ساده)
|
||||||
|
8883/tcp: پورت MQTT روی TLS
|
||||||
Reference in New Issue
Block a user