I looked into this for a good several hours, it seems the method sd_bus_start was changed to include additional checks. I wasn't able to narrow down what else it is looking for, however I was able to come up with a more elegant solution to accomplish the same task using remote systemctl commands instead of mounting all the directories from the host.
Remote systemctl
systemctl
supports remote commands via the --host / -H
flag. It is using ssh to connect to the remote host, so an ssh key pair will be needed. Since we are controlling the host we are on, this is pretty straightforward to setup.
Docker command (or Kubernetes arg)
Here is the full command that can be used, I will break down each part below. The assumptions of the container are that it has systemctl
and ssh
installed, the container is running on the host network, and that the root
account's home directory is mounted (you can use another use if you want).
(ls ~/.ssh/id_rsa || ssh-keygen -b 2048 -t rsa -f ~/.ssh/id_rsa -q -N "")
&& (grep -qxF $(cat ~/.ssh/id_rsa.pub) ~/.ssh/authorized_keys || echo $(cat ~/.ssh/id_rsa.pub) > ~/.ssh/authorized_keys)
&& (grep -qxF "StrictHostKeyChecking no" ~/.ssh/config || echo "StrictHostKeyChecking no" >> ~/.ssh/config)
&& (grep -qxF "UserKnownHostsFile /dev/null" ~/.ssh/config || echo "UserKnownHostsFile /dev/null" >> ~/.ssh/config)
&& systemctl -H [email protected] start nfs-server.service
This command is seeing if the ~/.ssh/id_rsa
file exists, otherwise create one.
(ls ~/.ssh/id_rsa || ssh-keygen -b 2048 -t rsa -f ~/.ssh/id_rsa -q -N "")
Now we add our public key to our authorized keys if it does not exist in the file already.
(grep -qxF "$(cat ~/.ssh/id_rsa.pub)" ~/.ssh/authorized_keys || echo "$(cat ~/.ssh/id_rsa.pub)" > ~/.ssh/authorized_keys)
This can probably be made more secure by putting it in a section of the ssh config only for 127.0.0.1
, but we need
(grep -qxF "StrictHostKeyChecking no" ~/.ssh/config || echo "StrictHostKeyChecking no" >> ~/.ssh/config)
&& (grep -qxF "UserKnownHostsFile /dev/null" ~/.ssh/config || echo "UserKnownHostsFile /dev/null" >> ~/.ssh/config)
Finally we have the actual systemctl
command. Notice the -H [email protected]
.
systemctl -H [email protected] start nfs-server.service
For maximum security, it would be best to setup the keys and users outside of the containers first (via Ansible or similar) and only allow the systemctl -H
command inside the container.