diff --git a/visquitto/CHANGELOG.md b/visquitto/CHANGELOG.md index 0837474..7bf6bce 100644 --- a/visquitto/CHANGELOG.md +++ b/visquitto/CHANGELOG.md @@ -28,3 +28,8 @@ ## 0.2.5 - Minor bug fix + +## 0.3.0 + +- Added separated ACL's +- Improved logging capabilities diff --git a/visquitto/config.yaml b/visquitto/config.yaml index d5cb4a9..3446832 100644 --- a/visquitto/config.yaml +++ b/visquitto/config.yaml @@ -1,5 +1,5 @@ name: Visquitto -version: "0.2.5" +version: "0.3.0" slug: visquitto description: Second private Mosquitto broker for bitopa nodes arch: @@ -19,6 +19,10 @@ map: - ssl:ro options: users: [] + log_dest: [] + log_type: [] + nodes: [] + require_certificate: false cafile: mqtt-cert-manager-ca.crt certfile: mosquitto-server.crt keyfile: mosquitto-server.key @@ -26,6 +30,10 @@ schema: users: - username: str password: password + nodes: + log_dest: [] + log_type: [] + require_certificate: false cafile: str certfile: str keyfile: str \ No newline at end of file diff --git a/visquitto/run.sh b/visquitto/run.sh index 2e134e5..1874596 100644 --- a/visquitto/run.sh +++ b/visquitto/run.sh @@ -1,22 +1,25 @@ #!/bin/sh set -e - -# every file the script creates is private from the start umask 077 CONFIG=/config SHARE=/share/visquitto +DATA=/data/mosquitto PASSWD=/data/passwd CERTDIR=/data/certs -FINAL=/tmp/mosquitto.conf -mkdir -p "$SHARE" /data/mosquitto "$CERTDIR" -chown -R mosquitto:mosquitto /data/mosquitto +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; } @@ -31,49 +34,111 @@ chmod 600 "$CERTDIR/key.pem" # ---- Defaults in /config (regenerated at every start) ---- cat > "$CONFIG/mosquitto.conf" < "$CONFIG/acl.conf" < "$CONFIG/acl_plain" +cat > "$CONFIG/acl_plain" < "$CONFIG/accesscontrollist" < "$CONFIG/acl_tls" +cat > "$CONFIG/acl_tls" < "$SHARE/mosquitto.conf" + echo "# Extra global Mosquitto options (loaded with include_dir, before the listeners)" > "$SHARE/mosquitto.conf" fi -if [ ! -f "$SHARE/acl.conf" ]; then - echo "acl_file /share/visquitto/accesscontrollist" > "$SHARE/acl.conf" -fi - -if [ ! -f "$SHARE/accesscontrollist" ]; then - cat > "$SHARE/accesscontrollist" < "$SHARE/acl_plain" < "$SHARE/acl_tls" < "$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" @@ -83,19 +148,8 @@ while IFS="$(printf '\t')" read -r user pass; do mosquitto_passwd -b "$PASSWD" "$user" "$pass" done chown mosquitto:mosquitto "$PASSWD" -chmod 600 "$PASSWD" +chmod 0700 "$PASSWD" -[ -s "$PASSWD" ] || echo "Warning: no users defined, nobody can log in" >&2 +[ -s "$PASSWD" ] || echo "Warning: no users defined, nobody can log in on the plain listener" >&2 -# ---- Final config: defaults + user config + ACL ---- -cat "$CONFIG/mosquitto.conf" > "$FINAL" -echo >> "$FINAL" -cat "$SHARE/mosquitto.conf" >> "$FINAL" -echo >> "$FINAL" -if grep -q '^[[:space:]]*acl_file' "$SHARE/acl.conf"; then - cat "$SHARE/acl.conf" >> "$FINAL" -else - cat "$CONFIG/acl.conf" >> "$FINAL" -fi - -exec mosquitto -c "$FINAL" \ No newline at end of file +exec mosquitto -c "$CONFIG/mosquitto.conf" \ No newline at end of file