atlantis: Error `unsafe repository` using EFS via terraform-aws-atlantis pre-v3.17.0

Community Note

  • Please vote on this issue by adding a πŸ‘ reaction to the original issue to help the community and maintainers prioritize this request. Searching for pre-existing feature requests helps us consolidate datapoints for identical requirements into a single place, thank you!
  • Please do not leave β€œ+1” or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Overview of the Issue

I haven’t seen this issue noted in here, but I am reporting this in case anybody else has experienced this.

After recently restarting our Atlantis task, each atlantis plan results in a failure to download every single module. One such failure message looks like this:

β•·
β”‚ Error: Failed to download module
β”‚ 
β”‚ Could not download module "cloudtrail" (cloudtrail.tf:12) source code from
β”‚ "git::https://github.com/trussworks/terraform-aws-cloudtrail?ref=v4.3.0":
β”‚ error downloading
β”‚ 'https://github.com/trussworks/terraform-aws-cloudtrail?ref=v4.3.0':
β”‚ /usr/bin/git exited with 128: fatal: unsafe repository
β”‚ ('/******/.terraform/modules/cloudtrail'
β”‚ is owned by someone else)
β”‚ To add an exception for this directory, call:
β”‚ 
β”‚ 	git config --global --add safe.directory
β”‚ /******/.terraform/modules/cloudtrail
β”‚ .
β•΅

We understand this is related to the recent Git security vulnerability. We’ve tried adding the suggested git config --global --add safe.directory <repo> or to via * as documented here but have not had success.

Reproduction Steps

This problem began after we restarted our atlantis task in ECS. The git version running on the previous task was from a git version before the security patch.

Logs

Environment details

Atlantis version:

Additional Context

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 46
  • Comments: 18 (5 by maintainers)

Commits related to this issue

Most upvoted comments

I was able to workaround this issue setting the user too. The EFS storage wasn’t much of a need to me, and I couldn’t easily mount it externally, so I ended up adding the following lines on my terraform resource (using terraform-aws-atlantis):

  # User, needed because of https://github.com/runatlantis/atlantis/issues/2221
  # This is atlantis user per the official docker image
  user = "100:1000"

  # Ephemeral Storage, needed because the EFS storage
  # gets created with root-owned directories
  enable_ephemeral_storage = true

For those running https://github.com/terraform-aws-modules/terraform-aws-atlantis the fix for me was to set the user = "100:1000" which is the atlantis user in the official image. You will also need to mount the EFS directory externally and sudo chown -R 100:1000 <your_efs_mount>. By default, the EFS mount is root:root.

Not sure if applicable but the issue is still present on latest version @nitrocode

thanks @andyshinn & @biancarosa it was related to https://github.com/terraform-aws-modules/terraform-aws-atlantis/pull/287 from the initial setup terraform-aws-atlantis if you was not create user atlantis as uid = 100 & gid = 1000 by user = "100:1000" EFS will mount with root user 1000:1000 we could use as below

  # User, needed because of https://github.com/runatlantis/atlantis/issues/2221
  # This is atlantis user per the official docker image
  user = "100:1000"

  # Ephemeral Storage, needed because the EFS storage
  # gets created with root-owned directories
  enable_ephemeral_storage = true

or

For those running https://github.com/terraform-aws-modules/terraform-aws-atlantis the fix for me was to set the user = "100:1000" which is the atlantis user in the official image. You will also need to mount the EFS directory externally and sudo chown -R 100:1000 <your_efs_mount>. By default, the EFS mount is root:root.

Sorry, I don’t remember the exact steps. What I did was something like:

  1. Launch EC2 instance in same subnets as EFS
  2. Install needed NFS utilities and tools
  3. Mount the volume using the commands found in the EFS console
  4. Run sudo chown -R 100:1000 against the mount

note that switching to the Atlantis non root user may impact the above workaround