libgit2 / libgit2/pygit2

KeypairFromAgent throws fetch into an infinite loop

Đang mở
#953 0 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
Python
Star
1.7k
Fork
408
Merge trung bình
2 ngày 57 phút
Pull request đã merge (30 ngày)
7

Mô tả

I'm not sure I'm using it right, but the following code throws git_remote_fetch into some sort of infinite loop in case the agent can't find an appropriate key.

import pygit2

class MyCallbacks(pygit2.RemoteCallbacks):
    def credentials(self, url, username_from_url, allowed_types):
        # print('Credentials callback called')
        return pygit2.KeypairFromAgent(username_from_url)

repo = pygit2.Repository('foo')
repo.remotes['origin'].fetch(callbacks=MyCallbacks())
print("OK")

Here's an example:

$ git clone git@<some-ssh-repository> foo
Cloning into 'foo'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
$ python3 test.py  # Using my regular ssh agent which has the correct key
OK
$ eval $(ssh-agent)  # Create a new ssh-agent with no key and update env variables
$ python3 test.py  # Never returns...

If I uncomment the print statement in the python snippet above, I can see that my callback is called over and over.

There's one more thing that is odd but might help: when I interrupt the script with ctrl-c, I don't always get the same traceback. In the second case bellow it seems that the "correct" exception (_pygit2.GitError: callback failed to initialize SSH credentials) is raised at some point but just doesn't reach my code:

❯❯❯ python3 test.py
# ^C
Traceback (most recent call last):
  File "test.py", line 11, in <module>
    repo.remotes['origin'].fetch(callbacks=MyCallbacks())
  File "/home/gregoire/.local/lib/python3.7/site-packages/pygit2/remote.py", line 406, in fetch
    err = C.git_remote_fetch(self._remote, arr, fetch_opts, to_bytes(message))
KeyboardInterrupt
❯❯❯ python3 test.py
# ^C
From cffi callback <function RemoteCallbacks._credentials_cb at 0x7f5e027700d0>:
Traceback (most recent call last):
  File "/home/gregoire/.local/lib/python3.7/site-packages/pygit2/remote.py", line 304, in _credentials_cb
    ccred = get_credentials(credentials, url, username, allowed)
  File "/home/gregoire/.local/lib/python3.7/site-packages/pygit2/remote.py", line 515, in get_credentials
    if pubkey is None and privkey is None:
KeyboardInterrupt
Traceback (most recent call last):
  File "test.py", line 11, in <module>
    repo.remotes['origin'].fetch(callbacks=MyCallbacks())
  File "/home/gregoire/.local/lib/python3.7/site-packages/pygit2/remote.py", line 409, in fetch
    check_error(err)
  File "/home/gregoire/.local/lib/python3.7/site-packages/pygit2/errors.py", line 64, in check_error
    raise GitError(message)
_pygit2.GitError: callback failed to initialize SSH credentials

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với các đường dẫn trong remote.py được hiển thị trong traceback, đặc biệt là RemoteCallbacks._credentials_cb và get_credentials. Tái hiện fetch bằng một ssh-agent không chứa khóa nào, sau đó lần theo callback và cách xử lý lỗi thông tin xác thực. Hoàn tất khi việc tra cứu thông tin xác thực thất bại không còn được thử lại và GitError mong đợi đến được caller.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
git, python
Lĩnh vực
tooling
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.