atlantis: helm chart gitconfig option ignored

Running terraform with modules imported from private gitLab fails using the /etc/secret-gitconfig/gitconfig mounted helm gitconfig option. If I copy this file to /home/atlantis/.gitconfig then terraform succeeds. Atlantis appears to be ignoring the mounted /etc/secret-gitconfig/gitconfig file?

Error: Failed to download module

Could not download module "eks_ingress" (main.tf:109) source code from
"git::https://git.mycompany.com/high-five/tf-modules/eks-ingress.git?ref=v2.0.0":
error downloading
'https://git.mycompany.com/high-five/tf-modules/eks-ingress.git?ref=v2.0.0':
/usr/bin/git exited with 128: Cloning into '.terraform/modules/eks_ingress'...
remote: Not Found
fatal: repository 'https://github.com/high-five/tf-modules/eks-ingress.git/'
not found

File contents: /etc/secret-gitconfig/gitconfig

[url "https://username:password@git.mycompany.com/"]
	insteadOf = https://git.mycompany.com/

Helm Chart:

gitconfig: |
   [url "https://username:password@git.mycompany.com/""]
     insteadOf = https://git.mycompany.com/

Atlantis version:

- name: atlantis
  repository: https://runatlantis.github.io/helm-charts
  version: "3.12.4"

  image:
    repository: runatlantis/atlantis
    tag: v0.15.1

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 17 (7 by maintainers)

Most upvoted comments

there’s a poststart hook in the statefulset that copies /etc/secret-gitconfig/gitconfig to /home/atlantis/.gitconfig. this works fine, but atlantis overwrites /home/atlantis/.gitconfig when a user files a PR and runs atlantis plan with the following:

[credential]
	helper = store
# [url "https://$GIT_TOKEN@github.com"]
#   insteadOf = https://github.com
# [url "https://$GIT_TOKEN@github.com"]
#   insteadOf = ssh://git@github.com
[url "https://x-access-token@github.com"]
	insteadOf = ssh://git@github.com

i believe this is the logic that writes the git-related files

Setting ATLANTIS_WRITE_GIT_CREDS=false results in a crashLoop because I am using a github app.

Mounting a custom /home/atlantis/.gitconfigresults in

There was an error running git config --global credential.helper store: error: could not write config file /home/atlantis/.gitconfig: Resource busy
: exit status 4

updating the PR clone ref per https://github.com/runatlantis/atlantis/issues/1696 would solve my issue

We solved this issue as described in https://github.com/runatlantis/helm-charts/issues/222:

  • Create the gitconfig Secret outside the chart
  • Mount the secret as a volume
  • Add a lifecycle hook, that copies the mounted secret and sets the correct permissions

So our setup basically looks like this:

...
    # Replicate the changes from
    # https://github.com/runatlantis/helm-charts/pull/223/files
    # to avoid https://github.com/runatlantis/helm-charts/issues/222.
    extraVolumes:
    - name: gitconfig
      secret:
        secretName: atlantis-gitconfig-secret
    extraVolumeMounts:
    - name: gitconfig
      mountPath: /etc/secret-gitconfig
      subPath: gitconfig
    lifecycle:
      postStart:
        exec:
          command: ["/bin/sh", "-c", "cp /etc/secret-gitconfig /home/atlantis/.gitconfig && chown atlantis /home/atlantis/.gitconfig"]
...

Hey thanks for the fast answer! Yeah so actually just tried to fork your chart and try to set to volume to be writable, but it resulted in the same issue. I also tried the lifecycle hook and the extra volumes from your link, but i get now an error that the hook is not running successfully: Screenshot 2024-05-08 at 19 43 07

So I think the fix is currently not working anymore with this chart. Any other idea how to use github apps with the latest version of your chart?

Just used the latest version of the helm chart (v5.0.2) and I am still running into the same issue. Helm values file looks like:

githubApp:
  id: 111111
  slug: some-slug

vcsSecretName: atlantis-github-app-credentials

gitconfigSecretName: atlantis-gitconfig

Error:

No files found in /docker-entrypoint.d/, skipping
{"level":"info","ts":"2024-05-08T16:46:00.019Z","caller":"server/server.go:447","msg":"Utilizing BoltDB","json":{}}
{"level":"info","ts":"2024-05-08T16:46:00.020Z","caller":"vcs/git_cred_writer.go:29","msg":"wrote git credentials to /home/atlantis/.git-credentials","json":{}}
Error: initializing server: could not write credentials: Writing ~/.git-credentials file: There was an error running git config --global credential.helper store: error: could not write config file /home/atlantis/.gitconfig: Resource busy
: exit status 4

@ggujabidze If I remember correctly, there was an open issue or pr that wanted to revert some of these changes. But I can’t find it at the moment. I think the revert conflicted with some other changes that happened in the meantime.