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

git modules reports missing https password clearly #71898

Closed
wants to merge 2 commits into from

Conversation

SimonHeimberg
Copy link
Contributor

SUMMARY

git module reports missing https password instead of hanging

fixes #69489

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

git

ADDITIONAL INFORMATION

Asking for the ssh password is prevented on Line411 by setting -o BatchMode=yes for ssh. To do the same for https, we can set an environment variable. Not sure if it is done in the correct place.

@ansibot ansibot added affects_2.11 bug This issue/PR relates to a bug. module This issue/PR relates to a module. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. needs_triage Needs a first human triage before being processed. new_contributor This PR is the first contribution by a new community member. small_patch source_control Source-control category support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Sep 23, 2020
@relrod relrod added the ci_verified Changes made in this PR are causing tests to fail. label Sep 24, 2020
@samdoran
Copy link
Contributor

samdoran commented Sep 24, 2020

Based on this comment it seems that setting GIT_TERMINAL_PROMPT does not fix the issue. The only way to prevent this from hanging is setting GIT_ASKPASS to something that exits cleanly.

@samdoran
Copy link
Contributor

samdoran commented Sep 24, 2020

We also need a changelog entry and integration tests.

@samdoran samdoran removed the needs_triage Needs a first human triage before being processed. label Sep 24, 2020
@SimonHeimberg
Copy link
Contributor Author

Based on this comment it seems that the GIT_TERMINAL_PROMPT does not fix the issue. The only way to prevent this from hanging is setting GIT_ASKPASS to something that exits cleanly.

I tested with more git versions now.
It fails on 1.9.1, the prompt is still shown.
On git 2.7.4 and 2.11.0, it works as expected:

$ GIT_TERMINAL_PROMPT=0 git fetch
fatal: could not read Password for 'https://MyUser@github.com': terminal prompts disabled
$ echo returned $?
returned 128

So for old versions, we have to set GIT_ASKPASS=/bin/true (or bin/echo, but trying an empty password instead of the prompt argument seems safer.) When GIT_ASKPASS is set, GIT_TERMINAL_PROMPT does not have any effect. So this can be left out.

@SimonHeimberg
Copy link
Contributor Author

We also needs a changelog entry and integration tests.

I need some guidance.
I do not find how to do this in https://docs.ansible.com/ansible/latest/community/index.html#working-with-the-ansible-repo

Where do I put the changelog?
What should the integration test do? (Test that it does not hang when the https password is not given? Or ...? I do not (yet) find any testing that no prompt is shown for ssh repos.) Will it end up in test/integration/targets/git/tasks/....?

@@ -1163,6 +1163,8 @@ def main():
# We screenscrape a huge amount of git commands so use C locale anytime we
# call run_command()
module.run_command_environ_update = dict(LANG='C', LC_ALL='C', LC_MESSAGES='C', LC_CTYPE='C')
if 'GIT_TERMINAL_PROMPT' not in os.environment:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, the variable name is os.environ (ment)

@samdoran
Copy link
Contributor

samdoran commented Oct 1, 2020

Where do I put the changelog?

Changelog fragments go in changelogs/fragments. See this fragment as an example.

What should the integration test do? (Test that it does not hang when the https password is not given? Or ...? I do not (yet) find any testing that no prompt is shown for ssh repos.) Will it end up in test/integration/targets/git/tasks/....?

Yes, the new test would go in test/integration/taregts/git/tasks/, probably in a new tasks file. Since the tests are so complicated, we like to break that test into separate tasks files to keep things readable. Make sure to add an import_tasks task to the main.yml so the new tests run.

The test would need to set the GIT_ASKPASS environment variable in order to exercise this code path. We could look at authentication against a private repo

- name: Test failure with GIT_ASKPASS (EXPECTED FAILURE)
  git:
    repo: https://someprivate.repo
    dest: "{{ checkout_dir }}"
  environment:
    GIT_ASKPASS: /bin/false
  register: result1

- name: Test failure with GIT_ASKPASS (EXPECTED FAILURE)
  git:
    repo: https://someprivate.repo
    dest: "{{ checkout_dir }}"
  register: result2

- assert:
    that:
      - result2 is failed   

@samdoran
Copy link
Contributor

samdoran commented Oct 1, 2020

The more I think about this, this would be a change in behavior that may affect some who are relying on this interactive capability in the module. It's probably uncommon, but I believe AWX is relying on this.

This should probably be a new option or an update to the documentation with an example task that shows how to set GIT_ASKPASS on the task to invoke a failure when credentials are missing.

* older git versions do not know GIT_TERMINAL_PROMPT, so use GIT_ASKPASS
* use correct variable name os.environ
@SimonHeimberg
Copy link
Contributor Author

SimonHeimberg commented Oct 3, 2020

Whoever wants the interactive functionality can set GIT_TERMINAL_PROMPT=1, but they would have to do it explicitly.

Having a clear documentation (without this change) would also be a big plus to now, because this info is only found in a bug report.

@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. and removed ci_verified Changes made in this PR are causing tests to fail. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Oct 3, 2020
@ansibot
Copy link
Contributor

ansibot commented Oct 3, 2020

The test ansible-test sanity --test pep8 [explain] failed with 1 error:

lib/ansible/modules/git.py:1169:71: E261: at least two spaces before inline comment

click here for bot help

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed core_review In order to be merged, this PR must follow the core review workflow. labels Oct 3, 2020
@samdoran samdoran added the ci_verified Changes made in this PR are causing tests to fail. label Oct 5, 2020
@SimonHeimberg
Copy link
Contributor Author

SimonHeimberg commented Oct 6, 2020

TODO:

@samdoran
Copy link
Contributor

samdoran commented Oct 6, 2020

I think this should be a documentation change. It can be added to the EXAMPLES section in https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/git.py.

@SimonHeimberg
Copy link
Contributor Author

SimonHeimberg commented Oct 9, 2020

so what about pullrequest #72164 ?

@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Oct 17, 2020
@samdoran
Copy link
Contributor

samdoran commented Nov 9, 2020

Fixed by #72164

@samdoran samdoran closed this Nov 9, 2020
@ansible ansible locked and limited conversation to collaborators Dec 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.11 bug This issue/PR relates to a bug. ci_verified Changes made in this PR are causing tests to fail. module This issue/PR relates to a module. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. new_contributor This PR is the first contribution by a new community member. small_patch source_control Source-control category stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ansible git module stuck when cloning via HTTPS if authentication is required
4 participants