microsoft / git

A fork of Git containing Microsoft-specific patches.
http://git-scm.com/
Other
788 stars 95 forks source link

git-maintenance doesn't work with git-credential-manager & pass #625

Open nedsociety opened 9 months ago

nedsociety commented 9 months ago

Setup

$ git --version --build-options

git version 2.43.0.vfs.0.0
cpu: x86_64
built from commit: b7a6ed788a205fb2c0013111d277b4c9d6ab35bd
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh

Are you using Scalar or VFS for Git?

Yes (scalar)

Nope, it's Ubuntu 22.04 jammy.

$ git-credential-manager --version
2.4.1
$ pass --version
============================================
= pass: the standard unix password manager =
=                                          =
=                  v1.7.4                  =
=                                          =
=             Jason A. Donenfeld           =
=               Jason@zx2c4.com            =
=                                          =
=      http://www.passwordstore.org/       =
============================================

Details

$ sudo apt install pass

# Follow https://github.com/git-ecosystem/git-credential-manager/blob/release/docs/install.md#install-2

$ git config --global credential.credentialStore gpg # make gcm use pass as its credstore

# try cloning a private repo

$ pass list

# confirm that the auth data is listed correctly

$ scalar register path/to/private/repo
$ systemctl --user start git-maintenance@hourly.service || systemctl --user status git-maintenance@hourly.service

The command succeeds.

@ systemctl --user daemon-reload && systemctl --user start git-maintenance@hourly.service; systemctl --user status git-maintenance@hourly.service
Job for git-maintenance@hourly.service failed because the control process exited with error code.
See "systemctl --user status git-maintenance@hourly.service" and "journalctl --user -xeu git-maintenance@hourly.service" for details.
× git-maintenance@hourly.service - Optimize Git repositories data
     Loaded: loaded (/home/ned/.config/systemd/user/git-maintenance@.service; static)
     Active: failed (Result: exit-code) since Wed 2024-02-07 17:32:01 KST; 8ms ago
TriggeredBy: ● git-maintenance@hourly.timer
    Process: 4051421 ExecStart=/usr/local/lib/git-core/git --exec-path=/usr/local/lib/git-core -c credential.interactive=false -c core.askPass=true for-each-repo --config=maintenance.repo maintenance run >
   Main PID: 4051421 (code=exited, status=1/FAILURE)
        CPU: 31ms

Feb 07 17:32:01 xxx systemd[1292]: Starting Optimize Git repositories data...
Feb 07 17:32:01 xxx git[4051425]: fatal: unable to get password from user
Feb 07 17:32:01 xxx git[4051422]: error: failed to prefetch remotes
Feb 07 17:32:01 xxx git[4051422]: error: task 'prefetch' failed
Feb 07 17:32:01 xxx systemd[1292]: git-maintenance@hourly.service: Main process exited, code=exited, status=1/FAILURE
Feb 07 17:32:01 xxx systemd[1292]: git-maintenance@hourly.service: Failed with result 'exit-code'.
Feb 07 17:32:01 xxx systemd[1292]: Failed to start Optimize Git repositories data.

I believe this is repo-agnostic

Additional info

Similar to #604 I've found that the problem resolves when I try to comment out two lines from ~/.config/systemd/user/git-maintenance@.service:

# This file was created and is maintained by Git.
# Any edits made in this file might be replaced in the future
# by a Git command.

[Unit]
Description=Optimize Git repositories data

[Service]
Type=oneshot
ExecStart="/usr/local/lib/git-core/git" --exec-path="/usr/local/lib/git-core" -c credential.interactive=false -c core.askPass=true  for-each-repo --config=maintenance.repo maintenance run --schedule=%i
LockPersonality=yes
# MemoryDenyWriteExecute=yes              #  <----------
NoNewPrivileges=yes
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 AF_VSOCK
RestrictNamespaces=yes
RestrictRealtime=yes
RestrictSUIDSGID=yes
SystemCallArchitectures=native
# SystemCallFilter=@system-service               #  <----------

I didn't check if the upstream git has the same problem (it probably has), but since git-maintenance is probably mostly used by scalar I felt this issue is to be reported here.

X-post (gcm): https://github.com/git-ecosystem/git-credential-manager/issues/1521

derrickstolee commented 9 months ago

Since this issue happens when using the systemd scheduler, could you run git maintenance start --scheduler=crontab to check if the problem repeats when using cron? If that works, then it would be a valuable workaround.

nedsociety commented 9 months ago

Since this issue happens when using the systemd scheduler, could you run git maintenance start --scheduler=crontab to check if the problem repeats when using cron? If that works, then it would be a valuable workaround.

I currently don't have access to the machine for a while, may be able to report in 5~6 days. Though in terms of workaround I'm not sure if switching to crond is a better way against just removing those two lines.

nedsociety commented 9 months ago

git maintenance start --scheduler=crontab returned immediately with no output (exitcode was zero). Nothing had been registered to any of /etc/crontab, /etc/cron.*/*.

EDIT: Okay /var/spool/cron/crontabs has the configuration. I'm not sure how to trigger them manually though. I also noted that the systemd timers were gone.

nedsociety commented 9 months ago

Update: the cron scheduler succeeded for both hourly and daily runs :+1: