Skip to content

Commit 4680780

Browse files
committed
fix: set cert to HA IP and remove old certs on every start
MeshCentral validates Origin header against its cert CN. When the cert was generated with hostname 'homeassistant' but browser connects via IP 192.168.x.x:4430, the origin check fails with 'Invalid origin'. Two fixes: 1. Set cert in config.json to HA's actual IP address (or cert_url host for external access) so the generated cert matches what browser sends 2. Remove old .crt/.key files on every start so MeshCentral always regenerates certs with the current IP/hostname Bump version to 0.2.9.
1 parent ca9858a commit 4680780

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

meshcentral/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "MeshCentral",
3-
"version": "0.2.8",
3+
"version": "0.2.9",
44
"slug": "meshcentral",
55
"description": "Self-hosted remote device management — monitor and control your PCs from Home Assistant",
66
"url": "https://github.com/andlo/ha-meshcentral-addon",

meshcentral/run.sh

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,26 @@ if bashio::config.has_value 'hostname'; then
2525
HOSTNAME=$(bashio::config 'hostname')
2626
fi
2727

28+
# Get HA's local IP for cert — this is what users browse to
29+
HA_IP=$(bashio::info.ip_address 2>/dev/null || echo "")
30+
2831
bashio::log.info "Starting MeshCentral..."
2932
bashio::log.info "Server mode: ${SERVER_MODE}"
3033
bashio::log.info "Hostname: ${HOSTNAME}"
34+
if [ -n "$HA_IP" ]; then
35+
bashio::log.info "IP address: ${HA_IP}"
36+
fi
3137

3238
mkdir -p "${DATA_PATH}" "${FILES_PATH}" "${BACKUP_PATH}" "${RECORDINGS_PATH}"
3339

40+
# Remove old certs on every start so MeshCentral regenerates them with current config
41+
# This ensures the cert CN always matches the current IP/hostname
42+
MESHDATA="${DATA_PATH}/meshcentral-data"
43+
if [ -d "$MESHDATA" ]; then
44+
rm -f "$MESHDATA"/*.crt "$MESHDATA"/*.key 2>/dev/null || true
45+
bashio::log.info "Old certificates removed — will be regenerated with current settings."
46+
fi
47+
3448
# ── Build settings ────────────────────────────────────────────────────────────
3549

3650
SETTINGS="{}"
@@ -43,9 +57,16 @@ elif [ "$SERVER_MODE" = "lan" ]; then
4357
fi
4458
# hybrid: neither flag set — MeshCentral default behaviour
4559

46-
# Ports — use external ports so MeshCentral knows its public address
47-
# HA maps container 443→4430 and 80→4431 externally
60+
# Ports — MeshCentral listens directly on external ports to avoid origin mismatch
4861
SETTINGS=$(echo "$SETTINGS" | jq '. + {port: 4430, redirPort: 4431, mpsPort: 4433}')
62+
63+
# Cert — set to HA IP so MeshCentral's origin check matches what the browser sends
64+
if bashio::config.has_value 'cert_url'; then
65+
CERT_HOST=$(bashio::config 'cert_url' | sed 's|https://||' | sed 's|http://||' | sed 's|/.*||')
66+
SETTINGS=$(echo "$SETTINGS" | jq --arg v "$CERT_HOST" '. + {cert: $v}')
67+
elif [ -n "$HA_IP" ]; then
68+
SETTINGS=$(echo "$SETTINGS" | jq --arg v "$HA_IP" '. + {cert: $v}')
69+
fi
4970
SETTINGS=$(echo "$SETTINGS" | jq --argjson v "$TLS_OFFLOAD" '. + {tlsOffload: $v}')
5071

5172
# Trusted proxy (optional)

0 commit comments

Comments
 (0)