Cannot authenticate from scheduled git-maintenance (systemd timers)

Open
#1,521 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
csharp, git, github

Research direction

Reproduce the failure with the user systemd unit at ~/.config/systemd/user/git-maintenance@.service, comparing a scheduled run with a local command and enabling the reported GCM_TRACE and GIT_TRACE options. Trace the credential request from git-maintenance through Git Credential Manager; done means scheduled maintenance can authenticate and complete without the password or prefetch errors.

Written by the indexing model from the issue text.

Description

auth-issue
Version

2.4.1

Operating system

Linux

OS version or distribution

Ubuntu 22.04

Git hosting provider(s)

GitHub

Other hosting provider

No response

(Azure DevOps only) What format is your remote URL?

None

Can you access the remote repository directly in the browser?

Yes, I can access the repository

Expected behavior

I'm currently using scalar to manage repositories. It triggers git-maintenance to schedule periodic management operations in the form of systemd timer.

# Installed gcm 2.4.1 beforehand.
git config --global credential.credentialStore gpg
scalar clone <some_private_repo>

With gcm I can access, clone and push the repo as needed in my local sessions like terminals and GUIs. So this should work on generated git-maintenance jobs as well.

Actual behavior

In my recently clean installation of Ubuntu I found that git-maintenance jobs are failing:

# Both periodic timer and manual run via `systemctl --user start git-maintenance@hourly.service` yields similar results
$ systemctl --user status git-maintenance@hourly.service

× 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-01-24 10:13:27 KST; 8min ago
TriggeredBy: ● git-maintenance@hourly.timer
    Process: 57680 ExecStart=/usr/local/lib/git-core/git --exec-path=/usr/local/lib/git-core -c credential.interactive=false -c core.askPass=true for-eac>
   Main PID: 57680 (code=exited, status=1/FAILURE)
        CPU: 74ms

Jan 24 10:13:27 ned systemd[2367]: Starting Optimize Git repositories data...
Jan 24 10:13:27 ned git[57686]: Segmentation fault (core dumped)
Jan 24 10:13:27 ned git[57684]: fatal: unable to get password from user
Jan 24 10:13:27 ned git[57681]: error: failed to prefetch remotes
Jan 24 10:13:27 ned git[57681]: error: task 'prefetch' failed
Jan 24 10:13:27 ned systemd[2367]: git-maintenance@hourly.service: Main process exited, code=exited, status=1/FAILURE
Jan 24 10:13:27 ned systemd[2367]: git-maintenance@hourly.service: Failed with result 'exit-code'.
Jan 24 10:13:27 ned systemd[2367]: Failed to start Optimize Git repositories data.
lines 1-16/16 (END)

This is weird because if I run the command locally (stored in ~/.config/systemd/user/git-maintenance@.service) it works.

Logs

Adding trace option gives little information. With the modified the command line in ~/.config/systemd/user/git-maintenance@.service like this:

From:

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

To:

ExecStart=bash -c 'WSLENV=$WSLENV:GCM_TRACE:GIT_TRACE GCM_TRACE=1 GIT_TRACE=1 "/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'

Then,

@ systemctl --user status git-maintenance@hourly.service
× 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-01-24 10:29:14 KST; 1min 57s ago
TriggeredBy: ● git-maintenance@hourly.timer
    Process: 58557 ExecStart=bash -c WSLENV=$WSLENV:GCM_TRACE:GIT_TRACE GCM_TRACE=1 GIT_TRACE=1 "/usr/local/lib/git-core/git" --exec-path="/usr/local/lib/git-core" -c credential.interacti>
   Main PID: 58557 (code=exited, status=1/FAILURE)
        CPU: 80ms

Jan 24 10:29:14 ned bash[58560]: 10:29:14.150995 run-command.c:659       trace: run_command: git-remote-https origin https://github.com/<redacted>/<redacted>
Jan 24 10:29:14 ned bash[58561]: 10:29:14.425922 run-command.c:659       trace: run_command: '/usr/local/bin/git-credential-manager get'
Jan 24 10:29:14 ned bash[58561]: fatal: unable to get password from user
Jan 24 10:29:14 ned bash[58558]: error: failed to prefetch remotes
Jan 24 10:29:14 ned bash[58558]: error: task 'prefetch' failed
Jan 24 10:29:14 ned bash[58558]: 10:29:14.524122 run-command.c:659       trace: run_command: git commit-graph write --split --reachable --no-progress
Jan 24 10:29:14 ned bash[58570]: 10:29:14.524970 git.c:535               trace: built-in: git commit-graph write --split --reachable --no-progress
Jan 24 10:29:14 ned systemd[2367]: git-maintenance@hourly.service: Main process exited, code=exited, status=1/FAILURE
Jan 24 10:29:14 ned systemd[2367]: git-maintenance@hourly.service: Failed with result 'exit-code'.
Jan 24 10:29:14 ned systemd[2367]: Failed to start Optimize Git repositories data.
Dominant language
C#
Stars
9.3k
Forks
2.9k
Avg merge
7d 1h
Merged PRs (30d)
14

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from git-ecosystem/git-credential-manager

All issues in git-ecosystem/git-credential-manager

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.