Private git repositories (Azure Repos): cannot authenticate

Open
#319 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
azure, git, r

Research direction

Start with pkgdepends:::async_git_list_refs_v2 and reproduce the private Azure Repos URL from new_pkg_installation_proposal(). Trace how gitcreds credentials become the URL, then compare the encoded-username and system-git authentication paths shown in the report. Done means the documented private repository case no longer produces an illegal-URL error.

Written by the indexing model from the issue text.

Description

bug

I can't handle private git repositories (in my case Azure Repos) that require authentication in the URL.

The Remote entry is something like: git::https://dev.azure.com/org/project_git/package.

Starting e.g. from a new_pkg_installation_proposal("git::https://dev.azure.com/org/project_git/package"), {pkgdepends} retrieves the credentials using {gitcreds} from the system credential store, then builds the URL and should grab stuff from git.

Instead, I get an error from curl:

s_remote <- "git::https://dev.azure.com/org/project/_git/package"
p <- pkgdepends::new_pkg_installation_proposal(s_remote, config = list(library = tempfile()))
#> ℹ Creating library directory: 'C:\Users\LORENZ~1\AppData\Local\Temp\RtmpM93Fz5\file4140718a10d'
p$resolve()
p$get_resolution()$error
#> [[1]]
#> <async_rejected/rlib_error_3_0/rlib_error/error>
#> Error in `value[[3L]](cond)`:
#> ! pkgdepends resolution error for
#> git::https://dev.azure.com/org/project/_git/package.
#> Caused by error: 
#> ! Failed to download 'DESCRIPTION' from git repo at
#> <https://dev.azure.com/org/project/_git/package>.
#> Caused by error in `(function (e) …`:
#> ! URL using bad/illegal format or missing URL

Created on 2023-05-24 with reprex v2.0.2

By digging into the internals, I see that {pkgdepends} retrieves the username (in my org they have the form of user@domain), the password, and builds the resulting URL:
https://user@domain:password@dev.azure.com/org/project/_git/package

I believe that the @ in the username must be URL-encoded (%40) if using {pkgdepends}: I'm not sure if it's an Azure-specific pattern.
I confirm it works by debugging into pkgdepends:::async_git_list_refs_v2.

I get the same behavior from the shell with the system git (notice that user@ gets dropped):

git clone "https://user@domain:password@dev.azure.com/org/project/_git/package"
Cloning into 'rITAtools'...
fatal: unable to access 'https://domain:password@dev.azure.com/org/project/_git/package': URL using bad/illegal format or missing URL

Cloning succeeds with git clone "https://user%40domain:password@dev.azure.com/org/project/_git/package".

It would be cool to be able to use the system git if available, as {remotes} already does.
In that way, I can setup authentication in the .gitconfig with a PAT + HTTPS extra header (as recommended), and that would avoid reimplementing a whole git client...

Thanks!

Dominant language
C
Stars
135
Forks
47
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

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 r-lib/pkgdepends

All issues in r-lib/pkgdepends

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.