canonical / charm-local-users

A subordinate charm for creating and managing local user accounts and groups on principal units.
Apache License 2.0
0 stars 4 forks source link

`sudoers` config does not work without a newline at the end #50

Open marcusboden opened 1 month ago

marcusboden commented 1 month ago

If you set the sudoers option with

juju config local-users sudoers="%group ALL=(root) NOPASSWD: /bin/cat /etc/libvirt/qemu/instance-????????.xml"

the visudo check will not pass:

unit-local-users-2359: 07:39:29 DEBUG unit.local-users/2359.juju-log Checking sudoers file: visudo -c -f /tmp/tmpxscrhu6c
unit-local-users-2359: 07:39:29 DEBUG unit.local-users/2359.juju-log Stdout: b'parse error in /tmp/tmpxscrhu6c near line 1\n', Stderr: b'>>> /tmp/tmpxscrhu6c: syntax error near line 1 <<<\n'
unit-local-users-2359: 07:39:29 DEBUG unit.local-users/2359.juju-log Cleaning up /tmp/tmpxscrhu6c

It works if you write it into a file and apply that:

$ cat sudoers 
%group ALL=(root) NOPASSWD: /bin/cat /etc/libvirt/qemu/instance-????????.xml
$ juju config local-users sudoers=@sudoers

And a small side note: It may be helpful to a) display the visudo output in the log at info or warning level, if the check failed and b) print the content of the file as well (as it is removed afterwards, so checking it for errors is hard)