forked from GovStackWorkingGroup/IM_Demo_InstallingScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init_ss1.yml
352 lines (312 loc) · 10.5 KB
/
init_ss1.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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
---
- name: Initialize ss1
hosts: ss1.egovstack.net
vars_files: vars_with_secret.yml
vars:
user: xrd
apikey: "{{ apikey_json['key'] }}"
softToken0_fromlist: "{{ token_list.json | selectattr('name', 'equalto', 'softToken-0') | first }}"
softToken0: "{{ token_info.json }}"
key_name:
signing: signingKey
authentication: authKey
key_type: signing
key_list: "{{ softToken0['keys'] | selectattr('name', 'equalto', key_name[key_type]) }}"
key_detail: "{{ key_list | default([{}], true) | first }}"
tasks:
- name: Create API key
uri:
method: POST
url: https://localhost:4000/api/v1/api-keys
user: "{{ user }}"
password: "{{ password }}"
body:
- XROAD_SECURITY_OFFICER
- XROAD_REGISTRATION_OFFICER
- XROAD_SERVICE_ADMINISTRATOR
- XROAD_SYSTEM_ADMINISTRATOR
- XROAD_SECURITYSERVER_OBSERVER
body_format: json
validate_certs: no
creates: /home/host/APIKEY
dest: /home/host/APIKEY
no_log: true
- name: Register JSON output as a variable
command: cat /home/host/APIKEY
register: apikey_result
- name: Set a variable
ansible.builtin.set_fact:
apikey_json: "{{ apikey_result.stdout | from_json }}"
# Initialize
#
- name: Get initialization status
uri:
method: GET
url: https://localhost:4000/api/v1/initialization/status
headers:
authorization: X-Road-ApiKey token={{ apikey }}
validate_certs: no
register: init_status
- name: Initialize Configuration Anchor
when: not init_status.json.is_anchor_imported
uri:
method: POST
url: https://localhost:4000/api/v1/system/anchor
headers:
authorization: X-Road-ApiKey token={{ apikey }}
Content-Type: application/octet-stream
src: /home/host/configuration_anchor_egovstack_internal.xml
status_code: [200, 201]
validate_certs: no
- name: Initialize Security Server
when: not init_status.json.is_server_owner_initialized
uri:
method: POST
url: https://localhost:4000/api/v1/initialization
headers:
authorization: X-Road-ApiKey token={{ apikey }}
body: '{{ api_body | to_json }}'
body_format: json
status_code: [200, 201]
validate_certs: no
vars:
api_body:
owner_member_class: GOV
owner_member_code: "0"
security_server_code: "{{ inventory_hostname_short }}"
software_token_pin: "0123"
ignore_warnings: false
- name: Get list of security tokens
uri:
method: GET
url: https://localhost:4000/api/v1/tokens
headers:
authorization: X-Road-ApiKey token={{ apikey }}
validate_certs: no
register: token_list
- name: Login to security token
when: not softToken0_fromlist.logged_in
uri:
method: PUT
url: https://localhost:4000/api/v1/tokens/{{ softToken0_fromlist.id }}/login
headers:
authorization: X-Road-ApiKey token={{ apikey }}
body: '{{ api_body | to_json }}'
body_format: json
validate_certs: no
vars:
api_body:
password: "0123"
- name: Get token info
uri:
method: GET
url: https://localhost:4000/api/v1/tokens/{{ softToken0_fromlist.id }}
headers:
authorization: X-Road-ApiKey token={{ apikey }}
validate_certs: no
register: token_info
# Create Signing key
#
- name: Set key type SIGNING
ansible.builtin.set_fact:
key_type: signing
- name: Delete {{ key_type }} keys without csr and without certificate
when: not item.certificate_signing_requests and not item.certificates
uri:
method: DELETE
url: https://localhost:4000/api/v1/keys/{{ item.id }}
headers:
authorization: X-Road-ApiKey token={{ apikey }}
status_code: [200, 204]
validate_certs: no
loop: "{{ key_list }}"
register: delete_status
- name: Refresh token info after delete
uri:
method: GET
url: https://localhost:4000/api/v1/tokens/{{ softToken0.id }}
headers:
authorization: X-Road-ApiKey token={{ apikey }}
validate_certs: no
register: token_info
- debug:
var: softToken0
- name: Create {{ key_type }} key csr
when: not key_list or not (key_detail.certificate_signing_requests or key_detail.certificates)
uri:
method: POST
url: https://localhost:4000/api/v1/tokens/{{ softToken0.id }}/keys-with-csrs
headers:
authorization: X-Road-ApiKey token={{ apikey }}
body: '{{ api_body | to_json }}'
body_format: json
validate_certs: no
vars:
api_body:
key_label: "{{ key_name[key_type] }}"
csr_generate_request:
key_usage_type: "{{ key_type | upper }}"
ca_name: "Test CA"
csr_format: "PEM"
member_id: "egovstack:GOV:0"
subject_field_values:
C: "egovstack"
O: "GOV"
CN: "0"
register: signing_request
- name: Remove old files
when: signing_request is not skipped
command: rm -f /home/host/{{ key_name[key_type] }}.csr /home/host/{{ key_name[key_type] }}.cer
- name: Refresh token info after csr
uri:
method: GET
url: https://localhost:4000/api/v1/tokens/{{ softToken0.id }}
headers:
authorization: X-Road-ApiKey token={{ apikey }}
validate_certs: no
register: token_info
- debug:
var: token_info
- name: Get {{ key_type }} key csr
when: not key_detail.certificates
uri:
method: GET
url: https://localhost:4000/api/v1/keys/{{ key_detail.id }}/csrs/{{ key_detail.certificate_signing_requests[0].id }}?csr_format=PEM
headers:
authorization: X-Road-ApiKey token={{ apikey }}
validate_certs: no
creates: /home/host/{{ key_name[key_type] }}.csr
dest: /home/host/{{ key_name[key_type] }}.csr
- name: Get stat of {{ key_name[key_type] }}.cer
stat:
path: /home/host/{{ key_name[key_type] }}.cer
register: stat_info
- name: Certify {{ key_type }} key
when: not stat_info.stat.exists
command:
cmd: curl -Fcertreq=@{{ key_name[key_type] }}.csr http://ca.egovstack.net:8888/testca/sign -o {{ key_name[key_type] }}.cer
- name: Upload {{ key_type }} key certificate
when: not key_detail.certificates
uri:
method: POST
url: https://localhost:4000/api/v1/token-certificates
headers:
authorization: X-Road-ApiKey token={{ apikey }}
Content-Type: application/octet-stream
remote_src: yes
src: "{{ key_name[key_type] }}.cer"
status_code: [200, 201]
validate_certs: no
# Create Authentication key
#
- name: Set key type AUTHENTICATION
ansible.builtin.set_fact:
key_type: authentication
- name: Delete {{ key_type }} keys without csr and without certificate
when: not item.certificate_signing_requests and not item.certificates
uri:
method: DELETE
url: https://localhost:4000/api/v1/keys/{{ item.id }}
headers:
authorization: X-Road-ApiKey token={{ apikey }}
status_code: [200, 204]
validate_certs: no
loop: "{{ key_list }}"
register: delete_status
- name: Refresh token info after delete
uri:
method: GET
url: https://localhost:4000/api/v1/tokens/{{ softToken0.id }}
headers:
authorization: X-Road-ApiKey token={{ apikey }}
validate_certs: no
register: token_info
- debug:
var: softToken0
- name: Create {{ key_type }} key csr
when: not key_list or not (key_detail.certificate_signing_requests or key_detail.certificates)
uri:
method: POST
url: https://localhost:4000/api/v1/tokens/{{ softToken0.id }}/keys-with-csrs
headers:
authorization: X-Road-ApiKey token={{ apikey }}
body: '{{ api_body | to_json }}'
body_format: json
validate_certs: no
vars:
api_body:
key_label: "{{ key_name[key_type] }}"
csr_generate_request:
key_usage_type: "{{ key_type | upper }}"
ca_name: "Test CA"
csr_format: "PEM"
subject_field_values:
C: "egovstack"
CN: "ss1"
register: signing_request
- name: Remove old files
when: signing_request is not skipped
command: rm -f /home/host/{{ key_name[key_type] }}.csr /home/host/{{ key_name[key_type] }}.cer
- name: Refresh token info after csr
uri:
method: GET
url: https://localhost:4000/api/v1/tokens/{{ softToken0.id }}
headers:
authorization: X-Road-ApiKey token={{ apikey }}
validate_certs: no
register: token_info
- debug:
var: token_info
- name: Get {{ key_type }} key csr
when: not key_detail.certificates
uri:
method: GET
url: https://localhost:4000/api/v1/keys/{{ key_detail.id }}/csrs/{{ key_detail.certificate_signing_requests[0].id }}?csr_format=PEM
headers:
authorization: X-Road-ApiKey token={{ apikey }}
validate_certs: no
creates: /home/host/{{ key_name[key_type] }}.csr
dest: /home/host/{{ key_name[key_type] }}.csr
- name: Get stat of {{ key_name[key_type] }}.cer
stat:
path: /home/host/{{ key_name[key_type] }}.cer
register: stat_info
- name: Certify {{ key_type }} key
when: not stat_info.stat.exists
command:
cmd: curl -Fcertreq=@{{ key_name[key_type] }}.csr http://ca.egovstack.net:8888/testca/sign -o {{ key_name[key_type] }}.cer
- name: Upload {{ key_type }} key certificate
when: not key_detail.certificates
uri:
method: POST
url: https://localhost:4000/api/v1/token-certificates
headers:
authorization: X-Road-ApiKey token={{ apikey }}
Content-Type: application/octet-stream
remote_src: yes
src: "{{ key_name[key_type] }}.cer"
status_code: [200, 201]
validate_certs: no
- name: Refresh token info after cert upload
uri:
method: GET
url: https://localhost:4000/api/v1/tokens/{{ softToken0.id }}
headers:
authorization: X-Road-ApiKey token={{ apikey }}
validate_certs: no
register: token_info
- debug:
var: key_detail
- name: Register certificate
uri:
method: PUT
url: https://localhost:4000/api/v1/token-certificates/{{ key_detail.certificates[0].certificate_details.hash }}/register
headers:
authorization: X-Road-ApiKey token={{ apikey }}
body: '{{ api_body | to_json }}'
body_format: json
status_code: [200, 201, 204]
validate_certs: no
vars:
api_body:
address: "{{ inventory_hostname }}"