Open mpvader opened 5 years ago
Settings/System/MqttOnLanInsecure
named MQTT on LAN (insecure)
. Implemented just like the local ssh port was done [1], but then controlling 1883 rather than port 22.[1] https://github.com/victronenergy/gui/commit/972a978374e7ab13b56bb72d28a856e9490c30ee [2] https://github.com/victronenergy/localsettings/commit/c23cbd49e4e73fddf720a9e284adbc114c4826f4
(after downgrading, remember to remove the newly made settings)
Only VRM two-way enabled:
1883, 8883 and 9001 must all be disallowed.
root@beaglebone:~# iptables -nvL
Chain INPUT (policy ACCEPT 45 packets, 9456 bytes)
pkts bytes target prot opt in out source destination
18053 3811K ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0
1234 415K new-conn all -- * * 0.0.0.0/0 0.0.0.0/0 ctstate NEW
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 290 packets, 135K bytes)
pkts bytes target prot opt in out source destination
Chain new-conn (1 references)
pkts bytes target prot opt in out source destination
2 128 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:22
0 0 REJECT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:1883 reject-with icmp-port-unreachable
0 0 REJECT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:9001 reject-with icmp-port-unreachable
0 0 REJECT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:8883 reject-with icmp-port-unreachable
PASS
Allow 8883:
root@beaglebone:~# iptables -nvL
Chain INPUT (policy ACCEPT 45 packets, 8360 bytes)
pkts bytes target prot opt in out source destination
26784 4763K ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0
1840 596K new-conn all -- * * 0.0.0.0/0 0.0.0.0/0 ctstate NEW
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 123 packets, 173K bytes)
pkts bytes target prot opt in out source destination
Chain new-conn (1 references)
pkts bytes target prot opt in out source destination
2 128 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:22
0 0 REJECT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:1883 reject-with icmp-port-unreachable
0 0 REJECT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:9001 reject-with icmp-port-unreachable
0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:8883
Allows 8883: PASS.
oot@beaglebone:~# iptables -nvL
Chain INPUT (policy ACCEPT 74 packets, 26998 bytes)
pkts bytes target prot opt in out source destination
26835 4814K ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0
2114 684K new-conn all -- * * 0.0.0.0/0 0.0.0.0/0 ctstate NEW
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 29 packets, 28016 bytes)
pkts bytes target prot opt in out source destination
Chain new-conn (1 references)
pkts bytes target prot opt in out source destination
2 128 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:22
0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:8883
0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:1883
0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:9001
root@beaglebone:~#
Allows all three: PASS
root@beaglebone:~# iptables -nvL
Chain INPUT (policy ACCEPT 38 packets, 8032 bytes)
pkts bytes target prot opt in out source destination
26890 4899K ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0
2158 693K new-conn all -- * * 0.0.0.0/0 0.0.0.0/0 ctstate NEW
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 95 packets, 99223 bytes)
pkts bytes target prot opt in out source destination
Chain new-conn (1 references)
pkts bytes target prot opt in out source destination
2 128 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:22
0 0 REJECT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:8883 reject-with icmp-port-unreachable
0 0 REJECT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:1883 reject-with icmp-port-unreachable
0 0 REJECT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:9001 reject-with icmp-port-unreachable
PASS.
netcat -v 192.168.178.122 9001 -w 5
and similar: all PASS.
PASS for all switch combinations.
PASS
PASS (both for enabled and disabled).
skipped; I don't know how to easily test this.
svc -d /service/localsettings
rm /data/conf/settings.xml
rm -rf /data/conf/mosquitto.d
rm /data/conf/mqtt_password.txt
Status (updated by MVA on 2020-01-29)
All changes in naming of feature on/off switching in Venus OS, as well as what services they enable and disable, and ports that they open and close, are completed, and implemented per v2.40. Also that completes everything when connecting to Venus OS with VictronConnect over MQTT via VRM, ie. remotely.
Remaining todo list
See also below section 3, security details and passwords, for details.
Details
0. Requirements of the change
1. End result of the settings and their functionality
There will be three settings relating to MQTT:
VRM Two Way Communication
- enable/disableMQTT on LAN (ssl)
- enable/disableMQTT on LAN (plaintext)
- enable/disable (can only be enabled if its secure variant is also enabled)Functionality:
If either of them is enabled, start dbus-mqtt & mqtt-rpc & mosquitto. So technically all is available.
And then open/close ports using iptables and enable/disable the bridge configs to our cloud brokers to control the individual features:
2. Migration:
To not break any existing systems:
MQTT on LAN
andMQTT on VRM
; and also enableMQTT on LAN insecure
, since that is how that works now and its used, for example, on certain externally managed ESS type installations.MQTT on VRM
.3. Security and passwords
Everything via VRM, is already secured. The connection between the local broker and the VRM broker is MQTT over SSL, using a Victron root CA certificate and pre-shared token. The connection between the client and the VRM-broker is also over SSL, and uses the VRM system for authentication.
We also want to secure local connections that use MQTT. The idea is to self generate a SSL certificate and private key pair on the Venus device at boot. And every new VictronConnect install that connects to that device, locally, will ask the user once to accept the certificate, showing its hash (aka finger print). On Remote Console, the same is visible, for cautious people to go and check before they accept it. If and how its possible to that in VictronConnect, needs to be looked into.
Also there will be a password on MQTT. But then preferably make a general password; instead of adding yet another one to the list (Remote Console & WiFi Access point). One option is to re-use the WiFi password for that on the Venus GX-es; in other words, promoting that to a general access password. Note that the CCGX does not have a factory installed password. Also note that the WiFi Password is currently not changeable on the Venus GX. But, with the planned new feature to have a reset button, that is easily over come.
On the topic of passwords and such, note that there is another one coming: the bluetooth pin code.