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