Skip to content

Commit 8ef3493

Browse files
committed
feat(storage): no longer require a password when spawning nbd-client
Ship some sudoers rules to let users belonging to the "mtda" group attach a network block device without a password. Signed-off-by: Cedric Hombourger <[email protected]>
1 parent c6b8d9a commit 8ef3493

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

debian/mtda-client.postinst

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
if ! getent group mtda >/dev/null; then
4+
addgroup --system mtda
5+
fi

debian/mtda-client.sudoers

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
%mtda ALL=(ALL) NOPASSWD: /usr/sbin/modprobe nbd
2+
%mtda ALL=(ALL) NOPASSWD: /usr/sbin/nbd-client -N mtda-storage [A-Za-z0-9.-]*
3+
%mtda ALL=(ALL) NOPASSWD: /usr/sbin/nbd-client -d /dev/nbd[0-9]*

debian/rules

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ override_dh_auto_install:
4444
mv debian/mtda-service/usr/bin/mtda-cli debian/mtda-client/usr/bin/
4545
install -m 0755 -d debian/mtda-client$(MTDA_DIST)/
4646
mv debian/mtda-service$(MTDA_DIST)/client.py debian/mtda-client$(MTDA_DIST)/
47+
install -m 0755 -d debian/mtda-client/etc/sudoers.d/
48+
install -m 0644 debian/mtda-client.sudoers debian/mtda-client/etc/sudoers.d/mtda-client
4749
:
4850
install -m 0755 -d debian/mtda-common$(MTDA_DIST)/
4951
mv debian/mtda-service$(MTDA_DIST)/constants.py debian/mtda-common$(MTDA_DIST)/

mtda/client.py

+3
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ def storage_network(self, remote):
109109
if rdev is None:
110110
raise RuntimeError('could not put storage on network')
111111

112+
cmd = ['sudo', '/usr/sbin/modprobe', 'nbd']
113+
subprocess.check_call(cmd)
114+
112115
cmd = ['sudo', cmd, '-N', 'mtda-storage', remote]
113116
subprocess.check_call(cmd)
114117

0 commit comments

Comments
 (0)