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

Support for credential helpers #873

Open
0x2b3bfa0 opened this issue May 26, 2021 · 1 comment · May be fixed by #976
Open

Support for credential helpers #873

0x2b3bfa0 opened this issue May 26, 2021 · 1 comment · May be fixed by #976

Comments

@0x2b3bfa0
Copy link

0x2b3bfa0 commented May 26, 2021

Follow-up to #768

it probably has a Git credentials helper that can provide the credentials - see https://www.git-scm.com/docs/gitcredentials

dulwich does not support reading credentials from gitcredentials helpers, but that is not properly hooked up yet in the porcelain unfortunately. If you try this again in a couple of months it may work. #768 (comment)

It would be really nice to support credential loading from helpers like in the standalone git command‑line tool. Many users rely on HTTPS remotes and their system keychain for passwordless authentication, especially on macOS.

Minimal example

>>> from dulwich.porcelain import ls_remote
>>> ls_remote("https://github.com/user/repository")

Expected output

{b'HEAD': b'···', b'refs/heads/main': b'···'}

Actual output

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/···/site-packages/dulwich/porcelain.py", line 1618, in ls_remote
    return client.get_refs(host_path)
  File "/···/site-packages/dulwich/client.py", line 2089, in get_refs
    refs, _, _ = self._discover_references(b"git-upload-pack", url)
  File "/···/site-packages/dulwich/client.py", line 1906, in _discover_references
    resp, read = self._http_request(url, headers, allow_compression=True)
  File "/···/site-packages/dulwich/client.py", line 1875, in _http_request
    raise HTTPUnauthorized(resp.getheader("WWW-Authenticate"), url)
dulwich.client.HTTPUnauthorized: No valid credentials provided

System configuration

$ uname -a
Darwin ··· 19.6.0 Darwin Kernel Version 19.6.0: Tue Nov 10 00:10:30 PST 2020; root:xnu-6153.141.10~1/RELEASE_X86_64 x86_64
$ python --version
Python 3.9.4
$ pip show dulwich
Name: dulwich
Version: 0.20.23
Summary: Python Git Library
Home-page: https://www.dulwich.io/
Author: Jelmer Vernooij
Author-email: jelmer@jelmer.uk
License: Apachev2 or later or GPLv2
Location: /···/site-packages
Requires: certifi, urllib3
Required-by: dvc
$ cat /Applications/Xcode.app/Contents/Developer/usr/share/git-core/gitconfig
[credential]
        helper = osxkeychain
@jelmer
Copy link
Owner

jelmer commented Jun 13, 2021

This would be great to see implemented - it'd be great if somebody picked this up. I'm to help provide guidance and/or review pull requests.

@dtrifiro dtrifiro linked a pull request Jun 7, 2022 that will close this issue
dtrifiro added a commit to dtrifiro/dulwich that referenced this issue Jun 20, 2022
Introduces `GitCredentialsHttpClient` that will retry http requests
failing with 401/404 with authorization headers generated from
credentials returned by git credentials helpers (if any).

https://www.git-scm.com/docs/gitcredentials

fixes jelmer#873
dtrifiro added a commit to dtrifiro/dulwich that referenced this issue Jan 12, 2023
- add `CredentialHelper` class to run credential helper commands and
  retrieve values
- add `get_credentials_from_helper` to retrieve credentials from helpers
defined in provided config
- moved (unused) `get_credentials_from_store` to `credentials.py`

Also see https://www.git-scm.com/docs/gitcredentials

fixes jelmer#873
dtrifiro added a commit to dtrifiro/dulwich that referenced this issue Jan 26, 2023
- add `CredentialHelper` class to run credential helper commands and
  retrieve values
- add `get_credentials_from_helper` to retrieve credentials from helpers
defined in provided config
- moved (unused) `get_credentials_from_store` to `credentials.py`

Also see https://www.git-scm.com/docs/gitcredentials

fixes jelmer#873
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants