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 module verifies signatures after the repo has already been updated #75609

Open
1 task done
spanezz opened this issue Aug 31, 2021 · 5 comments
Open
1 task done

git module verifies signatures after the repo has already been updated #75609

spanezz opened this issue Aug 31, 2021 · 5 comments
Labels
affects_2.10 This issue/PR affects Ansible v2.10 bug This issue/PR relates to a bug. module This issue/PR relates to a module. needs_verified This issue needs to be verified/reproduced by maintainer P3 Priority 3 - Approved, No Time Limitation support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Comments

@spanezz
Copy link

spanezz commented Aug 31, 2021

Summary

I would expect that if some changes are not signed, ansible would leave my working copy unchanged to the last verified version.

Instead, since verify_commit_sign is called at the end of all operations, even if it will fail, working copies will have been updated.

This may mean that a failed playbook might cause production code to get updated to an untrusted/unverified version. Depending on setups, that may have serious consequences.

Issue Type

Bug Report

Component Name

git

Ansible Version

$ ansible --version
ansible 2.10.8

Configuration

$ ansible-config dump --only-changed
ANSIBLE_NOCOWS(/home/enrico/dev/transilience/ansible.cfg) = True

OS / Environment

Debian Bullseye

Steps to Reproduce

---
- hosts: localhost
  tasks:
   - name: test git
     git:
        repo: https://github.com/spanezz/transilience.git
        dest: /tmp/test
        verify_commit: yes
        version: main

It will make a checkout. If a checkout is present to an earlier commit in main, it will update it to the last commit in main

Expected Results

I would expect that if a signature fails to verify, nothing is changed in the filesystem

Actual Results

PLAY [localhost] *************************************************************************************************************************************************

TASK [Gathering Facts] *******************************************************************************************************************************************
ok: [localhost]

TASK [test git] **************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Failed to verify GPG signature of commit/tag \"main\"", "rc": 1, "stderr": "gpg: Signature made Fri Jul  2 23:30:54 2021 CEST\ngpg:                using RSA key 4AEE18F83AFDEB23\ngpg: Can't check signature: No public key\n", "stderr_lines": ["gpg: Signature made Fri Jul  2 23:30:54 2021 CEST", "gpg:                using RSA key 4AEE18F83AFDEB23", "gpg: Can't check signature: No public key"], "stdout": "", "stdout_lines": []}

PLAY RECAP *******************************************************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   



This error is as expected. The problem is the unexpected side effect on the destination

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibot
Copy link
Contributor

ansibot commented Aug 31, 2021

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot ansibot added affects_2.10 This issue/PR affects Ansible v2.10 bug This issue/PR relates to a bug. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Aug 31, 2021
@bcoca bcoca added P3 Priority 3 - Approved, No Time Limitation needs_verified This issue needs to be verified/reproduced by maintainer and removed needs_triage Needs a first human triage before being processed. labels Sep 2, 2021
@konstruktoid
Copy link
Contributor

This is due to the fact that fetch doesn't support verification, so the verification is done after the repo has been cloned or updated.

git pull --verify-signatures would propably be an alternative.

https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/git.py#L830
https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/git.py#L1021

@spanezz
Copy link
Author

spanezz commented Oct 25, 2021

git fetch without signature verification is probably not an issue, while checkout out before verifying is, as it may leave an unverified checkout around.

A possible strategy to deal with this can be to fetch no matter what; then verify the signature; then checkout if the signature is sound

@konstruktoid
Copy link
Contributor

I might be missing something but how to verify the commits without altering unless you're using git pull --verify-signatures?

@spanezz
Copy link
Author

spanezz commented Nov 6, 2021

Git does offer some way to check signatures without checkout out code, I guess the trick is to find a convenient one for integration in the module, and to use that right give the intrications of signature verification.

I know that at least git show --show-signature can be used to verify the signature on a commit without needing the files to be checked out, although it does need the commit to be fetched into the local repo. I would guess it's fine (and unavoidable, given how git works) to fetch untrusted commits, and that the critical point is the decision what can be safely checked out of the repo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects_2.10 This issue/PR affects Ansible v2.10 bug This issue/PR relates to a bug. module This issue/PR relates to a module. needs_verified This issue needs to be verified/reproduced by maintainer P3 Priority 3 - Approved, No Time Limitation support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

No branches or pull requests

4 participants