Skip to main content

max / alloy

2.1 KB · 46 lines History Blame Raw
1 # Write this machine's USB policy before anything enforces one.
2 #
3 # The reasoning is all in usr/bin/alloy-usb-seed; this file is only what runs
4 # it. The short version: the image ships an empty rules.conf on purpose, and
5 # an empty policy plus ImplicitPolicyTarget=block is "deny every USB device on
6 # this machine". The seeder turns that into "allow what this machine already
7 # had", which is the only policy the machine itself can honestly assert.
8 #
9 # Ordering is the whole point of the unit. Before=usbguard.service, so the
10 # daemon never sees the empty file; After=systemd-udevd.service, so the bus has
11 # been enumerated and generate-policy has something to read. Without the second
12 # the policy would be written from a half-populated /sys and would deny whatever
13 # had not appeared yet.
14 #
15 # Not Wants=usbguard.service, and never Requires=. This must not be a reason for
16 # enforcement to start; it prepares the ground for a daemon that is armed
17 # somewhere else, and on the majority of machines — usbguard installed and not
18 # enabled — it writes a policy nothing reads. That is deliberate: it means the
19 # day a person arms enforcement from `alloy usb`, the policy is already there.
20 #
21 # The seeder is idempotent against a written policy, so this is enabled on every
22 # install rather than gated on a stamp. See the script for why the policy file
23 # itself is the state.
24
25 [Unit]
26 Description=Seed the USB device policy from this machine's own devices
27 Documentation=https://makenot.work/git/max/alloy
28 After=systemd-udevd.service
29 Wants=systemd-udevd.service
30 Before=usbguard.service
31 # On a machine with no usbguard the script exits saying so, which is harmless
32 # and pointless. The condition says it out loud instead.
33 ConditionPathExists=/usr/bin/usbguard
34
35 [Service]
36 Type=oneshot
37 RemainAfterExit=yes
38 ExecStart=/usr/bin/alloy-usb-seed
39 # The script returns 0 on every path it means to take, including the ones where
40 # it decides not to write anything, so a non-zero here is a real fault. It must
41 # not be fatal to the boot: a seeder that failed leaves the policy empty, and an
42 # empty policy is refused by usbguard's own drop-in rather than enforced.
43
44 [Install]
45 WantedBy=multi-user.target
46