-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
verify.yml
270 lines (261 loc) · 11 KB
/
verify.yml
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
---
- name: Verify
hosts: all
gather_facts: false
vars:
pki_base: '/var/local/lib/pki'
t1base: "{{ pki_base }}/test1"
t1ca: "{{ t1base }}/ca"
t1sub1: "{{ t1base }}/subca_sub1"
t1sub2: "{{ t1base }}/subca_sub2"
t2base: "{{ pki_base }}/test2"
t2ca: "{{ t2base }}/ca"
t2sub1: "{{ t2base }}/subca_sub1"
owner: 'pki'
owner2: 'pki2'
group_read: 'pki_read'
group_read2: 'pki_read2'
tasks:
- name: Performing backup
ansible.builtin.systemd:
name: 'backup-pki.service'
state: started
- name: Performing CRL-Update
ansible.builtin.systemd:
name: 'pki-crl-updater.service'
state: started
- name: Checking certificate existence
ansible.builtin.stat:
path: "{{ item }}"
register: test_cert_file
failed_when: not test_cert_file.stat.exists
loop:
# instance 1
- "{{ t1ca }}/ca.crt"
- "{{ t1ca }}/private/ca.key"
## sub-ca 1
### defaults
- "{{ t1sub1 }}/ca.crt"
- "{{ t1sub1 }}/private/ca.key"
- "{{ t1sub1 }}/issued/server_test2.chain.crt"
- "{{ t1sub1 }}/private/server_test2.p12"
- "{{ t1sub1 }}/issued/server_test2.crt"
- "{{ t1sub1 }}/private/server_test2.key"
- "{{ t1sub1 }}/issued/client_wkst1.crt"
- "{{ t1sub1 }}/private/client_wkst1.key"
- "{{ t1sub1 }}/issued/email_guy.crt"
- "{{ t1sub1 }}/private/email_guy.key"
- "{{ t1sub1 }}/private/server_ansibleguynet.p12"
- "{{ t1sub1 }}/issued/server_ansibleguynet.crt"
- "{{ t1sub1 }}/private/server_ansibleguynet.key"
### custom configured
- "{{ t1sub1 }}/private/server_ansibleguynet.unencrypted.key"
# sub-ca 2
### defaults
- "{{ t1sub2 }}/ca.crt"
- "{{ t1sub2 }}/private/ca.key"
- "{{ t1sub2 }}/issued/server_random1.crt"
- "{{ t1sub2 }}/issued/server_random1.chain.crt"
- "{{ t1sub2 }}/private/server_random1.key"
- "{{ t1sub2 }}/private/server_random1.p12"
### custom configured
# - "{{ t1sub2 }}/private/server_random1.p1"
- "{{ t1sub2 }}/issued/server_random1.p7b"
- "{{ t1sub2 }}/private/server_random1.p8"
# instance 2
- "{{ t2ca }}/ca.crt"
- "{{ t2ca }}/private/ca.key"
- "{{ t2sub1 }}/ca.crt"
- "{{ t2sub1 }}/private/ca.key"
# single
- "{{ t1sub1 }}/issued/server_single.crt"
- "{{ t1sub1 }}/issued/server_single.chain.crt"
- "{{ t1sub1 }}/private/server_single.key"
- "{{ t1sub1 }}/private/server_single.p12"
- "{{ t1sub1 }}/private/server_single.unencrypted.key"
- name: Checking certificate absence
ansible.builtin.stat:
path: "{{ item }}"
register: test_cert_file
failed_when: test_cert_file.stat.exists
loop:
# instance 1
- "{{ t1sub1 }}/private/server_test2.p1"
- "{{ t1sub1 }}/issued/server_test2.p7b"
- "{{ t1sub1 }}/private/server_test2.p8"
- "{{ t1sub1 }}/private/server_test2.unencrypted.key"
# sub-ca 2
- "{{ t1sub2 }}/private/server_random1.unencrypted.key"
- "{{ t1sub2 }}/issued/serverClient_random2.chain.crt"
- "{{ t1sub2 }}/private/serverClient_random2.p12"
- name: Checking certificate content
ansible.builtin.shell: |
set -o pipefail
openssl x509 -in {{ item.file }} -text | grep -q '{{ item.find }}'
changed_when: false
args:
executable: '/bin/bash'
with_items:
# instance 1
- {file: "{{ t1ca }}/ca.crt", find: 'Signature Algorithm: ecdsa-with-SHA512'}
- {file: "{{ t1ca }}/ca.crt", find: 'ASN1 OID: secp384r1'}
- {file: "{{ t1ca }}/ca.crt", find: 'CRL Distribution Points'}
- {file: "{{ t1ca }}/ca.crt", find: 'URI:http://crl.ansibleguy.net/ca.crl'}
- {file: "{{ t1ca }}/ca.crt", find: 'CA Issuers - URI:http://crl.ansibleguy.net/ca.crt'}
- {file: "{{ t1ca }}/ca.crt", find: 'CA:TRUE'}
- {file: "{{ t1ca }}/ca.crt", find: 'Subject: C = AT, ST = Styria, O = Ultra Company, OU = IT, CN = TestRootCA, emailAddress = [email protected]'}
## sub-ca 1
- {file: "{{ t1sub1 }}/ca.crt", find: 'Signature Algorithm: ecdsa-with-SHA256'}
- {file: "{{ t1sub1 }}/ca.crt", find: 'ASN1 OID: secp384r1'}
- {file: "{{ t1sub1 }}/ca.crt", find: 'CRL Distribution Points'}
- {file: "{{ t1sub1 }}/ca.crt", find: 'URI:http://crl.ansibleguy.net/ca.crl'}
- {file: "{{ t1sub1 }}/ca.crt", find: 'CA Issuers - URI:http://crl.ansibleguy.net/ca.crt'}
- {file: "{{ t1sub1 }}/ca.crt", find: 'CA:TRUE'}
- {file: "{{ t1sub1 }}/ca.crt", find: 'Issuer: C = AT, ST = Styria, O = Ultra Company, OU = IT, CN = TestRootCA, emailAddress = [email protected]'}
- {file: "{{ t1sub1 }}/ca.crt", find: 'Subject: C = AT, ST = Styria, L = Graz, O = Internal Org, CN = TestSubCA1, emailAddress = [email protected]'}
- {file: "{{ t1sub1 }}/ca.crt", find: 'DirName:/C=AT/ST=Styria/O=Ultra Company/OU=IT/CN=TestRootCA/[email protected]'}
- {file: "{{ t1sub1 }}/issued/server_test2.crt", find: 'Signature Algorithm: ecdsa-with-SHA256'}
- {file: "{{ t1sub1 }}/issued/server_test2.crt", find: 'ASN1 OID: secp384r1'}
- {file: "{{ t1sub1 }}/issued/server_test2.crt", find: 'CRL Distribution Points'}
- {file: "{{ t1sub1 }}/issued/server_test2.crt", find: 'URI:http://crl.ansibleguy.net/subca_sub1.crl'}
- {file: "{{ t1sub1 }}/issued/server_test2.crt", find: 'CA Issuers - URI:http://crl.ansibleguy.net/subca_sub1.crt'}
- {file: "{{ t1sub1 }}/issued/server_ansibleguynet.crt",
find: 'Subject: C = AT, ST = Styria, L = Graz, O = Internal Org, CN = AnsibleGuy Website, emailAddress = [email protected]'}
- {file: "{{ t1sub1 }}/issued/server_ansibleguynet.crt",
find: 'Issuer: C = AT, ST = Styria, L = Graz, O = Internal Org, CN = TestSubCA1, emailAddress = [email protected]'}
- {file: "{{ t1sub1 }}/issued/server_ansibleguynet.crt",
find: 'DNS:www.ansibleguy.net, DNS:ansibleguy.net, IP Address:135.181.170.217, URI:https://www.ansibleguy.net'}
## sub-ca 2
- {file: "{{ t1sub2 }}/issued/server_random1.crt", find: 'URI:http://crl.ansibleguy.net/subca_sub2.crl'}
- {file: "{{ t1sub2 }}/issued/server_random1.crt", find: 'CA Issuers - URI:http://crl.ansibleguy.net/subca_sub2.crt'}
- {file: "{{ t1sub2 }}/issued/server_random1.crt", find: 'DNS:random.ansible.net'}
- {file: "{{ t1sub2 }}/issued/serverClient_random2.crt",
find: 'Subject: C = DE, ST = test2province, O = test2org, OU = test2ou, CN = ServerClientTest, emailAddress = [email protected]'}
- {file: "{{ t1sub2 }}/issued/serverClient_random2.crt", find: 'TLS Web Server Authentication, TLS Web Client Authentication'}
# single
- {file: "{{ t1sub1 }}/issued/server_single.crt", find: 'DNS:single.test, IP Address:192.168.0.1'}
- {file: "{{ t1sub1 }}/issued/server_single.crt",
find: 'Subject: C = AT, ST = Styria, L = Graz, O = test1org, CN = Single Certificate, emailAddress = [email protected]'}
- name: Checking file/directory permissions (chmod)
ansible.builtin.shell: |
set -o pipefail
ls -l {{ item.path }} | cut -d ' ' -f1
changed_when: false
args:
executable: '/bin/bash'
register: test_chmod
failed_when: test_chmod.stdout_lines[1:] != item.expect
with_items:
- {path: "{{ t1sub1 }}", expect: [
'-rw-r-----',
'-rw-r-----',
'drwxr-x---',
'-rw-r-----',
'-rw-r-----',
'-rw-r-----',
'-rw-r-----',
'-rw-r-----',
'-rw-r-----',
'drwxr-x---',
'drwxr-x---',
'-rw-r-----',
'drwxr-x---',
'drwxr-x---',
'drwxr-x---',
'-rw-r-----',
'-rw-r-----',
'-rw-r-----',
'drwxr-x---',
]}
- {path: "{{ t1sub1 }}/issued", expect: [
'-rw-r-----',
'-rw-r-----',
'-rw-r-----',
'-rw-r-----',
'-rw-r-----',
'-rw-r-----',
'-rw-r-----',
'-rw-r-----',
'-rw-r-----',
'-rw-r-----',
]}
- {path: "{{ t1sub1 }}/private", expect: [
'-rw-r-----',
'-rw-r-----',
'-rw-r-----',
'-rw-r-----',
'-rw-r-----',
'-rw-r-----',
'-rw-r-----',
'-rw-r-----',
'-rw-r-----',
'-rw-r-----',
'-rw-r-----',
'-rw-r-----',
'-rw-r-----',
]}
- name: Checking file/directory ownership (chown)
ansible.builtin.shell: |
set -o pipefail
ls -l {{ item.path }} | cut -d ' ' -f{{ item.fields }}
changed_when: false
args:
executable: '/bin/bash'
register: test_chown
failed_when: test_chown.stdout_lines[1:] != item.expect
with_items:
- {path: "{{ t1sub1 }}", fields: '3-4', expect: [
"{{ owner }} {{ group_read }}",
"{{ owner }} {{ group_read }}",
"{{ owner }} {{ group_read }}",
"{{ owner }} {{ group_read }}",
"{{ owner }} {{ group_read }}",
"{{ owner }} {{ owner }}",
"{{ owner }} {{ owner }}",
"{{ owner }} {{ owner }}",
"{{ owner }} {{ owner }}",
"{{ owner }} {{ owner }}",
"{{ owner }} {{ group_read }}",
"{{ owner }} {{ owner }}",
"{{ owner }} {{ owner }}",
"{{ owner }} {{ owner }}",
"{{ owner }} {{ owner }}",
"{{ owner }} {{ owner }}",
"{{ owner }} {{ owner }}",
"{{ owner }} {{ owner }}",
"{{ owner }} {{ owner }}",
]}
- {path: "{{ t1sub1 }}/private", fields: '3-4', expect: [
"{{ owner }} {{ owner }}",
"{{ owner }} {{ owner }}",
"{{ owner }} {{ owner }}",
"{{ owner }} {{ owner }}",
"{{ owner }} {{ owner }}",
"{{ owner }} {{ owner }}",
"{{ owner }} {{ owner }}",
"{{ owner }} {{ owner }}",
"{{ owner }} {{ owner }}",
"{{ owner }} {{ owner }}",
"{{ owner }} {{ owner }}",
"{{ owner }} {{ owner }}",
"{{ owner }} {{ owner }}",
]}
- {path: "{{ t1sub1 }}/issued", fields: '3-4', expect: [
"{{ owner }} {{ group_read }}",
"{{ owner }} {{ group_read }}",
"{{ owner }} {{ group_read }}",
"{{ owner }} {{ group_read }}",
"{{ owner }} {{ group_read }}",
"{{ owner }} {{ group_read }}",
"{{ owner }} {{ group_read }}",
"{{ owner }} {{ group_read }}",
"{{ owner }} {{ group_read }}",
"{{ owner }} {{ group_read }}",
]}
- {path: "{{ t2sub1 }}/private", fields: '3-4', expect: [
"{{ owner2 }} {{ owner2 }}",
]}
- {path: "{{ t2base }}", fields: '3-4', expect: [
"{{ owner2 }} {{ group_read2 }}",
"{{ owner2 }} {{ group_read2 }}",
]}