You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As a Chef user in an enterprise setting, I want to consume cookbooks/profiles from private git repos.
E.g. Internal policies require that all source code is stored in authenticated repositories that limit who can access the code. Currently, the effortless pattern has no mechanism to provide credentials or keys to facilitate this authentication.
Specification
Add scaffolding variables to allow user to provide either credentials or ssh key for authenticating.
Downstream Impact
Since this will only add the ability to auth, no downstream impact is expected.
I did some research and opened an issue for this against habitat and here are the results of what needs to be done to make this work.
First, you need to be using the Habitat Docker Studio to do the builds. The reason for this is so that you can mount your .ssh folder into the studio. Before launching the studio or running hab pkg build you need to set the HAB_DOCKER_OPTS environment variable. Here is an example of how to do this on Windows and Linux
windows:
$env:HAB_DOCKER_OPTS = 'c:/users/<your_username>/.ssh:<full path studio user>/.ssh'
The user for a Linux studio is root and the user for a Windows studio is ContainerAdministrator.
If you are doing this on windows the file permissions for the ssh key won't work when building a Linux habitat package. To fix this, you will need to mount the .ssh directory to /tmp instead of directly to the /root location and then copy the directory to /root/.ssh. Once that is done you will then need to change the permissions on the id_rsa key as well as the id_ras.pub key so that chef can use it here is a little script to do that
If you have too many keys in your SSH dir it may not work, as you may hit the attempt limit before it finds the right key
The best solution here would be to use an external secrets management service like Vault, AWS SecretsManager, Habitat Builder origin secrets, etc. What would be helpful then is if the scaffolding could look for a particular variable (git_private_key) and base64decode its contents and put them in an ssh key file for use by git automatically. This could then be configured using origin secrets or alternately exported into the habitat environment by the user or CI system with something like HAB_STUDIO_SECRET_git_private_key=<keydata> hab pkg build -D ..
Activity
TheLunaticScripter commentedon Mar 25, 2020
I did some research and opened an issue for this against habitat and here are the results of what needs to be done to make this work.
First, you need to be using the Habitat Docker Studio to do the builds. The reason for this is so that you can mount your
.sshfolder into the studio. Before launching the studio or runninghab pkg buildyou need to set theHAB_DOCKER_OPTSenvironment variable. Here is an example of how to do this on Windows and Linuxwindows:
Linux:
The user for a Linux studio is
rootand the user for a Windows studio isContainerAdministrator.If you are doing this on windows the file permissions for the ssh key won't work when building a Linux habitat package. To fix this, you will need to mount the
.sshdirectory to/tmpinstead of directly to the/rootlocation and then copy the directory to/root/.ssh. Once that is done you will then need to change the permissions on theid_rsakey as well as theid_ras.pubkey so that chef can use it here is a little script to do thatThis should be all the steps needed to get you working with using git in your policyfiles.
I'm going to leave this open as a Design Proposal as this is not the greatest way to do this and there may be room for improvement.
mbainter commentedon Aug 28, 2020
FYI - the above description leaves out the required option flag (--volume or -v).
mbainter commentedon Sep 3, 2020
This solution has a few problems:
The best solution here would be to use an external secrets management service like Vault, AWS SecretsManager, Habitat Builder origin secrets, etc. What would be helpful then is if the scaffolding could look for a particular variable (git_private_key) and base64decode its contents and put them in an ssh key file for use by git automatically. This could then be configured using origin secrets or alternately exported into the habitat environment by the user or CI system with something like
HAB_STUDIO_SECRET_git_private_key=<keydata> hab pkg build -D ..