salt icon indicating copy to clipboard operation
salt copied to clipboard

[FEATURE REQUEST] Support an easy way to set git's safe.directory for a repo in salt.states.git

Open timwsuqld opened this issue 4 years ago • 2 comments

Is your feature request related to a problem? Please describe. The recent updates to git that require you to run git config --global --add safe.directory /path/to/repo is breaking many git states. Trying to use git.config_set will be very difficult as the config is a multi value, and when lots of different states reference git repos, it would be hard to get a complete list.

Describe the solution you'd like An option for states like git.latest to automatically add the repo to safe.directory config for the user running the git state. Something like mark_as_safe: True that when set on the state would check if the repo is in the current users git global config as a safe.directory, and add it if it's not. This would allow shared repos (or repo's managed by salt as the user root but with different permissions on the directory for other software that uses it) to continue to be managed by salt easily.

Describe alternatives you've considered Running git config --global --add safe.directory '*' on all our salt managed machines. But this looses the benefit of this safety feature for any other repo's on the system, also we'd need to make sure we run it for all users that salt could use for git actions (some of our repos are checked out by root, others by another system user, all depends on the software being deployed).

Additional context Current git.latest failures look like this, this repo is setup as a shared repo, so salt uses root to do the checkout (git.latest) and then other states set the core.sharedRepository value and file permissions.

----------                                                  
          ID: deploy_git                                                                  
    Function: git.latest              
        Name: [email protected]:org-ltd/deploy.git
      Result: False
     Comment: fatal: unsafe repository ('/srv/containers/prod' is owned by someone else)
              To add an exception for this directory, call:
              
                git config --global --add safe.directory /srv/containers/prod
     Started: 21:03:37.012452
    Duration: 3473.282 ms
     Changes:  

I know this isn't a salt bug, but it would be great if we could fix this in salt somehow, otherwise managing git with salt just become way harder.

timwsuqld avatar Apr 28 '22 11:04 timwsuqld

It'd be great to get this out into the release, the git packages in Debian are including this check by default and it's making life a lot more difficult.

AllenRDCo avatar May 22 '23 22:05 AllenRDCo

Any suggestion on how to circumvent this?

skorpy2009 avatar Jul 28 '23 11:07 skorpy2009