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
|
## 0.1.0
|
||||||
|
|
||||||
- Initializing the Application
|
- Initializing the Application
|
||||||
|
|
||||||
|
## 0.2.0
|
||||||
|
|
||||||
|
- Added app icon
|
||||||
|
- Improved app configuration
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
FROM eclipse-mosquitto:2
|
FROM eclipse-mosquitto:2
|
||||||
|
RUN apk add --no-cache jq
|
||||||
COPY run.sh /run.sh
|
COPY run.sh /run.sh
|
||||||
RUN chmod a+x /run.sh
|
RUN chmod a+x /run.sh
|
||||||
CMD ["/run.sh"]
|
CMD ["/run.sh"]
|
||||||
+15
-2
@@ -1,5 +1,5 @@
|
|||||||
name: Visquitto
|
name: Visquitto
|
||||||
version: "0.1.0"
|
version: "0.2.0"
|
||||||
slug: visquitto
|
slug: visquitto
|
||||||
description: Second private Mosquitto broker for bitopa nodes
|
description: Second private Mosquitto broker for bitopa nodes
|
||||||
arch:
|
arch:
|
||||||
@@ -15,4 +15,17 @@ ports_description:
|
|||||||
8883/tcp: MQTT over TLS
|
8883/tcp: MQTT over TLS
|
||||||
map:
|
map:
|
||||||
- addon_config:rw
|
- addon_config:rw
|
||||||
- ssl:ro
|
- 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
|
#!/bin/sh
|
||||||
set -e
|
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
|
chown -R mosquitto:mosquitto /data/mosquitto
|
||||||
|
|
||||||
if [ ! -f /config/mosquitto.conf ]; then
|
CAFILE=$(jq -r '.cafile' /data/options.json)
|
||||||
cat > /config/mosquitto.conf <<'EOF'
|
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
|
allow_anonymous false
|
||||||
password_file /config/passwd
|
password_file $PASSWD
|
||||||
acl_file /config/acl
|
|
||||||
persistence true
|
persistence true
|
||||||
persistence_location /data/mosquitto/
|
persistence_location /data/mosquitto/
|
||||||
|
|
||||||
listener 1883
|
listener 1993
|
||||||
|
|
||||||
listener 8883
|
listener 9993
|
||||||
cafile /ssl/mqtt-cert-manager-ca.crt
|
cafile /ssl/$CAFILE
|
||||||
certfile /ssl/mosquitto-server.crt
|
certfile /ssl/$CERTFILE
|
||||||
keyfile /ssl/mosquitto-server.key
|
keyfile /ssl/$KEYFILE
|
||||||
tls_version tlsv1.2
|
tls_version tlsv1.2
|
||||||
EOF
|
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
|
fi
|
||||||
|
|
||||||
for f in passwd /ssl/mqtt-cert-manager-ca.crt /ssl/mosquitto-server.crt /ssl/mosquitto-server.key; do
|
if [ ! -f "$SHARE/acl" ]; then
|
||||||
if [ ! -f "/config/$f" ]; then
|
cat > "$SHARE/acl" <<EOF
|
||||||
echo "Missing /config/$f, see the app docs" >&2
|
acl_file /share/visquitto/accesscontrollist
|
||||||
exit 1
|
EOF
|
||||||
fi
|
fi
|
||||||
done
|
|
||||||
|
|
||||||
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