atlantis icon indicating copy to clipboard operation
atlantis copied to clipboard

authenticating for a module with a private github.com repo source

Open kevinwsin opened this issue 8 years ago • 10 comments

Hello,

I'm trying to use a module sourced from a private github repo:

module "module-name" {
  source = "git::https://github.com/<org>/<repo>.git?ref=0.0.2"
}

but I get the following when Atlantis tries to run a plan:

- module.module-name
  Getting source "github.com/<org>/<repo>.git?ref=0.0.2"
Error downloading modules: Error loading modules: error downloading 'https://github.com/<org>/<repo>.git?ref=0.0.2': /usr/bin/git exited with 128: Cloning into '.terraform/modules/c8c0fdcb0c5f003da8e6dd67d5520576'...
fatal: could not read Username for 'https://github.com': No such device or address

I thought Atlantis would be able to use the same username and personal access token that it used to read the original github private repo.

Thanks in advance for the help!

kevinwsin avatar Sep 17 '18 20:09 kevinwsin

Hi Kevin,

I don't think Atlantis can use those secrets in this case because I don't know how to pass them to Terraform. The solutions I know of:

  1. Use a .gitconfig file in the /home/atlantis/.gitconfig that redirects the https urls, something like:

    [url "https://[email protected]"]
      insteadOf = https://github.com
    
  2. Switch to ssh urls ex. [email protected]:hashicorp/example.git and ensure that the ssh config on the Atlantis server has the right keys.

lkysow avatar Sep 17 '18 21:09 lkysow

I just ran into this, another possible way is to configure the git credentials.helper inside the environment / container

cat <<EOF > /credentials.sh
	#!/bin/bash
	echo username=\$ATLANTIS_GH_USER
	echo password=\$ATLANTIS_GH_TOKEN
EOF

git config --global credential.helper "/credentials.sh"

stephencoe avatar Sep 18 '18 12:09 stephencoe

Got it, thanks for the help everybody. Decided to add a SSH key for the atlantis github user.

kevinwsin avatar Sep 19 '18 15:09 kevinwsin

I hit this today. Luckily we pass the git credentials to Atlantis using environment variables, so I enabled git-credential-store helper and generated the /home/atlantis/.git-credentials credentials file on /usr/local/bin/docker-entrypoint.sh. But... This solution doesn't work if credentials are passed as arguments.

nikovirtala avatar Jan 11 '19 18:01 nikovirtala

Related issue: #176

sryabkov avatar Mar 08 '19 18:03 sryabkov

Possible implementation of passing the SSH key for a GitHub service account: https://gist.github.com/sryabkov/39f20f263c5edfa650522c6a2e9484b6

sryabkov avatar Apr 25 '19 15:04 sryabkov

How are you supposed to do this with the Fargate Deployment?

djaboxx avatar Jul 10 '19 00:07 djaboxx

How are you supposed to do this with the Fargate Deployment?

You need to build a custom image where you configure the git client and credentials helper in a way that you're able to access your private repositories. For example, the solution @stephencoe presented above works perfectly fine also on Fargate. My solution too; I am running Atlantis on Fargate.

nikovirtala avatar Jul 10 '19 20:07 nikovirtala

Seems like this is built in natively now based on #711 - just FYI.

chaseconey avatar Aug 29 '19 14:08 chaseconey

As far as I can tell, #711 only supports HTTPS authentication via a GitHub token.

sryabkov avatar Sep 17 '19 18:09 sryabkov