Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for git https credentials #23

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

NikolausDemmel
Copy link
Contributor

This builds on top of PR #22, so that should be merged first.

This implements #21. It is a simple way to provide git credentials not only for
ssh via keys, but also for https. In corporate settings with internet access
through proxies, ssh is often not allowed and one is forced to use https.

There are two ways to use this, either you provide a credential store and mount
it when running vault.

docker run -p 172.17.0.1:14242:3000 -v $PWD/store:/vault/store vault

Alternatively you can also start the vault with an empty store and interactively
add / remove credentials.

docker run -p 172.17.0.1:14242:3000 --name vault vault

# the following prompts you for a username and password which are stored in the
# running container
docker exec -it vault credentials set github.com

The usage inside a Dockerfile is the same as for the ssh key. Simply prepend
your git clone or other commands with ONVAULT.

The changes are really fairly simple:

  • One route is added in index.js to download the file with the credentials.
  • ONVAULT is extended to download the additional file and configure git, as
    well as revert the changes after executing the passed command.
  • The credential helper script is added to the container. This is actually
    not essential, but more of a convenience such that you don't need to create
    the credential files manually.

I did not yet update the README, but I can do that before merge if you are
willing to include this addition.

closes #21

Without this, building Dockerfiles with ONVAULT fails in the presence of
an http proxy.
This implements dockito#21. It is a simple way to provide git credentials not only for
ssh via keys, but also for https. In corporate settings with internet access
through proxies, ssh is often not allowed and one is forced to use https.

There are two ways to use this, either you provide a credential store and mount
it when running `vault`.

```
docker run -p 172.17.0.1:14242:3000 -v $PWD/store:/vault/store vault
```

Alternatively you can also start the vault with an empty store and interactively
add / remove credentials.

```
docker run -p 172.17.0.1:14242:3000 --name vault vault

# the following prompts you for a username and password which are stored in the
# running container
docker exec -it vault credentials set github.com
```

The usage inside a `Dockerfile` is the same as for the ssh key. Simply prepend
your `git clone` or other commands with `ONVAULT`.

The changes are really fairly simple:

 - One route is added in `index.js` to download the file with the credentials.
 - ONVAULT is extended to download the additional file and configure git, as
   well as revert the changes after executing the passed command.
 - The `credential` helper script is added to the container. This is actually
   not essential, but more of a convenience such that you don't need to create
   the credential files manually.

I did not yet update the README, but I can do that before merge if you are
willing to include this addition.

closes dockito#21
if [[ "$VAULT_SSH_KEY" != "id_rsa" ]]; then
# configure the ssh to any host to use this ssh key
echo -e "\nHost *\nIdentityFile ~/.ssh/$VAULT_SSH_KEY" >> ~/.ssh/config
fi

# download git credential store to temporary location
tmp_git_credential_store=`mktemp ~/.git-credentials-XXXXXX`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed the mktemp from the script to allow using it with Linux distros without this command.
Please take a look at c202988.

@maxcnunes
Copy link
Member

Hi @NikolausDemmel,

The reasons for including this feature seems right to me. I have not looked deeply in your changes because I didn't have much free time this weekend. But from I what I have seen it looks good. I just have to test it carefully before merging it into master. I will save some free time during this week for this. Until there if you could also include the docs would be awesome. Thanks.


# restoring old setting
git config --global credential.helper "$git_config_old_credential_helper"
git config --global core.askpass "$git_config_old_core_askpass"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: I need to test this "restoring" of the git config.

@NikolausDemmel
Copy link
Contributor Author

I will save some free time during this week for this.

Cool, thanks! Yes, I will update the docs and remove mktemp, but I might not get round to it before the weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extension to support git https credentials
2 participants