In order to keep track here, we need to do the following:
- generate an SSH key for root if missing
- deploy that SSH key for the users in question if missing
- deploy
our-user@.service
on the host - enable
our-user@.service
for the users in question
For that purpose, we built an RPM package (I guess the same will be possible with your favorite package management system as well), which looks like this:
[Unit] Description=Alternative User Manager for %I After=sshd.service [Service] ExecStartPre=/bin/bash -c "test -e ~/.ssh/id_rsa || ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa" ExecStartPre=/bin/bash -c "/usr/bin/ssh -oBatchMode=yes %I@localhost /usr/bin/echo || cat ~/.ssh/id_rsa.pub | /usr/bin/su -l %I -c 'tee -a ~/.ssh/authorized_keys'" ExecStart=/usr/bin/ssh %I@localhost /usr/lib/systemd/systemd --user Restart=on-failure [Install] WantedBy=default.targetNOTE: don't break the lines.
The noticeable difference to our first version is the addition of two additional ExecStartPre options which perform (1) and (2) of our TODO list. Especially (2) turned out to be very tricky using all sorts of shell magic.
The remaining points (3) and (4) requires us to perform remote execution powered by SaltStack's (also on github). This way, we can deploy our additional package hassle-freely on all affected hosts and with it the service unit. Enabling and starting the service (via salt) also performs steps (1) and (2) and we are all set!
Best,
Sven
No comments:
Post a Comment