GIT_ASKPASS больше чем эхо - PullRequest
1 голос
/ 24 апреля 2020

Я играю с различными вариантами GIT_ASKPASS, и я хотел сделать ПО C, чтобы буквально можно было извлечь пароль из внешнего "хранилища". Чтобы доказать свою точку зрения, мне будет достаточно просто вызвать API и вернуть пароль из ответа. Проблема в том, что git зависает на предоставленном мною скрипте, и я понятия не имею, почему.

Некоторая информация:

  • скрипт был chmod +x -ед
  • команда внутри $(...) работает правильно
  • Я читаю ответ здесь git, токен oauth2 и GIT_ASKPASS , но все, что мне сказали, это то, что мы делаем то же самое
  • my git is git version 2.26.2

Вот скрипт:

#!/usr/bin/env bash

password="$(http https://postman-echo.com/get password=="trust-me" | jq '.args | .password' | tr -d '"')"
exec echo "${password}"

и вот журнал:

GIT_TRACE=1 GIT_ASKPASS=./git_ask_pass_url git clone "https://askpass-git-2@github.com/kornicameister/askpass-git-test.git" /tmp/ddddd
23:43:22.266086 git.c:439               trace: built-in: git clone https://da-user@github.com/kornicameister/askpass-git-test.git /tmp/ddddd
Cloning into '/tmp/ddddd'...
23:43:22.270259 run-command.c:663       trace: run_command: git-remote-https origin https://askpass-git-2@github.com/kornicameister/askpass-git-test.git
23:43:23.054837 run-command.c:663       trace: run_command: 'git credential-cache --timeout=28800 get'
23:43:23.057470 git.c:703               trace: exec: git-credential-cache --timeout=28800 get
23:43:23.057506 run-command.c:663       trace: run_command: git-credential-cache --timeout=28800 get
23:43:23.059112 run-command.c:663       trace: run_command: ./git_ask_pass_url 'Password for '\''https://askpass-git-2@github.com'\'': '

Обновление:

Хорошо, я изменил скрипт на:

#!/usr/bin/env bash

test "${GIT_TRACE}" -eq 1 && set -x
curl "https://postman-echo.com/get?password=${GIT_PASSWORD}" | jq -r '.args | .password'

, и с этой настройкой у нас есть:

GIT_PASSWORD="foo-course" GIT_TRACE=1 GIT_ASKPASS=./git_ask_pass_url git clone "https://foo-1@github.com/kornicameister/foo-test.git" /tmp/b              20:57:03
20:57:04.473789 git.c:439               trace: built-in: git clone https://foo-1@github.com/kornicameister/foo-test.git /tmp/b
Cloning into '/tmp/b'...
20:57:04.478021 run-command.c:663       trace: run_command: git-remote-https origin https://foo-1@github.com/kornicameister/foo-test.git
20:57:05.258448 run-command.c:663       trace: run_command: 'git credential-cache --timeout=28800 get'
20:57:05.262080 git.c:703               trace: exec: git-credential-cache --timeout=28800 get
20:57:05.262126 run-command.c:663       trace: run_command: git-credential-cache --timeout=28800 get
20:57:05.264706 run-command.c:663       trace: run_command: ./git_ask_pass_url 'Password for '\''https://foo-1@github.com'\'': '
++ curl 'https://postman-echo.com/get?password=foo-course'
++ jq -r '.args | .password'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   238  100   238    0     0    409      0 --:--:-- --:--:-- --:--:--   409
+ password=foo-course
+ exec echo foo-course
20:57:06.387701 run-command.c:663       trace: run_command: 'git credential-cache --timeout=28800 store'
20:57:06.391164 git.c:703               trace: exec: git-credential-cache --timeout=28800 store
20:57:06.391214 run-command.c:663       trace: run_command: git-credential-cache --timeout=28800 store
20:57:07.176076 run-command.c:663       trace: run_command: git index-pack --stdin -v --fix-thin '--keep=fetch-pack 24977 on kornicameister' --check-self-contained-and-connected
20:57:07.177517 git.c:439               trace: built-in: git index-pack --stdin -v --fix-thin '--keep=fetch-pack 24977 on kornicameister' --check-self-contained-and-connected
remote: Enumerating objects: 10, done.
remote: Counting objects: 100% (10/10), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 10 (delta 2), reused 10 (delta 2), pack-reused 0
Receiving objects: 100% (10/10), done.
Resolving deltas: 100% (2/2), done.
20:57:07.202708 run-command.c:663       trace: run_command: git rev-list --objects --stdin --not --all --quiet --alternate-refs '--progress=Checking connectivity'
20:57:07.204214 git.c:439               trace: built-in: git rev-list --objects --stdin --not --all --quiet --alternate-refs '--progress=Checking connectivity'
20:57:07.206501 run-command.c:663       trace: run_command: /tmp/b/.git/hooks/post-checkout 0000000000000000000000000000000000000000 581d755bfb10e1beee93fc190cd99428f9f1595c 1

, так что это действительно звучит так, как будто проблема была с использованием http вместо простого curl.

1 Ответ

2 голосов
/ 24 апреля 2020

Хорошо, вы можете использовать curl, как указано в обновлении выше, но я должен отдать должное http. Если вы хотите использовать sh в GIT_ASKPASS, очень важно сделать это так:

http -I "https://postman-echo.com/get" password=="${GIT_PASSWORD}" | jq -r '.args | .password'

Примечание -I flags. Это препятствует чтению со стандартного ввода. GIT_ASKPASS фактически получает некоторую строку в stdin, и, следовательно, она застряла в исходной попытке.

Так что, да, я думаю, что вывод состоит в том, что иногда самый простой инструмент работает, а более продвинутый вызывает неожиданные проблемы.

...