-
Notifications
You must be signed in to change notification settings - Fork 139
377 lines (317 loc) · 11.6 KB
/
ca-container-basic-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
name: Basic CA container
on: workflow_call
env:
DS_IMAGE: ${{ vars.DS_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: Install dependencies
run: |
sudo apt-get update
# replace docker with podman
sudo apt-get -y purge --auto-remove docker-ce-cli
sudo apt-get -y install podman-docker
- 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: Create shared folders
run: |
mkdir certs
mkdir conf
mkdir logs
- name: Set up client container
run: |
tests/bin/runner-init.sh \
--hostname=client.example.com \
--network=example \
client
- name: Set up CA container
run: |
docker run \
--name ca \
--hostname ca.example.com \
--network example \
--network-alias ca.example.com \
-v $PWD/certs:/certs \
-v $PWD/conf:/conf \
-v $PWD/logs:/logs \
-e PKI_DS_URL=ldap://ds.example.com:3389 \
-e PKI_DS_PASSWORD=Secret.123 \
--detach \
pki-ca
# wait for CA to start
docker exec client curl \
--retry 180 \
--retry-delay 0 \
--retry-connrefused \
-s \
-k \
-o /dev/null \
https://ca.example.com:8443
- name: Check conf dir
if: always()
run: |
ls -l conf \
| sed \
-e '/^total/d' \
-e 's/^\(\S*\) *\S* *\S* *\(\S*\) *\S* *\S* *\S* *\S* *\(.*\)$/\1 \2 \3/' \
| tee output
# everything should be owned by docker group
# TODO: review owners/permissions
cat > expected << EOF
drwxrwxrwx docker Catalina
drwxrwxrwx docker alias
drwxrwxrwx docker ca
-rw-rw-rw- docker catalina.policy
lrwxrwxrwx docker catalina.properties -> /usr/share/pki/server/conf/catalina.properties
drwxrwxrwx docker certs
lrwxrwxrwx docker context.xml -> /etc/tomcat/context.xml
-rw-rw-rw- docker jss.conf
lrwxrwxrwx docker logging.properties -> /usr/share/pki/server/conf/logging.properties
-rw-rw-rw- docker password.conf
-rw-rw-rw- docker server.xml
-rw-rw-rw- docker serverCertNick.conf
-rw-rw-rw- docker tomcat.conf
lrwxrwxrwx docker web.xml -> /etc/tomcat/web.xml
EOF
diff expected output
- name: Check conf/ca dir
if: always()
run: |
ls -l conf/ca \
| sed \
-e '/^total/d' \
-e 's/^\(\S*\) *\S* *\S* *\(\S*\) *\S* *\S* *\S* *\S* *\(.*\)$/\1 \2 \3/' \
-e '/^\S* *\S* *\S* *CS.cfg.bak /d' \
| tee output
# everything should be owned by docker group
# TODO: review owners/permissions
cat > expected << EOF
-rw-rw-rw- docker CS.cfg
-rw-rw-rw- docker adminCert.profile
drwxrwxrwx docker archives
-rw-rw-rw- docker caAuditSigningCert.profile
-rw-rw-rw- docker caCert.profile
-rw-rw-rw- docker caOCSPCert.profile
drwxrwxrwx docker emails
-rw-rw-rw- docker flatfile.txt
drwxrwxrwx docker profiles
-rw-rw-rw- docker proxy.conf
-rw-rw-rw- docker registry.cfg
-rw-rw-rw- docker serverCert.profile
-rw-rw-rw- docker subsystemCert.profile
EOF
diff expected output
- name: Check logs dir
if: always()
run: |
ls -l logs \
| sed \
-e '/^total/d' \
-e 's/^\(\S*\) *\S* *\S* *\(\S*\) *\S* *\S* *\S* *\S* *\(.*\)$/\1 \2 \3/' \
| tee output
DATE=$(date +'%Y-%m-%d')
# everything should be owned by docker group
# TODO: review owners/permissions
cat > expected << EOF
drwxrwx--- docker backup
drwxrwxrwx docker ca
-rw-rw-rw- docker catalina.$DATE.log
-rw-rw-rw- docker host-manager.$DATE.log
-rw-rw-rw- docker localhost.$DATE.log
-rw-rw-rw- docker localhost_access_log.$DATE.txt
-rw-rw-rw- docker manager.$DATE.log
drwxrwxrwx docker pki
EOF
diff expected output
- name: Check CA info
run: |
docker exec ca pki-server cert-export \
--cert-file /conf/certs/ca_signing.crt \
ca_signing
docker exec client pki nss-cert-import \
--cert $SHARED/conf/certs/ca_signing.crt \
--trust CT,C,C \
ca_signing
docker exec client pki \
-U https://ca.example.com:8443 \
info
- name: Set up DS container
run: |
tests/bin/ds-create.sh \
--image=${{ env.DS_IMAGE }} \
--hostname=ds.example.com \
--network=example \
--network-alias=ds.example.com \
--password=Secret.123 \
ds
# https://github.com/dogtagpki/pki/wiki/Setting-up-CA-Database
- name: Initialize CA database
run: |
docker exec ca pki-server ca-db-init -v
docker exec ca pki-server ca-db-index-add -v
docker exec ca pki-server ca-db-index-rebuild -v
docker exec ca pki-server ca-db-vlv-add -v
docker exec ca pki-server ca-db-vlv-reindex -v
- name: Import CA signing cert into CA database
run: |
docker exec ca pki-server cert-export \
--cert-file /conf/certs/ca_signing.crt \
ca_signing
docker exec ca pki-server ca-cert-import \
--cert /conf/certs/ca_signing.crt \
--csr /conf/certs/ca_signing.csr \
--profile /usr/share/pki/ca/conf/caCert.profile
- name: Import CA OCSP signing cert into CA database
run: |
docker exec ca pki-server cert-export \
--cert-file /conf/certs/ca_ocsp_signing.crt \
ca_ocsp_signing
docker exec ca pki-server ca-cert-import \
--cert /conf/certs/ca_ocsp_signing.crt \
--csr /conf/certs/ca_ocsp_signing.csr \
--profile /usr/share/pki/ca/conf/caOCSPCert.profile
- name: Import subsystem cert into CA database
run: |
docker exec ca pki-server cert-export \
--cert-file /conf/certs/subsystem.crt \
subsystem
docker exec ca pki-server ca-cert-import \
--cert /conf/certs/subsystem.crt \
--csr /conf/certs/subsystem.csr \
--profile /usr/share/pki/ca/conf/rsaSubsystemCert.profile
- name: Import SSL server cert into CA database
run: |
docker exec ca pki-server cert-export \
--cert-file /conf/certs/sslserver.crt \
sslserver
docker exec ca pki-server ca-cert-import \
--cert /conf/certs/sslserver.crt \
--csr /conf/certs/sslserver.csr \
--profile /usr/share/pki/ca/conf/rsaServerCert.profile
- name: Create admin cert
run: |
# create cert request
docker exec client pki nss-cert-request \
--subject "CN=Administrator" \
--ext /usr/share/pki/server/certs/admin.conf \
--csr $SHARED/admin.csr
docker cp admin.csr ca:.
# issue cert
docker exec ca pki-server ca-cert-create \
--csr admin.csr \
--profile /usr/share/pki/ca/conf/rsaAdminCert.profile \
--cert admin.crt \
--import-cert
docker cp ca:admin.crt .
# import cert
docker exec client pki nss-cert-import \
--cert $SHARED/admin.crt \
admin
- name: Check certs in CA
run: |
docker exec client pki \
-U https://ca.example.com:8443 \
ca-cert-find
# https://github.com/dogtagpki/pki/wiki/Setting-up-CA-Admin-User
- name: Add CA admin user
run: |
# create CA admin user
docker exec ca pki-server ca-user-add \
--full-name Administrator \
--type adminType \
--cert admin.crt \
admin
# add CA admin user into CA groups
docker exec ca pki-server ca-user-role-add admin "Administrators"
docker exec ca pki-server ca-user-role-add admin "Certificate Manager Agents"
- name: Check CA admin user
run: |
docker exec client pki \
-U https://ca.example.com:8443 \
-n admin \
ca-user-show \
admin
- name: Check cert enrollment
run: |
# create cert request
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"
# issue cert
docker exec client pki \
-U https://ca.example.com:8443 \
-n admin \
ca-cert-request-approve \
$REQUEST_ID \
--force
- name: Restart CA
run: |
docker restart ca
sleep 10
docker network reload --all
# wait for CA to restart
docker exec client curl \
--retry 180 \
--retry-delay 0 \
--retry-connrefused \
-s \
-k \
-o /dev/null \
https://ca.example.com:8443
- name: Check CA admin user again
run: |
docker exec client pki \
-U https://ca.example.com:8443 \
-n admin \
ca-user-show \
admin
- name: Check DS server systemd journal
if: always()
run: |
docker exec ds journalctl -x --no-pager -u [email protected]
- name: Check DS container logs
if: always()
run: |
docker logs ds
- name: Check CA container logs
if: always()
run: |
docker logs ca 2>&1
- name: Check CA debug logs
if: always()
run: |
docker exec ca find /var/lib/pki/pki-tomcat/logs/ca -name "debug.*" -exec cat {} \;
- name: Gather artifacts
if: always()
run: |
tests/bin/ds-artifacts-save.sh ds
mkdir -p /tmp/artifacts/ca
cp -r certs /tmp/artifacts/ca
cp -r conf /tmp/artifacts/ca
cp -r logs /tmp/artifacts/ca
docker logs ca > /tmp/artifacts/ca/container.out 2> /tmp/artifacts/ca/container.err
mkdir -p /tmp/artifacts/client
docker logs client > /tmp/artifacts/client/container.out 2> /tmp/artifacts/client/container.err
- name: Upload artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: ca-container-basic
path: /tmp/artifacts