icon, config
- Added app icon - added certificates and user management in app config - added user customization files in `/share`
This commit is contained in:
@@ -3,3 +3,8 @@
|
||||
## 0.1.0
|
||||
|
||||
- Initializing the Application
|
||||
|
||||
## 0.2.0
|
||||
|
||||
- Added app icon
|
||||
- Improved app configuration
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
FROM eclipse-mosquitto:2
|
||||
RUN apk add --no-cache jq
|
||||
COPY run.sh /run.sh
|
||||
RUN chmod a+x /run.sh
|
||||
CMD ["/run.sh"]
|
||||
+14
-1
@@ -1,5 +1,5 @@
|
||||
name: Visquitto
|
||||
version: "0.1.0"
|
||||
version: "0.2.0"
|
||||
slug: visquitto
|
||||
description: Second private Mosquitto broker for bitopa nodes
|
||||
arch:
|
||||
@@ -15,4 +15,17 @@ ports_description:
|
||||
8883/tcp: MQTT over TLS
|
||||
map:
|
||||
- addon_config:rw
|
||||
- share:rw
|
||||
- ssl:ro
|
||||
options:
|
||||
users: []
|
||||
cafile: mqtt-cert-manager-ca.crt
|
||||
certfile: mosquitto-server.key
|
||||
keyfile: mosquitto-server.key
|
||||
schema:
|
||||
users:
|
||||
- username: str
|
||||
password: password
|
||||
cafile: str
|
||||
certfile: str
|
||||
keyfile: str
|
||||
+82
-18
@@ -1,33 +1,97 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
mkdir -p /data/mosquitto /config/certs
|
||||
CONFIG=/config
|
||||
SHARE=/share/visquitto
|
||||
PASSWD=/data/passwd
|
||||
FINAL=/tmp/mosquitto.conf
|
||||
|
||||
mkdir -p "$SHARE" /data/mosquitto
|
||||
chown -R mosquitto:mosquitto /data/mosquitto
|
||||
|
||||
if [ ! -f /config/mosquitto.conf ]; then
|
||||
cat > /config/mosquitto.conf <<'EOF'
|
||||
CAFILE=$(jq -r '.cafile' /data/options.json)
|
||||
CERTFILE=$(jq -r '.certfile' /data/options.json)
|
||||
KEYFILE=$(jq -r '.keyfile' /data/options.json)
|
||||
|
||||
for f in "$CAFILE" "$CERTFILE" "$KEYFILE"; do
|
||||
[ -f "/ssl/$f" ] || { echo "Missing /ssl/$f" >&2; exit 1; }
|
||||
done
|
||||
|
||||
# ---- Defaults in /config (regenerated at every start) ----
|
||||
|
||||
cat > "$CONFIG/mosquitto.conf" <<EOF
|
||||
allow_anonymous false
|
||||
password_file /config/passwd
|
||||
acl_file /config/acl
|
||||
password_file $PASSWD
|
||||
persistence true
|
||||
persistence_location /data/mosquitto/
|
||||
|
||||
listener 1883
|
||||
listener 1993
|
||||
|
||||
listener 8883
|
||||
cafile /ssl/mqtt-cert-manager-ca.crt
|
||||
certfile /ssl/mosquitto-server.crt
|
||||
keyfile /ssl/mosquitto-server.key
|
||||
listener 9993
|
||||
cafile /ssl/$CAFILE
|
||||
certfile /ssl/$CERTFILE
|
||||
keyfile /ssl/$KEYFILE
|
||||
tls_version tlsv1.2
|
||||
EOF
|
||||
touch /config/acl
|
||||
|
||||
# Default ACL file: used only if the user's acl file doesn't set acl_file
|
||||
cat > "$CONFIG/acl" <<EOF
|
||||
acl_file $CONFIG/accesscontrollist
|
||||
EOF
|
||||
|
||||
# Default access control list: grants nothing
|
||||
cat > "$CONFIG/accesscontrollist" <<EOF
|
||||
# Default ACL: no rules, all access denied
|
||||
EOF
|
||||
|
||||
# ---- User customization in /share (created once, never overwritten) ----
|
||||
|
||||
if [ ! -f "$SHARE/mosquitto.conf" ]; then
|
||||
cat > "$SHARE/mosquitto.conf" <<EOF
|
||||
# Extra Mosquitto options, appended to the default config
|
||||
EOF
|
||||
fi
|
||||
|
||||
for f in passwd /ssl/mqtt-cert-manager-ca.crt /ssl/mosquitto-server.crt /ssl/mosquitto-server.key; do
|
||||
if [ ! -f "/config/$f" ]; then
|
||||
echo "Missing /config/$f, see the app docs" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
if [ ! -f "$SHARE/acl" ]; then
|
||||
cat > "$SHARE/acl" <<EOF
|
||||
acl_file /share/visquitto/accesscontrollist
|
||||
EOF
|
||||
fi
|
||||
|
||||
exec mosquitto -c /config/mosquitto.conf
|
||||
if [ ! -f "$SHARE/accesscontrollist" ]; then
|
||||
cat > "$SHARE/accesscontrollist" <<EOF
|
||||
# Visquitto ACL rules, for example:
|
||||
# user myuser
|
||||
# topic readwrite myprivate/#
|
||||
EOF
|
||||
fi
|
||||
|
||||
chown mosquitto:mosquitto "$SHARE/mosquitto.conf" "$SHARE/acl" "$SHARE/accesscontrollist"
|
||||
chown mosquitto:mosquitto "$CONFIG/acl" "$CONFIG/accesscontrollist"
|
||||
|
||||
# ---- 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 600 "$PASSWD"
|
||||
|
||||
[ -s "$PASSWD" ] || echo "Warning: no users defined, nobody can log in" >&2
|
||||
|
||||
# ---- Build the 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"; then
|
||||
cat "$SHARE/acl" >> "$FINAL"
|
||||
else
|
||||
cat "$CONFIG/acl" >> "$FINAL"
|
||||
fi
|
||||
|
||||
exec mosquitto -c "$FINAL"
|
||||
Reference in New Issue
Block a user