When we provision new linux servers, we
- create a new user with sudo rights, and...
- block root from ssh access
And then we proceed to configure the system via the new user account. Of course we do it this way because our logs are full of hostile ssh root login attempts.
But now we're trying to use Chef (chef solo with knife-solo and librarian-chef) to build servers. Once we create a recipe that blocks ssh login from root, we can't run the recipes again.
I have seen this: How to run chef-client vagrant provisioner from custom non-root user? but it seems like "root" is hardcoded all over the place and the accepted solution would require branching all the basic cookbooks.
Any ideas on how to create a re-runnable Chef setup that includes disabling root ssh access ?
It's not unusual to bootstrap servers using a non-root account. As @StephenKing pointed out, knife supports this. The following is my normal procedure:
However, this answer assumes you're using a chef server (highly recommended)....
You are using a non-standard knife plugin to emulate this bootstrapping behavior. The documentation states that sudo will be used by the "knife solo prepare" command:
And the "knife solo bootstrap" command appears to support similar options to the standard bootstrap.
I notice all kinds of funky stuff including an option to use chef zero (a feature now supported in chef-client).
Hope this helps, but I'd advise considering the use of chef-server. It's easy to stand up and you will then be following a standard way of using chef.
Update
An interesting read: