-
Notifications
You must be signed in to change notification settings - Fork 141
611 lines (517 loc) · 22.9 KB
/
kra-clone-hsm-test.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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
name: KRA clone with HSM
on: workflow_call
env:
DS_IMAGE: ${{ vars.DS_IMAGE || 'quay.io/389ds/dirsrv' }}
jobs:
# docs/installation/kra/Installing_KRA_Clone_with_HSM.md
test:
name: Test
runs-on: ubuntu-latest
env:
SHARED: /tmp/workdir/pki
steps:
- name: Clone repository
uses: actions/checkout@v4
- name: Retrieve PKI images
uses: actions/cache@v4
with:
key: pki-images-${{ github.sha }}
path: pki-images.tar
- name: Load PKI images
run: docker load --input pki-images.tar
- name: Create network
run: docker network create example
- name: Set up primary DS container
run: |
tests/bin/ds-create.sh \
--image=${{ env.DS_IMAGE }} \
--hostname=primaryds.example.com \
--password=Secret.123 \
primaryds
- name: Connect primary DS container to network
run: docker network connect example primaryds --alias primaryds.example.com
- name: Set up primary PKI container
run: |
tests/bin/runner-init.sh primary
env:
HOSTNAME: primary.example.com
- name: Connect primary PKI container to network
run: docker network connect example primary --alias primary.example.com
- name: Install dependencies in primary PKI container
run: |
docker exec primary dnf install -y softhsm
- name: Create SoftHSM token in primary PKI container
run: |
# allow PKI user to access SoftHSM files
docker exec primary usermod pkiuser -a -G ods
# create SoftHSM token for PKI server
docker exec primary runuser -u pkiuser -- \
softhsm2-util \
--init-token \
--label HSM \
--so-pin Secret.HSM \
--pin Secret.HSM \
--free
docker exec primary ls -laR /var/lib/softhsm/tokens
docker exec primary runuser -u pkiuser -- \
softhsm2-util --show-slots
- name: Install CA in primary PKI container
run: |
docker exec primary pkispawn \
-f /usr/share/pki/server/examples/installation/ca.cfg \
-s CA \
-D pki_ds_url=ldap://primaryds.example.com:3389 \
-D pki_hsm_enable=True \
-D pki_token_name=HSM \
-D pki_token_password=Secret.HSM \
-D pki_ca_signing_token=HSM \
-D pki_ocsp_signing_token=HSM \
-D pki_audit_signing_token=HSM \
-D pki_subsystem_token=HSM \
-D pki_sslserver_token=internal \
-v
- name: Install KRA in primary PKI container
run: |
docker exec primary pkispawn \
-f /usr/share/pki/server/examples/installation/kra.cfg \
-s KRA \
-D pki_ds_url=ldap://primaryds.example.com:3389 \
-D pki_hsm_enable=True \
-D pki_token_name=HSM \
-D pki_token_password=Secret.HSM \
-D pki_storage_token=HSM \
-D pki_transport_token=HSM \
-D pki_audit_signing_token=HSM \
-D pki_subsystem_token=HSM \
-D pki_sslserver_token=internal \
-v
- name: Check system certs in internal token
run: |
# there should be 8 certs
echo "8" > expected
docker exec primary pki \
-d /var/lib/pki/pki-tomcat/conf/alias \
nss-cert-find | tee output
grep "Serial Number:" output | wc -l > actual
diff expected actual
- name: Check system certs in HSM
run: |
# there should be 7 certs
echo "7" > expected
docker exec primary pki \
-d /var/lib/pki/pki-tomcat/conf/alias \
-f /var/lib/pki/pki-tomcat/conf/password.conf \
--token HSM \
nss-cert-find | tee output
grep "Serial Number:" output | wc -l > actual
diff expected actual
- name: Copy keys from primary PKI container
run: |
docker exec primary ls -laR /var/lib/softhsm/tokens
docker cp primary:/var/lib/softhsm/tokens/. tokens
ls -laR tokens
- name: Set up secondary DS container
run: |
tests/bin/ds-create.sh \
--image=${{ env.DS_IMAGE }} \
--hostname=secondaryds.example.com \
--password=Secret.123 \
secondaryds
- name: Connect secondary DS container to network
run: docker network connect example secondaryds --alias secondaryds.example.com
- name: Set up secondary PKI container
run: |
tests/bin/runner-init.sh secondary
env:
HOSTNAME: secondary.example.com
- name: Connect secondary PKI container to network
run: docker network connect example secondary --alias secondary.example.com
- name: Install dependencies in secondary PKI container
run: |
docker exec secondary dnf install -y softhsm
- name: Copy keys to secondary PKI container
run: |
# allow PKI user to access SoftHSM files
docker exec secondary usermod pkiuser -a -G ods
docker cp tokens/. secondary:/var/lib/softhsm/tokens
docker exec secondary chown -R pkiuser:pkiuser /var/lib/softhsm/tokens
docker exec secondary ls -laR /var/lib/softhsm/tokens
docker exec secondary runuser -u pkiuser -- \
softhsm2-util --show-slots
- name: Install CA in secondary PKI container
run: |
docker exec primary pki-server cert-export ca_signing \
--cert-file ${SHARED}/ca_signing.crt
docker exec secondary pkispawn \
-f /usr/share/pki/server/examples/installation/ca-clone.cfg \
-s CA \
-D pki_cert_chain_path=${SHARED}/ca_signing.crt \
-D pki_ds_url=ldap://secondaryds.example.com:3389 \
-D pki_hsm_enable=True \
-D pki_token_name=HSM \
-D pki_token_password=Secret.HSM \
-D pki_ca_signing_token=HSM \
-D pki_ocsp_signing_token=HSM \
-D pki_audit_signing_token=HSM \
-D pki_subsystem_token=HSM \
-D pki_sslserver_token=internal \
-v
- name: Install KRA in secondary PKI container
run: |
# get CS.cfg from primary KRA before cloning
docker cp primary:/var/lib/pki/pki-tomcat/conf/kra/CS.cfg CS.cfg.primary
docker exec secondary pkispawn \
-f /usr/share/pki/server/examples/installation/kra-clone.cfg \
-s KRA \
-D pki_cert_chain_path=${SHARED}/ca_signing.crt \
-D pki_ds_url=ldap://secondaryds.example.com:3389 \
-D pki_hsm_enable=True \
-D pki_token_name=HSM \
-D pki_token_password=Secret.HSM \
-D pki_server_database_password=Secret.123 \
-D pki_storage_token=HSM \
-D pki_transport_token=HSM \
-D pki_audit_signing_token=HSM \
-D pki_subsystem_token=HSM \
-D pki_sslserver_token=internal \
-v
- name: Check system certs in internal token
run: |
# there should be 4 certs
# NOTE: ideally it should match the
# primary CA, but it works fine as is
# TODO: investigate the discrepancy
echo "4" > expected
docker exec secondary pki \
-d /var/lib/pki/pki-tomcat/conf/alias \
nss-cert-find | tee output
grep "Serial Number:" output | wc -l > actual
diff expected actual
- name: Check system certs in HSM
run: |
# there should be 7 certs
echo "7" > expected
docker exec secondary pki \
-d /var/lib/pki/pki-tomcat/conf/alias \
-f /var/lib/pki/pki-tomcat/conf/password.conf \
--token HSM \
nss-cert-find | tee output
grep "Serial Number:" output | wc -l > actual
diff expected actual
- name: Check CS.cfg in primary KRA after cloning
run: |
# get CS.cfg from primary KRA after cloning
docker cp primary:/var/lib/pki/pki-tomcat/conf/kra/CS.cfg CS.cfg.primary.after
# normalize expected result:
# - remove params that cannot be compared
# - set dbs.enableSerialManagement to true (automatically enabled when cloned)
sed -e '/^dbs.beginReplicaNumber=/d' \
-e '/^dbs.endReplicaNumber=/d' \
-e '/^dbs.nextBeginReplicaNumber=/d' \
-e '/^dbs.nextEndReplicaNumber=/d' \
-e 's/^\(dbs.enableSerialManagement\)=.*$/\1=true/' \
CS.cfg.primary \
| sort > expected
# normalize actual result:
# - remove params that cannot be compared
sed -e '/^dbs.beginReplicaNumber=/d' \
-e '/^dbs.endReplicaNumber=/d' \
-e '/^dbs.nextBeginReplicaNumber=/d' \
-e '/^dbs.nextEndReplicaNumber=/d' \
CS.cfg.primary.after \
| sort > actual
diff expected actual
- name: Check CS.cfg in secondary KRA
run: |
# get CS.cfg from secondary KRA
docker cp secondary:/var/lib/pki/pki-tomcat/conf/kra/CS.cfg CS.cfg.secondary
# normalize expected result:
# - remove params that cannot be compared
# - replace primary.example.com with secondary.example.com
# - replace primaryds.example.com with secondaryds.example.com
# - set securitydomain.host to primary.example.com
sed -e '/^installDate=/d' \
-e '/^dbs.beginReplicaNumber=/d' \
-e '/^dbs.endReplicaNumber=/d' \
-e '/^dbs.nextBeginReplicaNumber=/d' \
-e '/^dbs.nextEndReplicaNumber=/d' \
-e '/^kra.sslserver.cert=/d' \
-e '/^kra.sslserver.certreq=/d' \
-e 's/primary.example.com/secondary.example.com/' \
-e 's/primaryds.example.com/secondaryds.example.com/' \
-e 's/^\(securitydomain.host\)=.*$/\1=primary.example.com/' \
CS.cfg.primary.after \
| sort > expected
# normalize actual result:
# - remove params that cannot be compared
sed -e '/^installDate=/d' \
-e '/^dbs.beginReplicaNumber=/d' \
-e '/^dbs.endReplicaNumber=/d' \
-e '/^dbs.nextBeginReplicaNumber=/d' \
-e '/^dbs.nextEndReplicaNumber=/d' \
-e '/^kra.sslserver.cert=/d' \
-e '/^kra.sslserver.certreq=/d' \
CS.cfg.secondary \
| sort > actual
diff expected actual
- name: Check KRA admin in secondary PKI container
run: |
docker exec primary cp /root/.dogtag/pki-tomcat/ca_admin_cert.p12 ${SHARED}/ca_admin_cert.p12
docker exec secondary pki nss-cert-import \
--cert $SHARED/ca_signing.crt \
--trust CT,C,C \
ca_signing
docker exec secondary pki pkcs12-import \
--pkcs12 ${SHARED}/ca_admin_cert.p12 \
--pkcs12-password Secret.123
docker exec secondary pki -n caadmin kra-user-show kraadmin
- name: Set up tertiary DS container
run: |
tests/bin/ds-create.sh \
--image=${{ env.DS_IMAGE }} \
--hostname=tertiaryds.example.com \
--password=Secret.123 \
tertiaryds
- name: Connect tertiary DS container to network
run: docker network connect example tertiaryds --alias tertiaryds.example.com
- name: Set up tertiary PKI container
run: |
tests/bin/runner-init.sh tertiary
env:
HOSTNAME: tertiary.example.com
- name: Connect tertiary PKI container to network
run: docker network connect example tertiary --alias tertiary.example.com
- name: Install dependencies in tertiary PKI container
run: |
docker exec tertiary dnf install -y softhsm
- name: Copy keys to tertiary PKI container
run: |
# allow PKI user to access SoftHSM files
docker exec tertiary usermod pkiuser -a -G ods
docker cp tokens/. tertiary:/var/lib/softhsm/tokens
docker exec tertiary chown -R pkiuser:pkiuser /var/lib/softhsm/tokens
docker exec tertiary ls -laR /var/lib/softhsm/tokens
docker exec tertiary runuser -u pkiuser -- \
softhsm2-util --show-slots
- name: Install CA in tertiary PKI container
run: |
# export CA signing CSR
docker exec secondary pki-server cert-export ca_signing \
--csr-file ${SHARED}/ca_signing.csr
# export CA OCSP signing CSR
docker exec secondary pki-server cert-export ca_ocsp_signing \
--csr-file ${SHARED}/ca_ocsp_signing.csr
# export CA audit signing CSR
docker exec secondary pki-server cert-export ca_audit_signing \
--csr-file ${SHARED}/ca_audit_signing.csr
# export subsystem CSR
docker exec secondary pki-server cert-export subsystem \
--csr-file ${SHARED}/subsystem.csr
docker exec tertiary pkispawn \
-f /usr/share/pki/server/examples/installation/ca-clone-of-clone.cfg \
-s CA \
-D pki_cert_chain_path=${SHARED}/ca_signing.crt \
-D pki_ds_url=ldap://tertiaryds.example.com:3389 \
-D pki_hsm_enable=True \
-D pki_token_name=HSM \
-D pki_token_password=Secret.HSM \
-D pki_ca_signing_token=HSM \
-D pki_ca_signing_csr_path=${SHARED}/ca_signing.csr \
-D pki_ocsp_signing_token=HSM \
-D pki_ocsp_signing_csr_path=${SHARED}/ca_ocsp_signing.csr \
-D pki_audit_signing_token=HSM \
-D pki_audit_signing_csr_path=${SHARED}/ca_audit_signing.csr \
-D pki_subsystem_token=HSM \
-D pki_subsystem_csr_path=${SHARED}/subsystem.csr \
-D pki_sslserver_token=internal \
-v
- name: Install KRA in tertiary PKI container
run: |
# export KRA storage CSR
docker exec secondary pki-server cert-export kra_storage \
--csr-file ${SHARED}/kra_storage.csr
# export KRA transport CSR
docker exec secondary pki-server cert-export kra_transport \
--csr-file ${SHARED}/kra_transport.csr
# export KRA audit signing CSR
docker exec secondary pki-server cert-export kra_audit_signing \
--csr-file ${SHARED}/kra_audit_signing.csr
# export subsystem CSR
docker exec secondary pki-server cert-export subsystem \
--csr-file ${SHARED}/subsystem.csr
docker exec tertiary pkispawn \
-f /usr/share/pki/server/examples/installation/kra-clone-of-clone.cfg \
-s KRA \
-D pki_cert_chain_path=${SHARED}/ca_signing.crt \
-D pki_ds_url=ldap://tertiaryds.example.com:3389 \
-D pki_hsm_enable=True \
-D pki_token_name=HSM \
-D pki_token_password=Secret.HSM \
-D pki_server_database_password=Secret.123 \
-D pki_storage_token=HSM \
-D pki_storage_csr_path=${SHARED}/kra_storage.csr \
-D pki_transport_token=HSM \
-D pki_transport_csr_path=${SHARED}/kra_transport.csr \
-D pki_audit_signing_token=HSM \
-D pki_audit_signing_csr_path=${SHARED}/kra_audit_signing.csr \
-D pki_subsystem_token=HSM \
-D pki_subsystem_csr_path=${SHARED}/subsystem.csr \
-D pki_sslserver_token=internal \
-v
- name: Check system certs in internal token
run: |
# there should be 4 certs
# NOTE: ideally it should match the
# primary CA, but it works fine as is
# TODO: investigate the discrepancy
echo "4" > expected
docker exec tertiary pki \
-d /var/lib/pki/pki-tomcat/conf/alias \
nss-cert-find | tee output
grep "Serial Number:" output | wc -l > actual
diff expected actual
- name: Check system certs in HSM
run: |
# there should be 7 certs
echo "7" > expected
docker exec tertiary pki \
-d /var/lib/pki/pki-tomcat/conf/alias \
-f /var/lib/pki/pki-tomcat/conf/password.conf \
--token HSM \
nss-cert-find | tee output
grep "Serial Number:" output | wc -l > actual
diff expected actual
- name: Check CS.cfg in secondary KRA after cloning
run: |
# get CS.cfg from secondary KRA after cloning
docker cp secondary:/var/lib/pki/pki-tomcat/conf/kra/CS.cfg CS.cfg.secondary.after
# normalize expected result:
# - remove params that cannot be compared
sed -e '/^dbs.beginReplicaNumber=/d' \
-e '/^dbs.endReplicaNumber=/d' \
-e '/^dbs.nextBeginReplicaNumber=/d' \
-e '/^dbs.nextEndReplicaNumber=/d' \
CS.cfg.secondary \
| sort > expected
# normalize actual result:
# - remove params that cannot be compared
sed -e '/^dbs.beginReplicaNumber=/d' \
-e '/^dbs.endReplicaNumber=/d' \
-e '/^dbs.nextBeginReplicaNumber=/d' \
-e '/^dbs.nextEndReplicaNumber=/d' \
CS.cfg.secondary.after \
| sort > actual
diff expected actual
- name: Check CS.cfg in tertiary KRA
run: |
# get CS.cfg from tertiary KRA
docker cp tertiary:/var/lib/pki/pki-tomcat/conf/kra/CS.cfg CS.cfg.tertiary
# normalize expected result:
# - remove params that cannot be compared
# - replace secondary.example.com with tertiary.example.com
# - replace secondaryds.example.com with tertiaryds.example.com
# - set securitydomain.host to secondary.example.com
sed -e '/^installDate=/d' \
-e '/^dbs.beginReplicaNumber=/d' \
-e '/^dbs.endReplicaNumber=/d' \
-e '/^dbs.nextBeginReplicaNumber=/d' \
-e '/^dbs.nextEndReplicaNumber=/d' \
-e '/^kra.sslserver.cert=/d' \
-e '/^kra.sslserver.certreq=/d' \
-e 's/secondary.example.com/tertiary.example.com/' \
-e 's/secondaryds.example.com/tertiaryds.example.com/' \
-e 's/^\(securitydomain.host\)=.*$/\1=secondary.example.com/' \
CS.cfg.secondary.after \
| sort > expected
# normalize actual result:
# - remove params that cannot be compared
sed -e '/^installDate=/d' \
-e '/^dbs.beginReplicaNumber=/d' \
-e '/^dbs.endReplicaNumber=/d' \
-e '/^dbs.nextBeginReplicaNumber=/d' \
-e '/^dbs.nextEndReplicaNumber=/d' \
-e '/^kra.sslserver.cert=/d' \
-e '/^kra.sslserver.certreq=/d' \
CS.cfg.tertiary \
| sort > actual
diff expected actual
- name: Check KRA admin in tertiary PKI container
run: |
docker exec tertiary pki nss-cert-import \
--cert $SHARED/ca_signing.crt \
--trust CT,C,C \
ca_signing
docker exec tertiary pki pkcs12-import \
--pkcs12 ${SHARED}/ca_admin_cert.p12 \
--pkcs12-password Secret.123
docker exec tertiary pki -n caadmin kra-user-show kraadmin
- name: Run PKI healthcheck in primary container
run: docker exec primary pki-healthcheck --failures-only
- name: Run PKI healthcheck in secondary container
run: docker exec secondary pki-healthcheck --failures-only
- name: Run PKI healthcheck in tertiary container
run: docker exec tertiary pki-healthcheck --failures-only
- name: Remove KRA from tertiary PKI container
run: docker exec tertiary pkidestroy -s KRA -v
- name: Remove CA from tertiary PKI container
run: docker exec tertiary pkidestroy -s CA -v
- name: Remove KRA from secondary PKI container
run: docker exec secondary pkidestroy -s KRA -v
- name: Remove CA from secondary PKI container
run: docker exec secondary pkidestroy -s CA -v
- name: Remove KRA from primary PKI container
run: docker exec primary pkidestroy -s KRA -v
- name: Remove CA from primary PKI container
run: docker exec primary pkidestroy -s CA -v
- name: Check PKI server systemd journal in primary container
if: always()
run: |
docker exec primary journalctl -x --no-pager -u [email protected]
- name: Check primary CA debug log
if: always()
run: |
docker exec primary find /var/lib/pki/pki-tomcat/logs/ca -name "debug.*" -exec cat {} \;
- name: Check primary KRA debug log
if: always()
run: |
docker exec primary find /var/lib/pki/pki-tomcat/logs/kra -name "debug.*" -exec cat {} \;
- name: Check PKI server systemd journal in secondary container
if: always()
run: |
docker exec secondary journalctl -x --no-pager -u [email protected]
- name: Check secondary CA debug log
if: always()
run: |
docker exec secondary find /var/lib/pki/pki-tomcat/logs/ca -name "debug.*" -exec cat {} \;
- name: Check secondary KRA debug log
if: always()
run: |
docker exec secondary find /var/lib/pki/pki-tomcat/logs/kra -name "debug.*" -exec cat {} \;
- name: Check PKI server systemd journal in tertiary container
if: always()
run: |
docker exec tertiary journalctl -x --no-pager -u [email protected]
- name: Check tertiary CA debug log
if: always()
run: |
docker exec tertiary find /var/lib/pki/pki-tomcat/logs/ca -name "debug.*" -exec cat {} \;
- name: Check tertiary KRA debug log
if: always()
run: |
docker exec tertiary find /var/lib/pki/pki-tomcat/logs/kra -name "debug.*" -exec cat {} \;
- name: Gather artifacts
if: always()
run: |
tests/bin/ds-artifacts-save.sh primaryds
tests/bin/pki-artifacts-save.sh primary
tests/bin/ds-artifacts-save.sh secondaryds
tests/bin/pki-artifacts-save.sh secondary
tests/bin/ds-artifacts-save.sh tertiaryds
tests/bin/pki-artifacts-save.sh tertiary
continue-on-error: true
- name: Upload artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: kra-clone-hsm
path: /tmp/artifacts