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

Allow specifying a custom gitconfig file #1696

Open
johananl opened this issue Aug 27, 2024 · 4 comments
Open

Allow specifying a custom gitconfig file #1696

johananl opened this issue Aug 27, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@johananl
Copy link

Feature description

Right now GCM adds a [credential] directive to ~/.gitconfig. I'd like to be able to tell GCM which gitconfig file to write the directive to.

Rationale: I manage my dotfiles in a Git repo and don't want to commit sensitive info to that repo. Since the [credential] directive may sometimes contain sensitive info, I'd like to add it to a separate .gitconfig_local file which I include from the main file and don't commit to the dotfiles repo.

@johananl johananl added the enhancement New feature or request label Aug 27, 2024
@dscho
Copy link
Collaborator

dscho commented Aug 27, 2024

the [credential] directive may sometimes contain sensitive info

That should not be the case, ever, if all you use is Git Credential Manager. Granted, other credential helpers sometimes put sensitive information there, but not Git Credential Manager. All that is added to the config is:

  1. an empty value (because credential.helper is actually a multi-valued setting, and the empty value will forget all helpers seen up to that point).
  2. the path to Git Credential Manager.
  3. credential.https://dev.azure.com.useHttpPath is set to true.

Do you consider any of this sensitive information?

Having said this, there is already a way to do what you want, but it is admittedly hard to figure out from Git's documentation. The way to do this is to set the environment variable GIT_CONFIG_GLOBAL. In Git Bash, you would do this:

$ GIT_CONFIG_GLOBAL=~/.gitconfig_local git credential-manager configure

If you use PowerShell or CMD instead, you will set that environment variable in a different manner, of course, but the principle is the very same.

@johananl
Copy link
Author

johananl commented Aug 27, 2024

@dscho thanks for your reply.

What you said is true regarding the first [credential] directive that's added when running git credential-manager configure. However, I'm referring to the second directive that's added when trying to do e.g. git push to a repo for which GCM is configured. What happens for me is that after I authenticate in the browser tab which gets opened, GCM is adding something similar to the following to my global gitconfig file:

[credential "<redacted>"]
        azureAuthority = https://login.microsoftonline.com/<redacted>
        username = [email protected]

The thing I treat as "secret" is the value of azureAuthority and username. True, they aren't credentials, but azureAuthority is in my case an internal URL which I don't want to accidentally advertise and username is an email address. That's why I was trying to control which gitconfig file is chosen when this directive is added.

Anyway, not a big deal and if there is no easy way to achieve that (or if this feature isn't useful to others) we can just close this issue.

@dscho
Copy link
Collaborator

dscho commented Aug 27, 2024

What happens for me is that after I authenticate in the browser tab which gets opened, GCM is adding something similar to the following to my global gitconfig file:

[credential "<redacted>"]
        azureAuthority = https://login.microsoftonline.com/<redacted>
        username = [email protected]

The thing I treat as "secret" is the value of azureAuthority and username. True, they aren't credentials, but azureAuthority is in my case an internal URL which I don't want to accidentally advertise and username is an email address. That's why I was trying to control which gitconfig file is chosen when this directive is added.

Ah, I can understand that.

The code that is responsible for this is here.

I am not sure that I can think of an elegant way to accommodate your use case (considering that ~/.gitconfig_local is not used by default, it would require an option to write that .azureAuthority setting to arbitrary files that might not be in Git's config file chain and would therefore open new opportunities for users to become confused). Maybe write that information to the repository config instead? But that would not work in general, e.g. for git clone...

Maybe there would be a good home for this information in the Windows Credential Store? @mjcheetham what are your thoughts on the matter?

@johananl
Copy link
Author

Of course, GCM shouldn't be responsible for the way I handle my config files. That's well outside the scope of this project IMO.

But I thought that given the fact that GCM writes something to a gitconfig file, it would make sense to be able to control which file is being written to. Right now we seem to assume that this file is always at ~/.gitconfig, and I'm sure there are some users or use cases for which this assumption is wrong (for whatever reason).

So, I think it's less about my special use case and more about GCM's flexibility (i.e. it's more flexible to be able to control the file path than to have a hardcoded path).

I don't have an opinion about Windows Credential Store, but IMO if we try to solve this the solution should be cross platform (I run GCM on Linux in this case for example).

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

No branches or pull requests

2 participants