Skip to content

Commit

Permalink
feat(storage): no longer require a password when spawning nbd-client
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
chombourger committed Jan 30, 2025
1 parent c6b8d9a commit 8ef3493
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions debian/mtda-client.postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

if ! getent group mtda >/dev/null; then
addgroup --system mtda
fi
3 changes: 3 additions & 0 deletions debian/mtda-client.sudoers
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
%mtda ALL=(ALL) NOPASSWD: /usr/sbin/modprobe nbd
%mtda ALL=(ALL) NOPASSWD: /usr/sbin/nbd-client -N mtda-storage [A-Za-z0-9.-]*
%mtda ALL=(ALL) NOPASSWD: /usr/sbin/nbd-client -d /dev/nbd[0-9]*
2 changes: 2 additions & 0 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ override_dh_auto_install:
mv debian/mtda-service/usr/bin/mtda-cli debian/mtda-client/usr/bin/
install -m 0755 -d debian/mtda-client$(MTDA_DIST)/
mv debian/mtda-service$(MTDA_DIST)/client.py debian/mtda-client$(MTDA_DIST)/
install -m 0755 -d debian/mtda-client/etc/sudoers.d/
install -m 0644 debian/mtda-client.sudoers debian/mtda-client/etc/sudoers.d/mtda-client
:
install -m 0755 -d debian/mtda-common$(MTDA_DIST)/
mv debian/mtda-service$(MTDA_DIST)/constants.py debian/mtda-common$(MTDA_DIST)/
Expand Down
3 changes: 3 additions & 0 deletions mtda/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ def storage_network(self, remote):
if rdev is None:
raise RuntimeError('could not put storage on network')

cmd = ['sudo', '/usr/sbin/modprobe', 'nbd']
subprocess.check_call(cmd)

cmd = ['sudo', cmd, '-N', 'mtda-storage', remote]
subprocess.check_call(cmd)

Expand Down

0 comments on commit 8ef3493

Please sign in to comment.