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

Commit using configured git config user.email to honor GH private email security setting #4235

Open
03juan opened this issue Jul 3, 2024 · 4 comments
Labels
bug Something isn't working 🦀gitoxide🦀 `gitoxide` might help here

Comments

@03juan
Copy link
Contributor

03juan commented Jul 3, 2024

  • Version
    • release v0.12.7
  • OS
    • Ubuntu 24.04 on WSL2 in Windows 11
  • git version
    • 2.43.0

Issue

Testing the Git authentication on a new GB Project fails with the default "Use a Git executable" option as the commit is pushed with my GB profile's email address, instead of the one set in my global git configuration.

This is related to the GH email setting "Block command line pushes that expose my email".

Additional context

I have the gh CLI set up as a credential helper

image

Choosing "Use a Git credentials helper" also doesn't work

Related

#2883 (comment)_

@Byron Byron added bug Something isn't working 🦀gitoxide🦀 `gitoxide` might help here labels Jul 3, 2024
@Byron
Copy link
Collaborator

Byron commented Jul 3, 2024

Thanks a lot for reporting!

I took a quick look and it seems like we are only asking the Git configuration for user information. This is usually correct enough.

Could you help me understand how /home/juan/.config/git/config is included? My feeling is that git2 somehow doesn't see this file, maybe because it doesn't follow (conditional) includes.

@Byron Byron added the feedback requested Feedback was requested to help resolve the issue label Jul 3, 2024
@03juan
Copy link
Contributor Author

03juan commented Jul 3, 2024

That file is being picked up because $XDG_CONFIG_HOME is set in my environment, so git picks that up along with ~/.gitconfig as part of the global config.

FILES
By default, git config will read configuration options from multiple files:

   $(prefix)/etc/gitconfig
       System-wide configuration file.

   $XDG_CONFIG_HOME/git/config, ~/.gitconfig
       User-specific configuration files. When the XDG_CONFIG_HOME environment variable is not set or empty, $HOME/.config/ is
       used as $XDG_CONFIG_HOME.

man git-config

$ env | grep XDG
XDG_RUNTIME_DIR=/run/user/1000/
XDG_CONFIG_HOME=/home/juan/.config
XDG_CACHE_HOME=/home/juan/.cache
XDG_DATA_HOME=/home/juan/.local/share

As a test I also set user.name and user.email in the local config

$ git config --show-origin --show-scope --get-all user.email
global  file:/home/juan/.config/git/config      [email protected]
local   file:.git/config        [email protected]

$ git config --show-origin --show-scope --get-all user.name
global  file:/home/juan/.config/git/config      Juan P Barrios
local   file:.git/config        Juan P Barrios

But still got the error after restarting git-butler from the same command line.

STDERR:
remote: error: GH007: Your push would publish a private email address.
remote: You can make your email public or disable this protection by visiting:
remote: http://github.com/settings/emails
To https://github.com/03juan/ms_interface
! [remote rejected] a2c88c2f11902afe966ece77d4ee4042d5a1cfba -> test-push-1720023956647 (push declined due to email privacy restrictions)

@Byron
Copy link
Collaborator

Byron commented Jul 4, 2024

As a test I also set user.name and user.email in the local config

That's a great idea!
And it's shocking that despite local scope the setting is still not picked up when creating a commit. Looking into this further, fortunately I think I found the culprit.

let user = self.users.get_user()?;
super::integration::verify_branch(&project_repository)?;
Ok(tokio::task::spawn_blocking(move || {
action(&project_repository, user.as_ref())
}))

get_user() is called whenever a commit in a virtual branch is created, and it overrides getting credentials from the configuration.

That User struct has separate name and email fields which are then used in the commit.

pub name: Option<String>,
pub given_name: Option<String>,
pub family_name: Option<String>,
pub email: String,

(Some(user), _, _) => try_from(user)?,

I am going to CC @krlvi here as changing it would be easy, but it's also changing something that was probably done for a reason.

@Byron Byron removed the feedback requested Feedback was requested to help resolve the issue label Jul 4, 2024
@03juan
Copy link
Contributor Author

03juan commented Jul 4, 2024

Great news. Glad you managed to hone in on the potential culprit! 🔥

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 🦀gitoxide🦀 `gitoxide` might help here
Projects
None yet
Development

No branches or pull requests

2 participants