-
Notifications
You must be signed in to change notification settings - Fork 139
697 lines (616 loc) · 22.5 KB
/
ca-container-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
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
name: CA container
on: workflow_call
env:
DB_IMAGE: ${{ vars.DB_IMAGE || 'quay.io/389ds/dirsrv' }}
jobs:
# https://github.com/dogtagpki/pki/wiki/Deploying-CA-Container
test:
name: Test
runs-on: ubuntu-latest
env:
SHARED: /tmp/workdir/pki
steps:
- name: Clone repository
uses: actions/checkout@v3
- name: Retrieve PKI images
uses: actions/cache@v3
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 client container
run: |
tests/bin/runner-init.sh client
env:
HOSTNAME: client.example.com
- name: Connect client container to network
run: docker network connect example client --alias client.example.com
- name: Create CA signing cert
run: |
docker exec client pki \
nss-cert-request \
--subject "CN=CA Signing Certificate" \
--ext /usr/share/pki/server/certs/ca_signing.conf \
--csr ca_signing.csr
docker exec client pki \
nss-cert-issue \
--csr ca_signing.csr \
--ext /usr/share/pki/server/certs/ca_signing.conf \
--validity-length 1 \
--validity-unit year \
--cert ca_signing.crt
docker exec client pki \
nss-cert-import \
--cert ca_signing.crt \
--trust CT,C,C \
ca_signing
docker exec client pki \
nss-cert-show \
ca_signing
- name: Create OCSP signing cert
run: |
docker exec client pki \
nss-cert-request \
--subject "CN=OCSP Signing Certificate" \
--ext /usr/share/pki/server/certs/ocsp_signing.conf \
--csr ocsp_signing.csr
docker exec client pki \
nss-cert-issue \
--issuer ca_signing \
--csr ocsp_signing.csr \
--ext /usr/share/pki/server/certs/ocsp_signing.conf \
--cert ocsp_signing.crt
docker exec client pki \
nss-cert-import \
--cert ocsp_signing.crt \
ocsp_signing
docker exec client pki \
nss-cert-show \
ocsp_signing
- name: Create audit signing cert
run: |
docker exec client pki \
nss-cert-request \
--subject "CN=Audit Signing Certificate" \
--ext /usr/share/pki/server/certs/audit_signing.conf \
--csr audit_signing.csr
docker exec client pki \
nss-cert-issue \
--issuer ca_signing \
--csr audit_signing.csr \
--ext /usr/share/pki/server/certs/audit_signing.conf \
--cert audit_signing.crt
docker exec client pki \
nss-cert-import \
--cert audit_signing.crt \
--trust ,,P \
audit_signing
docker exec client pki \
nss-cert-show \
audit_signing
- name: Create subsystem cert
run: |
docker exec client pki \
nss-cert-request \
--subject "CN=Subsystem Certificate" \
--ext /usr/share/pki/server/certs/subsystem.conf \
--csr subsystem.csr
docker exec client pki \
nss-cert-issue \
--issuer ca_signing \
--csr subsystem.csr \
--ext /usr/share/pki/server/certs/subsystem.conf \
--cert subsystem.crt
docker exec client pki \
nss-cert-import \
--cert subsystem.crt \
subsystem
docker exec client pki \
nss-cert-show \
subsystem
- name: Create SSL server cert
run: |
docker exec client pki \
nss-cert-request \
--subject "CN=ca.example.com" \
--ext /usr/share/pki/server/certs/sslserver.conf \
--csr sslserver.csr
docker exec client pki \
nss-cert-issue \
--issuer ca_signing \
--csr sslserver.csr \
--ext /usr/share/pki/server/certs/sslserver.conf \
--cert sslserver.crt
docker exec client pki \
nss-cert-import \
--cert sslserver.crt \
sslserver
docker exec client pki \
nss-cert-show \
sslserver
- name: Create admin cert
run: |
docker exec client pki \
nss-cert-request \
--subject "CN=Administrator" \
--ext /usr/share/pki/server/certs/admin.conf \
--csr admin.csr
docker exec client pki \
nss-cert-issue \
--issuer ca_signing \
--csr admin.csr \
--ext /usr/share/pki/server/certs/admin.conf \
--cert admin.crt
docker exec client pki \
nss-cert-import \
--cert admin.crt \
admin
docker exec client pki \
nss-cert-show \
admin
- name: Export system certs and keys
run: |
docker exec client pki \
pkcs12-export \
--pkcs12 server.p12 \
--password Secret.123 \
ca_signing \
ocsp_signing \
audit_signing \
subsystem \
sslserver
- name: Export admin cert and key
run: |
docker exec client pki \
pkcs12-export \
--pkcs12 admin.p12 \
--password Secret.123 \
admin
- name: Set up CA container
run: |
mkdir certs
docker cp client:server.p12 certs
docker cp client:admin.p12 certs
docker cp client:ca_signing.csr certs
docker cp client:ocsp_signing.csr certs
docker cp client:audit_signing.csr certs
docker cp client:subsystem.csr certs
docker cp client:sslserver.csr certs
docker cp client:admin.csr certs
ls -la certs
docker run \
--name ca \
--hostname=ca.example.com \
--network=example \
--network-alias=ca.example.com \
-v $PWD/certs:/certs \
--detach \
pki-ca
- name: Wait for CA container to start
run: |
docker exec client curl \
--retry 180 \
--retry-delay 0 \
--retry-connrefused \
-s \
-k \
-o /dev/null \
https://ca.example.com:8443
- name: Check basic operations from CA container
run: |
# check PKI server info
docker exec ca pki info
- name: Check basic operations from client container
run: |
# check PKI server info
docker exec client pki \
-U https://ca.example.com:8443 \
info
- name: Set up DS container
run: |
tests/bin/ds-container-create.sh ds
env:
IMAGE: ${{ env.DB_IMAGE }}
HOSTNAME: ds.example.com
PASSWORD: Secret.123
- name: Connect DS container to network
run: docker network connect example ds --alias ds.example.com
# https://github.com/dogtagpki/pki/wiki/Setting-up-CA-Database
- name: Configure DS database
run: |
docker exec ds ldapadd \
-H ldap://ds.example.com:3389 \
-D "cn=Directory Manager" \
-w Secret.123 \
-f $SHARED/base/server/database/ds/config.ldif
- name: Add PKI schema
run: |
docker exec ds ldapmodify \
-H ldap://ds.example.com:3389 \
-D "cn=Directory Manager" \
-w Secret.123 \
-f $SHARED/base/server/database/ds/schema.ldif
- name: Add CA base entry
run: |
docker exec -i ds ldapadd \
-H ldap://ds.example.com:3389 \
-D "cn=Directory Manager" \
-w Secret.123 << EOF
dn: dc=ca,dc=pki,dc=example,dc=com
objectClass: dcObject
dc: ca
EOF
- name: Add CA database entries
run: |
sed \
-e 's/{rootSuffix}/dc=ca,dc=pki,dc=example,dc=com/g' \
base/ca/database/ds/create.ldif \
| tee create.ldif
docker exec ds ldapadd \
-H ldap://ds.example.com:3389 \
-D "cn=Directory Manager" \
-w Secret.123 \
-f $SHARED/create.ldif
- name: Add CA ACL resources
run: |
sed \
-e 's/{rootSuffix}/dc=ca,dc=pki,dc=example,dc=com/g' \
base/ca/database/ds/acl.ldif \
| tee acl.ldif
docker exec ds ldapadd \
-H ldap://ds.example.com:3389 \
-D "cn=Directory Manager" \
-w Secret.123 \
-f $SHARED/acl.ldif
- name: Add CA search indexes
run: |
sed \
-e 's/{database}/userroot/g' \
base/ca/database/ds/index.ldif \
| tee index.ldif
docker exec ds ldapadd \
-H ldap://ds.example.com:3389 \
-D "cn=Directory Manager" \
-w Secret.123 \
-f $SHARED/index.ldif
- name: Rebuild CA search indexes
run: |
# start rebuild task
sed \
-e 's/{database}/userroot/g' \
base/ca/database/ds/indextasks.ldif \
| tee indextasks.ldif
docker exec ds ldapadd \
-H ldap://ds.example.com:3389 \
-D "cn=Directory Manager" \
-w Secret.123 \
-f $SHARED/indextasks.ldif
# wait for task to complete
while true; do
sleep 1
docker exec ds ldapsearch \
-H ldap://ds.example.com:3389 \
-D "cn=Directory Manager" \
-w Secret.123 \
-b "cn=index1160589770, cn=index, cn=tasks, cn=config" \
-LLL \
nsTaskExitCode \
| tee output
sed -n -e 's/nsTaskExitCode:\s*\(.*\)/\1/p' output > nsTaskExitCode
cat nsTaskExitCode
if [ -s nsTaskExitCode ]; then
break
fi
done
echo "0" > expected
diff expected nsTaskExitCode
- name: Add CA VLV indexes
run: |
sed \
-e 's/{instanceId}/pki-tomcat/g' \
-e 's/{database}/userroot/g' \
-e 's/{rootSuffix}/dc=ca,dc=pki,dc=example,dc=com/g' \
base/ca/database/ds/vlv.ldif \
| tee vlv.ldif
docker exec ds ldapadd \
-H ldap://ds.example.com:3389 \
-D "cn=Directory Manager" \
-w Secret.123 \
-f $SHARED/vlv.ldif
- name: Rebuild CA VLV indexes
run: |
# start rebuild task
sed \
-e 's/{database}/userroot/g' \
-e 's/{instanceId}/pki-tomcat/g' \
base/ca/database/ds/vlvtasks.ldif \
| tee vlvtasks.ldif
docker exec ds ldapadd \
-H ldap://ds.example.com:3389 \
-D "cn=Directory Manager" \
-w Secret.123 \
-f $SHARED/vlvtasks.ldif
# wait for task to complete
while true; do
sleep 1
docker exec ds ldapsearch \
-H ldap://ds.example.com:3389 \
-D "cn=Directory Manager" \
-w Secret.123 \
-b "cn=index1160589769, cn=index, cn=tasks, cn=config" \
-LLL \
nsTaskExitCode \
| tee output
sed -n -e 's/nsTaskExitCode:\s*\(.*\)/\1/p' output > nsTaskExitCode
cat nsTaskExitCode
if [ -s nsTaskExitCode ]; then
break
fi
done
echo "0" > expected
diff expected nsTaskExitCode
# https://github.com/dogtagpki/pki/wiki/Setting-up-CA-Admin-User
- name: Add admin user
run: |
docker exec -i ds ldapadd \
-H ldap://ds.example.com:3389 \
-D "cn=Directory Manager" \
-w Secret.123 << EOF
dn: uid=admin,ou=people,dc=ca,dc=pki,dc=example,dc=com
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
objectClass: cmsuser
cn: admin
sn: admin
uid: admin
mail: [email protected]
userPassword: Secret.123
userState: 1
userType: adminType
EOF
- name: Assign admin cert to admin user
run: |
# convert cert from PEM to DER
docker cp client:admin.crt admin.crt
openssl x509 -outform der -in admin.crt -out admin.der
docker cp admin.der ds:admin.der
# get serial number
openssl x509 -text -noout -in admin.crt | tee output
SERIAL=$(sed -En 'N; s/^ *Serial Number:\n *(.*)$/\1/p; D' output)
echo "SERIAL: $SERIAL"
HEX_SERIAL=$(echo "$SERIAL" | tr -d ':')
echo "HEX_SERIAL: $HEX_SERIAL"
DEC_SERIAL=$(python -c "print(int('$HEX_SERIAL', 16))")
echo "DEC_SERIAL: $DEC_SERIAL"
docker exec -i ds ldapmodify \
-H ldap://ds.example.com:3389 \
-D "cn=Directory Manager" \
-w Secret.123 << EOF
dn: uid=admin,ou=people,dc=ca,dc=pki,dc=example,dc=com
changetype: modify
add: description
description: 2;$DEC_SERIAL;CN=CA Signing Certificate;CN=Administrator
-
add: userCertificate
userCertificate:< file:admin.der
-
EOF
- name: Add admin user into CA groups
run: |
docker exec -i ds ldapmodify \
-H ldap://ds.example.com:3389 \
-D "cn=Directory Manager" \
-w Secret.123 << EOF
dn: cn=Administrators,ou=groups,dc=ca,dc=pki,dc=example,dc=com
changetype: modify
add: uniqueMember
uniqueMember: uid=admin,ou=people,dc=ca,dc=pki,dc=example,dc=com
-
dn: cn=Certificate Manager Agents,ou=groups,dc=ca,dc=pki,dc=example,dc=com
changetype: modify
add: uniqueMember
uniqueMember: uid=admin,ou=people,dc=ca,dc=pki,dc=example,dc=com
-
dn: cn=Security Domain Administrators,ou=groups,dc=ca,dc=pki,dc=example,dc=com
changetype: modify
add: uniqueMember
uniqueMember: uid=admin,ou=people,dc=ca,dc=pki,dc=example,dc=com
-
dn: cn=Enterprise CA Administrators,ou=groups,dc=ca,dc=pki,dc=example,dc=com
changetype: modify
add: uniqueMember
uniqueMember: uid=admin,ou=people,dc=ca,dc=pki,dc=example,dc=com
-
dn: cn=Enterprise KRA Administrators,ou=groups,dc=ca,dc=pki,dc=example,dc=com
changetype: modify
add: uniqueMember
uniqueMember: uid=admin,ou=people,dc=ca,dc=pki,dc=example,dc=com
-
dn: cn=Enterprise RA Administrators,ou=groups,dc=ca,dc=pki,dc=example,dc=com
changetype: modify
add: uniqueMember
uniqueMember: uid=admin,ou=people,dc=ca,dc=pki,dc=example,dc=com
-
dn: cn=Enterprise TKS Administrators,ou=groups,dc=ca,dc=pki,dc=example,dc=com
changetype: modify
add: uniqueMember
uniqueMember: uid=admin,ou=people,dc=ca,dc=pki,dc=example,dc=com
-
dn: cn=Enterprise OCSP Administrators,ou=groups,dc=ca,dc=pki,dc=example,dc=com
changetype: modify
add: uniqueMember
uniqueMember: uid=admin,ou=people,dc=ca,dc=pki,dc=example,dc=com
-
dn: cn=Enterprise TPS Administrators,ou=groups,dc=ca,dc=pki,dc=example,dc=com
changetype: modify
add: uniqueMember
uniqueMember: uid=admin,ou=people,dc=ca,dc=pki,dc=example,dc=com
-
EOF
# https://github.com/dogtagpki/pki/wiki/Setting-up-CA-Database-User
- name: Add database user
run: |
docker exec -i ds ldapadd \
-H ldap://ds.example.com:3389 \
-D "cn=Directory Manager" \
-w Secret.123 << EOF
dn: uid=pkidbuser,ou=people,dc=ca,dc=pki,dc=example,dc=com
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
objectClass: cmsuser
cn: pkidbuser
sn: pkidbuser
uid: pkidbuser
userState: 1
userType: agentType
EOF
- name: Assign subsystem cert to database user
run: |
# convert cert from PEM to DER
docker cp client:subsystem.crt subsystem.crt
openssl x509 -outform der -in subsystem.crt -out subsystem.der
docker cp subsystem.der ds:subsystem.der
# get serial number
openssl x509 -text -noout -in subsystem.crt | tee output
SERIAL=$(sed -En 'N; s/^ *Serial Number:\n *(.*)$/\1/p; D' output)
echo "SERIAL: $SERIAL"
HEX_SERIAL=$(echo "$SERIAL" | tr -d ':')
echo "HEX_SERIAL: $HEX_SERIAL"
DEC_SERIAL=$(python -c "print(int('$HEX_SERIAL', 16))")
echo "DEC_SERIAL: $DEC_SERIAL"
docker exec -i ds ldapmodify \
-H ldap://ds.example.com:3389 \
-D "cn=Directory Manager" \
-w Secret.123 << EOF
dn: uid=pkidbuser,ou=people,dc=ca,dc=pki,dc=example,dc=com
changetype: modify
add: description
description: 2;$DEC_SERIAL;CN=CA Signing Certificate;CN=Subsystem Certificate
-
add: seeAlso
seeAlso: CN=Subsystem Certificate
-
add: userCertificate
userCertificate:< file:subsystem.der
-
EOF
- name: Add database user into CA groups
run: |
docker exec -i ds ldapmodify \
-H ldap://ds.example.com:3389 \
-D "cn=Directory Manager" \
-w Secret.123 << EOF
dn: cn=Subsystem Group,ou=groups,dc=ca,dc=pki,dc=example,dc=com
changetype: modify
add: uniqueMember
uniqueMember: uid=pkidbuser,ou=people,dc=ca,dc=pki,dc=example,dc=com
-
dn: cn=Certificate Manager Agents,ou=groups,dc=ca,dc=pki,dc=example,dc=com
changetype: modify
add: uniqueMember
uniqueMember: uid=pkidbuser,ou=people,dc=ca,dc=pki,dc=example,dc=com
-
EOF
- name: Grant database user access to CA database
run: |
sed \
-e 's/{rootSuffix}/dc=example,dc=com/g' \
-e 's/{dbuser}/uid=pkidbuser,ou=people,dc=ca,dc=pki,dc=example,dc=com/g' \
base/server/database/ds/db-access-grant.ldif \
| tee db-access-grant.ldif
docker exec ds ldapadd \
-H ldap://ds.example.com:3389 \
-D "cn=Directory Manager" \
-w Secret.123 \
-f $SHARED/db-access-grant.ldif \
-c
- name: Check public operations from CA container
run: |
# check certs in CA
docker exec ca pki ca-cert-find
- name: Check admin operations from CA container
run: |
# check admin user
docker exec ca pki \
-n admin \
ca-user-show \
admin
docker exec ca pki \
client-cert-request \
uid=testuser | tee output
REQUEST_ID=$(sed -n -e 's/^ *Request ID: *\(.*\)$/\1/p' output)
echo "REQUEST_ID: $REQUEST_ID"
docker exec ca pki \
-n admin \
ca-cert-request-approve \
$REQUEST_ID \
--force
- name: Check public operations from client container
run: |
# check certs in CA
docker exec client pki \
-U https://ca.example.com:8443 \
ca-cert-find
- name: Check admin operations from client container
run: |
# check admin user
docker exec client pki \
-U https://ca.example.com:8443 \
-n admin \
ca-user-show \
admin
docker exec client pki \
-U https://ca.example.com:8443 \
client-cert-request \
uid=testuser | tee output
REQUEST_ID=$(sed -n -e 's/^ *Request ID: *\(.*\)$/\1/p' output)
echo "REQUEST_ID: $REQUEST_ID"
docker exec client pki \
-U https://ca.example.com:8443 \
-n admin \
ca-cert-request-approve \
$REQUEST_ID \
--force
- name: Check CA container logs
if: always()
run: |
docker logs ca 2>&1
- name: Check CA debug logs
if: always()
run: |
docker exec ca bash -c "cat /var/log/pki/pki-tomcat/ca/debug.*"
- name: Gather artifacts from CA container
if: always()
run: |
tests/bin/ds-artifacts-save.sh --output=/tmp/artifacts/ca ds
docker exec ca ls -la /etc/pki
mkdir -p /tmp/artifacts/ca/etc/pki
docker cp ca:/etc/pki/pki.conf /tmp/artifacts/ca/etc/pki
docker cp ca:/etc/pki/pki-tomcat /tmp/artifacts/ca/etc/pki
docker exec ca ls -la /var/log/pki
mkdir -p /tmp/artifacts/ca/var/log
docker cp ca:/var/log/pki /tmp/artifacts/ca/var/log
docker logs ca > /tmp/artifacts/ca/container.out 2> /tmp/artifacts/ca/container.err
continue-on-error: true
- name: Gather artifacts from client container
if: always()
run: |
mkdir -p /tmp/artifacts/client
docker logs client > /tmp/artifacts/client/container.out 2> /tmp/artifacts/client/container.err
- name: Upload artifacts from CA container
if: always()
uses: actions/upload-artifact@v3
with:
name: ca-container-ca
path: /tmp/artifacts/ca
- name: Upload artifacts from client container
if: always()
uses: actions/upload-artifact@v3
with:
name: ca-container-client
path: /tmp/artifacts/client