Skip to content

Commit 549e16b

Browse files
Refine /etc/matter layout for network-manager daemon
Change /etc/matter to be owned by root and group-readable and move non-factory data into /etc/matter/data; only this sub-directory is now owned by the matter user. Change permissions of chip_factory.ini to be no longer group or world readable. Run the daemon with umask 027 instead of the default 022. These changes make it easier to "factory reset" the Matter service by deleting /etc/matter/data, and lay the ground work for giving another daemon read-access to some files managed by the matter daemon via the matter group (e.g. letting hostapd read /etc/matter/network). Also simplify get_model_name() to use jsonfilter instead of jshn (this is the same logic also used in the otbr-agent init script). jsonfilter is a dependency of the base-files package, so is always already available in practice. Also add the missing jsonfilter dependency to the openthread-br package.
1 parent f36d845 commit 549e16b

4 files changed

Lines changed: 35 additions & 23 deletions

File tree

service/matter-netman/Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
include $(TOPDIR)/rules.mk
1616

1717
PKG_NAME:=matter-netman
18-
PKG_RELEASE:=1
18+
PKG_RELEASE:=2
1919
PKG_SOURCE_URL:=https://github.com/project-chip/connectedhomeip.git
2020
PKG_SOURCE_PROTO:=git
2121
PKG_SOURCE_SUBMODULES:=\
@@ -49,7 +49,7 @@ define Package/matter-netman/default
4949
CATEGORY:=Network
5050
TITLE:=Matter Network Infrastructure Manager Daemon
5151
URL:=https://github.com/project-chip/connectedhomeip
52-
DEPENDS:=+libstdcpp +libatomic +libubus +libubox
52+
DEPENDS:=+libstdcpp +libatomic +libubus +libubox +jsonfilter
5353
USERID:=matter:matter
5454
endef
5555

@@ -112,10 +112,10 @@ endif
112112
# Configuration / persistence
113113
CONF_DIR:=/etc/matter
114114
TARGET_CFLAGS+=\
115-
-DCHIP_CONFIG_KVS_PATH=\"$(CONF_DIR)/chip_kvs.ini\" \
116115
-DFATCONFDIR=\"$(CONF_DIR)\" \
117-
-DSYSCONFDIR=\"$(CONF_DIR)\" \
118-
-DLOCALSTATEDIR=\"$(CONF_DIR)\"
116+
-DSYSCONFDIR=\"$(CONF_DIR)/data\" \
117+
-DLOCALSTATEDIR=\"$(CONF_DIR)/data\" \
118+
-DCHIP_CONFIG_KVS_PATH=\"$(CONF_DIR)/data/chip_kvs.ini\"
119119

120120
# Device Information. Runtime information is configured by bootstrap.sh
121121
include $(INCLUDE_DIR)/version.mk

service/matter-netman/files/bootstrap.sh

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# limitations under the License.
1414

1515
type get_mac_label >/dev/null || . /lib/functions/system.sh
16-
type json_init >/dev/null || . /usr/share/libubox/jshn.sh
1716

1817
random_uint32() {
1918
hexdump -n 4 -e '4 "%u"' /dev/urandom
@@ -35,17 +34,7 @@ random_pincode() {
3534
}
3635

3736
get_model_name() {
38-
local model
39-
local cfg="/etc/board.json"
40-
[ -s "$cfg" ] || return
41-
json_init
42-
json_load "$(cat $cfg)"
43-
if json_is_a model object; then
44-
json_select model
45-
json_get_var model name
46-
json_select ..
47-
fi
48-
echo "$model"
37+
jsonfilter -q -i /etc/board.json -e @.model.name
4938
}
5039

5140
generate_factory_ini() {
@@ -62,14 +51,37 @@ generate_factory_ini() {
6251
}
6352

6453
matter_bootstrap() {
65-
mkdir -p /etc/matter
66-
chown matter:matter /etc/matter
67-
chmod 0700 /etc/matter
54+
# create /etc/matter and /etc/matter/data if needed
55+
if ! [ -d /etc/matter/data ]; then
56+
if ! [ -d /etc/matter ]; then
57+
mkdir -m 0750 /etc/matter
58+
chgrp matter /etc/matter
59+
fi
60+
mkdir -m 0700 /etc/matter/data
61+
chown matter:matter /etc/matter/data
62+
fi
63+
64+
# generate factory config if necessary
6865
local ini=/etc/matter/chip_factory.ini
6966
if ! [ -s "$ini" ]; then
70-
generate_factory_ini >"${ini}.tmp"
67+
rm -f "${ini}.tmp"
68+
( umask 277; generate_factory_ini >"${ini}.tmp" )
69+
chown matter:matter "${ini}.tmp"
7170
mv "${ini}.tmp" "$ini"
7271
fi
72+
73+
# migration: /etc/matter used to be owned by matter
74+
if ! [ -O /etc/matter ]; then
75+
chmod 0400 /etc/matter/chip_factory.ini
76+
chown matter:matter /etc/matter/chip_factory.ini
77+
chmod 0750 /etc/matter
78+
chown root:matter /etc/matter
79+
fi
80+
81+
# migration: data used to live in /etc/matter directly
82+
if [ -f /etc/matter/chip_kvs.ini -a ! -f /etc/matter/data/chip_kvs.ini ]; then
83+
mv -n /etc/matter/chip_config.ini /etc/matter/chip_counters.ini /etc/matter/chip_kvs.ini /etc/matter/data/
84+
fi
7385
}
7486

7587
[ -n "$INCLUDE_ONLY" ] || matter_bootstrap

service/matter-netman/files/matter.init

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ start_service() {
2323
. /usr/share/matter/bootstrap.sh
2424

2525
procd_open_instance
26-
procd_set_param command "$PROG"
26+
procd_set_param command /bin/sh -c 'umask 027; exec "$@"' - "$PROG"
2727
procd_set_param user matter
2828
procd_set_param group matter
2929
procd_set_param respawn

third_party/openthread-br/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ define Package/openthread-br/Default
5757
CATEGORY:=Network
5858
TITLE:=OpenThread Border Router
5959
URL:=https://github.com/openthread/ot-br-posix
60-
DEPENDS:=+libstdcpp +OPENTHREADBR_SHARED_MBEDTLS:libmbedtls +libjson-c +libubus +libubox +kmod-usb-acm +kmod-tun
60+
DEPENDS:=+libstdcpp +OPENTHREADBR_SHARED_MBEDTLS:libmbedtls +libjson-c +libubus +libubox +kmod-usb-acm +kmod-tun +jsonfilter
6161
endef
6262

6363
define Package/openthread-br/Default/description

0 commit comments

Comments
 (0)