/
Dockerfile
328 lines (246 loc) · 9.41 KB
/
Dockerfile
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
#
# Copyright Red Hat, Inc.
#
# SPDX-License-Identifier: GPL-2.0-or-later
#
# https://docs.fedoraproject.org/en-US/containers/guidelines/guidelines/
ARG VENDOR="Dogtag"
ARG MAINTAINER="Dogtag PKI Team <devel@lists.dogtagpki.org>"
ARG COMPONENT="dogtag-pki"
ARG LICENSE="GPLv2 and LGPLv2"
ARG ARCH="x86_64"
ARG VERSION="0"
ARG BASE_IMAGE="registry.fedoraproject.org/fedora:latest"
ARG COPR_REPO=""
ARG BUILD_OPTS=""
################################################################################
FROM $BASE_IMAGE AS pki-base
RUN dnf install -y dnf-plugins-core systemd \
&& dnf clean all \
&& rm -rf /var/cache/dnf
CMD [ "/usr/sbin/init" ]
################################################################################
FROM pki-base AS pki-deps
ARG COPR_REPO
# Enable COPR repo if specified
RUN if [ -n "$COPR_REPO" ]; then dnf copr enable -y $COPR_REPO; fi
# Install PKI runtime dependencies
RUN dnf install -y dogtag-pki \
&& rpm -e --nodeps $(rpm -qa | grep -E "^java-|^dogtag-|^python3-dogtag-") \
&& dnf clean all \
&& rm -rf /var/cache/dnf
################################################################################
FROM pki-deps AS pki-builder-deps
# Install build tools
RUN dnf install -y rpm-build
# Import PKI sources
COPY pki.spec /root/pki/
WORKDIR /root/pki
# Install PKI build dependencies
RUN dnf builddep -y --skip-unavailable --spec pki.spec
################################################################################
FROM pki-builder-deps AS pki-builder
ARG BUILD_OPTS
# Import JSS packages
COPY --from=quay.io/dogtagpki/jss-dist:latest /root/RPMS /tmp/RPMS/
# Import LDAP SDK packages
COPY --from=quay.io/dogtagpki/ldapjdk-dist:latest /root/RPMS /tmp/RPMS/
# Install build dependencies
RUN dnf localinstall -y /tmp/RPMS/* \
&& dnf clean all \
&& rm -rf /var/cache/dnf \
&& rm -rf /tmp/RPMS
# Import PKI sources
COPY . /root/pki/
# Build PKI packages
RUN ./build.sh --work-dir=build $BUILD_OPTS rpm
################################################################################
FROM alpine:latest AS pki-dist
# Import PKI packages
COPY --from=pki-builder /root/pki/build/SRPMS /root/SRPMS/
COPY --from=pki-builder /root/pki/build/RPMS /root/RPMS/
################################################################################
FROM pki-deps AS pki-runner
# Import JSS packages
COPY --from=quay.io/dogtagpki/jss-dist:latest /root/RPMS /tmp/RPMS/
# Import LDAP SDK packages
COPY --from=quay.io/dogtagpki/ldapjdk-dist:latest /root/RPMS /tmp/RPMS/
# Import PKI packages
COPY --from=pki-dist /root/RPMS /tmp/RPMS/
# Install runtime packages
RUN dnf localinstall -y /tmp/RPMS/* \
&& dnf clean all \
&& rm -rf /var/cache/dnf \
&& rm -rf /tmp/RPMS
################################################################################
FROM pki-runner AS pki-server
ARG SUMMARY="Dogtag PKI Server"
LABEL name="pki-server" \
summary="$SUMMARY" \
license="$LICENSE" \
version="$VERSION" \
architecture="$ARCH" \
maintainer="$MAINTAINER" \
vendor="$VENDOR" \
usage="podman run -p 8080:8080 -p 8443:8443 pki-server" \
com.redhat.component="$COMPONENT"
EXPOSE 8080 8443
# In OpenShift the server runs as an OpenShift-assigned user
# (with a random UID) that belongs to the root group (GID=0),
# so the server instance needs to be owned by the root group.
#
# https://www.redhat.com/en/blog/jupyter-on-openshift-part-6-running-as-an-assigned-user-id
# Create PKI server
RUN pki-server create \
--group root \
--conf /data/conf \
--logs /data/logs
# In Docker/Podman the server runs as pkiuser (UID=17). To
# ensure it generates files with the proper ownership the
# pkiuser's primary group needs to be changed to the root
# group (GID=0).
# Change pkiuser's primary group to root group
RUN usermod pkiuser -g root
# Create NSS database
RUN pki-server nss-create --no-password
# Enable JSS
RUN pki-server jss-enable
# Configure SSL connector
RUN pki-server http-connector-add \
--port 8443 \
--scheme https \
--secure true \
--sslEnabled true \
--sslProtocol SSL \
--sslImpl org.dogtagpki.jss.tomcat.JSSImplementation \
Secure
# Configure SSL server certificate
RUN pki-server http-connector-cert-add \
--keyAlias sslserver \
--keystoreType pkcs11 \
--keystoreProvider Mozilla-JSS
# Grant the root group the full access to PKI server files
# https://www.openshift.com/blog/jupyter-on-openshift-part-6-running-as-an-assigned-user-id
RUN chgrp -Rf root /var/lib/pki/pki-tomcat
RUN chmod -Rf g+rw /var/lib/pki/pki-tomcat
VOLUME [ "/certs", "/data" ]
CMD [ "/usr/share/pki/server/bin/pki-server-run" ]
################################################################################
FROM pki-server AS pki-ca
ARG SUMMARY="Dogtag PKI Certificate Authority"
LABEL name="pki-ca" \
summary="$SUMMARY" \
license="$LICENSE" \
version="$VERSION" \
architecture="$ARCH" \
maintainer="$MAINTAINER" \
vendor="$VENDOR" \
usage="podman run -p 8080:8080 -p 8443:8443 pki-ca" \
com.redhat.component="$COMPONENT"
# Create CA subsystem
RUN pki-server ca-create
# Deploy CA subsystem
RUN pki-server ca-deploy
# Store default config files
RUN mv /data/conf /var/lib/pki/pki-tomcat/conf.default
# Grant the root group the full access to PKI server files
# https://www.openshift.com/blog/jupyter-on-openshift-part-6-running-as-an-assigned-user-id
RUN chgrp -Rf root /var/lib/pki/pki-tomcat
RUN chmod -Rf g+rw /var/lib/pki/pki-tomcat
CMD [ "/usr/share/pki/ca/bin/pki-ca-run" ]
################################################################################
FROM pki-server AS pki-kra
ARG SUMMARY="Dogtag PKI Key Recovery Authority"
LABEL name="pki-kra" \
summary="$SUMMARY" \
license="$LICENSE" \
version="$VERSION" \
architecture="$ARCH" \
maintainer="$MAINTAINER" \
vendor="$VENDOR" \
usage="podman run -p 8080:8080 -p 8443:8443 pki-kra" \
com.redhat.component="$COMPONENT"
# Create KRA subsystem
RUN pki-server kra-create
# Deploy KRA subsystem
RUN pki-server kra-deploy
# Store default config files
RUN mv /data/conf /var/lib/pki/pki-tomcat/conf.default
# Grant the root group the full access to PKI server files
# https://www.openshift.com/blog/jupyter-on-openshift-part-6-running-as-an-assigned-user-id
RUN chgrp -Rf root /var/lib/pki/pki-tomcat
RUN chmod -Rf g+rw /var/lib/pki/pki-tomcat
CMD [ "/usr/share/pki/kra/bin/pki-kra-run" ]
################################################################################
FROM pki-server AS pki-ocsp
ARG SUMMARY="Dogtag PKI OCSP Responder"
LABEL name="pki-ocsp" \
summary="$SUMMARY" \
license="$LICENSE" \
version="$VERSION" \
architecture="$ARCH" \
maintainer="$MAINTAINER" \
vendor="$VENDOR" \
usage="podman run -p 8080:8080 -p 8443:8443 pki-ocsp" \
com.redhat.component="$COMPONENT"
# Create OCSP subsystem
RUN pki-server ocsp-create
# Deploy OCSP subsystem
RUN pki-server ocsp-deploy
# Store default config files
RUN mv /data/conf /var/lib/pki/pki-tomcat/conf.default
# Grant the root group the full access to PKI server files
# https://www.openshift.com/blog/jupyter-on-openshift-part-6-running-as-an-assigned-user-id
RUN chgrp -Rf root /var/lib/pki/pki-tomcat
RUN chmod -Rf g+rw /var/lib/pki/pki-tomcat
CMD [ "/usr/share/pki/ocsp/bin/pki-ocsp-run" ]
################################################################################
FROM pki-server AS pki-acme
ARG SUMMARY="Dogtag PKI ACME Responder"
LABEL name="pki-acme" \
summary="$SUMMARY" \
license="$LICENSE" \
version="$VERSION" \
architecture="$ARCH" \
maintainer="$MAINTAINER" \
vendor="$VENDOR" \
usage="podman run -p 8080:8080 -p 8443:8443 pki-acme" \
com.redhat.component="$COMPONENT"
# Install PKI dependencies
RUN dnf install -y bind-utils iputils abrt-java-connector postgresql postgresql-jdbc
# Install PostgreSQL JDBC driver
RUN ln -s /usr/share/java/postgresql-jdbc/postgresql.jar /usr/share/pki/server/common/lib/postgresql.jar
# Create PKI ACME application
RUN pki-server acme-create
# Use in-memory database by default
RUN cp /usr/share/pki/acme/database/in-memory/database.conf /var/lib/pki/pki-tomcat/conf/acme
# Use NSS issuer by default
RUN cp /usr/share/pki/acme/issuer/nss/issuer.conf /var/lib/pki/pki-tomcat/conf/acme
# Use in-memory realm by default
RUN cp /usr/share/pki/acme/realm/in-memory/realm.conf /var/lib/pki/pki-tomcat/conf/acme
# Remove PKI ACME web application logging.properties so the logs will appear on the console
RUN rm -f /usr/share/pki/acme/webapps/acme/WEB-INF/classes/logging.properties
# Deploy PKI ACME application
RUN pki-server acme-deploy
# Store default config files
RUN mv /data/conf /var/lib/pki/pki-tomcat/conf.default
# Grant the root group the full access to PKI ACME files
# https://www.openshift.com/blog/jupyter-on-openshift-part-6-running-as-an-assigned-user-id
RUN chgrp -Rf root /var/lib/pki/pki-tomcat
RUN chmod -Rf g+rw /var/lib/pki/pki-tomcat
VOLUME [ \
"/certs", \
"/metadata", \
"/database", \
"/issuer", \
"/realm", \
"/data" ]
CMD [ "/usr/share/pki/acme/bin/pki-acme-run" ]
################################################################################
FROM pki-runner AS ipa-runner
# Install IPA packages
RUN dnf copr enable -y @freeipa/freeipa-master-nightly \
&& dnf install -y freeipa-server freeipa-server-dns freeipa-healthcheck freeipa-client \
python3-ipatests certbot \
&& dnf clean all \
&& rm -rf /var/cache/dnf