| 1 |
# Test for verification of GnuPG signatures |
| 2 |
|
| 3 |
- name: GPG-VERIFICATION | Create GnuPG verification workdir |
| 4 |
tempfile: |
| 5 |
state: directory |
| 6 |
register: git_gpg_workdir |
| 7 |
|
| 8 |
- name: GPG-VERIFICATION | Define variables based on workdir |
| 9 |
set_fact: |
| 10 |
git_gpg_keyfile: "{{ git_gpg_workdir.path }}/testkey.asc" |
| 11 |
git_gpg_source: "{{ git_gpg_workdir.path }}/source" |
| 12 |
git_gpg_dest: "{{ git_gpg_workdir.path }}/dest" |
| 13 |
git_gpg_gpghome: "{{ git_gpg_workdir.path }}/gpg" |
| 14 |
|
| 15 |
- name: GPG-VERIFICATION | Temporary store GnuPG test key |
| 16 |
copy: |
| 17 |
content: "{{ git_gpg_testkey }}" |
| 18 |
dest: "{{ git_gpg_keyfile }}" |
| 19 |
|
| 20 |
- name: GPG-VERIFICATION | Create temporary GNUPGHOME directory |
| 21 |
file: |
| 22 |
path: "{{ git_gpg_gpghome }}" |
| 23 |
state: directory |
| 24 |
mode: 0700 |
| 25 |
|
| 26 |
- name: GPG-VERIFICATION | Import GnuPG test key |
| 27 |
environment: |
| 28 |
- GNUPGHOME: "{{ git_gpg_gpghome }}" |
| 29 |
command: gpg --import {{ git_gpg_keyfile }} |
| 30 |
|
| 31 |
- name: GPG-VERIFICATION | Create local GnuPG signed repository directory |
| 32 |
file: |
| 33 |
path: "{{ git_gpg_source }}" |
| 34 |
state: directory |
| 35 |
|
| 36 |
- name: GPG-VERIFICATION | Generate local GnuPG signed repository |
| 37 |
environment: |
| 38 |
- GNUPGHOME: "{{ git_gpg_gpghome }}" |
| 39 |
shell: | |
| 40 |
set -eEu |
| 41 |
|
| 42 |
git init |
| 43 |
|
| 44 |
touch an_empty_file |
| 45 |
git add an_empty_file |
| 46 |
git commit --no-gpg-sign --message "Commit, and don't sign" |
| 47 |
git tag lightweight_tag/unsigned_commit HEAD |
| 48 |
git commit --allow-empty --gpg-sign --message "Commit, and sign" |
| 49 |
git tag lightweight_tag/signed_commit HEAD |
| 50 |
git tag --annotate --message "This is not a signed tag" unsigned_annotated_tag HEAD |
| 51 |
git commit --allow-empty --gpg-sign --message "Commit, and sign" |
| 52 |
git tag --sign --message "This is a signed tag" signed_annotated_tag HEAD |
| 53 |
git checkout -b some_branch/signed_tip '{{ git_default_branch }}' |
| 54 |
git commit --allow-empty --gpg-sign --message "Commit, and sign" |
| 55 |
git checkout -b another_branch/unsigned_tip '{{ git_default_branch }}' |
| 56 |
git commit --allow-empty --no-gpg-sign --message "Commit, and don't sign" |
| 57 |
git checkout '{{ git_default_branch }}' |
| 58 |
args: |
| 59 |
chdir: "{{ git_gpg_source }}" |
| 60 |
|
| 61 |
- name: GPG-VERIFICATION | Get hash of an unsigned commit |
| 62 |
command: git show-ref --hash --verify refs/tags/lightweight_tag/unsigned_commit |
| 63 |
args: |
| 64 |
chdir: "{{ git_gpg_source }}" |
| 65 |
register: git_gpg_unsigned_commit |
| 66 |
|
| 67 |
- name: GPG-VERIFICATION | Get hash of a signed commit |
| 68 |
command: git show-ref --hash --verify refs/tags/lightweight_tag/signed_commit |
| 69 |
args: |
| 70 |
chdir: "{{ git_gpg_source }}" |
| 71 |
register: git_gpg_signed_commit |
| 72 |
|
| 73 |
- name: GPG-VERIFICATION | Clone repo and verify signed HEAD |
| 74 |
environment: |
| 75 |
- GNUPGHOME: "{{ git_gpg_gpghome }}" |
| 76 |
git: |
| 77 |
repo: "{{ git_gpg_source }}" |
| 78 |
dest: "{{ git_gpg_dest }}" |
| 79 |
verify_commit: yes |
| 80 |
when: |
| 81 |
- git_version.stdout is version("2.1.0", '>=') |
| 82 |
|
| 83 |
- name: GPG-VERIFICATION | Clone repo and verify a signed lightweight tag |
| 84 |
environment: |
| 85 |
- GNUPGHOME: "{{ git_gpg_gpghome }}" |
| 86 |
git: |
| 87 |
repo: "{{ git_gpg_source }}" |
| 88 |
dest: "{{ git_gpg_dest }}" |
| 89 |
version: lightweight_tag/signed_commit |
| 90 |
verify_commit: yes |
| 91 |
when: |
| 92 |
- git_version.stdout is version("2.1.0", '>=') |
| 93 |
|
| 94 |
- name: GPG-VERIFICATION | Clone repo and verify an unsigned lightweight tag (should fail) |
| 95 |
environment: |
| 96 |
- GNUPGHOME: "{{ git_gpg_gpghome }}" |
| 97 |
git: |
| 98 |
repo: "{{ git_gpg_source }}" |
| 99 |
dest: "{{ git_gpg_dest }}" |
| 100 |
version: lightweight_tag/unsigned_commit |
| 101 |
verify_commit: yes |
| 102 |
register: git_verify |
| 103 |
ignore_errors: yes |
| 104 |
when: |
| 105 |
- git_version.stdout is version("2.1.0", '>=') |
| 106 |
|
| 107 |
- name: GPG-VERIFICATION | Check that unsigned lightweight tag verification failed |
| 108 |
assert: |
| 109 |
that: |
| 110 |
- git_verify is failed |
| 111 |
- git_verify.msg is match("Failed to verify GPG signature of commit/tag.+") |
| 112 |
when: |
| 113 |
- git_version.stdout is version("2.1.0", '>=') |
| 114 |
|
| 115 |
- name: GPG-VERIFICATION | Clone repo and verify a signed commit |
| 116 |
environment: |
| 117 |
- GNUPGHOME: "{{ git_gpg_gpghome }}" |
| 118 |
git: |
| 119 |
repo: "{{ git_gpg_source }}" |
| 120 |
dest: "{{ git_gpg_dest }}" |
| 121 |
version: "{{ git_gpg_signed_commit.stdout }}" |
| 122 |
verify_commit: yes |
| 123 |
when: |
| 124 |
- git_version.stdout is version("2.1.0", '>=') |
| 125 |
|
| 126 |
- name: GPG-VERIFICATION | Clone repo and verify an unsigned commit |
| 127 |
environment: |
| 128 |
- GNUPGHOME: "{{ git_gpg_gpghome }}" |
| 129 |
git: |
| 130 |
repo: "{{ git_gpg_source }}" |
| 131 |
dest: "{{ git_gpg_dest }}" |
| 132 |
version: "{{ git_gpg_unsigned_commit.stdout }}" |
| 133 |
verify_commit: yes |
| 134 |
register: git_verify |
| 135 |
ignore_errors: yes |
| 136 |
when: |
| 137 |
- git_version.stdout is version("2.1.0", '>=') |
| 138 |
|
| 139 |
- name: GPG-VERIFICATION | Check that unsigned commit verification failed |
| 140 |
assert: |
| 141 |
that: |
| 142 |
- git_verify is failed |
| 143 |
- git_verify.msg is match("Failed to verify GPG signature of commit/tag.+") |
| 144 |
when: |
| 145 |
- git_version.stdout is version("2.1.0", '>=') |
| 146 |
|
| 147 |
- name: GPG-VERIFICATION | Clone repo and verify a signed annotated tag |
| 148 |
environment: |
| 149 |
- GNUPGHOME: "{{ git_gpg_gpghome }}" |
| 150 |
git: |
| 151 |
repo: "{{ git_gpg_source }}" |
| 152 |
dest: "{{ git_gpg_dest }}" |
| 153 |
version: signed_annotated_tag |
| 154 |
verify_commit: yes |
| 155 |
|
| 156 |
- name: GPG-VERIFICATION | Clone repo and verify an unsigned annotated tag (should fail) |
| 157 |
environment: |
| 158 |
- GNUPGHOME: "{{ git_gpg_gpghome }}" |
| 159 |
git: |
| 160 |
repo: "{{ git_gpg_source }}" |
| 161 |
dest: "{{ git_gpg_dest }}" |
| 162 |
version: unsigned_annotated_tag |
| 163 |
verify_commit: yes |
| 164 |
register: git_verify |
| 165 |
ignore_errors: yes |
| 166 |
|
| 167 |
- name: GPG-VERIFICATION | Check that unsigned annotated tag verification failed |
| 168 |
assert: |
| 169 |
that: |
| 170 |
- git_verify is failed |
| 171 |
- git_verify.msg is match("Failed to verify GPG signature of commit/tag.+") |
| 172 |
|
| 173 |
- name: GPG-VERIFICATION | Clone repo and verify a signed branch |
| 174 |
environment: |
| 175 |
- GNUPGHOME: "{{ git_gpg_gpghome }}" |
| 176 |
git: |
| 177 |
repo: "{{ git_gpg_source }}" |
| 178 |
dest: "{{ git_gpg_dest }}" |
| 179 |
version: some_branch/signed_tip |
| 180 |
verify_commit: yes |
| 181 |
when: |
| 182 |
- git_version.stdout is version("2.1.0", '>=') |
| 183 |
|
| 184 |
- name: GPG-VERIFICATION | Clone repo and verify an unsigned branch (should fail) |
| 185 |
environment: |
| 186 |
- GNUPGHOME: "{{ git_gpg_gpghome }}" |
| 187 |
git: |
| 188 |
repo: "{{ git_gpg_source }}" |
| 189 |
dest: "{{ git_gpg_dest }}" |
| 190 |
version: another_branch/unsigned_tip |
| 191 |
verify_commit: yes |
| 192 |
register: git_verify |
| 193 |
ignore_errors: yes |
| 194 |
when: |
| 195 |
- git_version.stdout is version("2.1.0", '>=') |
| 196 |
|
| 197 |
- name: GPG-VERIFICATION | Check that unsigned branch verification failed |
| 198 |
assert: |
| 199 |
that: |
| 200 |
- git_verify is failed |
| 201 |
- git_verify.msg is match("Failed to verify GPG signature of commit/tag.+") |
| 202 |
when: |
| 203 |
- git_version.stdout is version("2.1.0", '>=') |
| 204 |
|
| 205 |
- name: GPG-VERIFICATION | Stop gpg-agent so we can remove any locks on the GnuPG dir |
| 206 |
command: gpgconf --kill gpg-agent |
| 207 |
environment: |
| 208 |
GNUPGHOME: "{{ git_gpg_gpghome }}" |
| 209 |
ignore_errors: yes |
| 210 |
|
| 211 |
- name: GPG-VERIFICATION | Remove GnuPG verification workdir |
| 212 |
file: |
| 213 |
path: "{{ git_gpg_workdir.path }}" |
| 214 |
state: absent |