Skip to content

Commit 3bfa477

Browse files
committed
feat: use a container for creating the CA and server certificate
1 parent c9157fe commit 3bfa477

File tree

7 files changed

+46
-364
lines changed

7 files changed

+46
-364
lines changed

docs/source/DeveloperGuide/DevelopmentEnvironment/DeveloperInstallation/stuffThatRun.rst

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,9 @@ the private key. You will need two different sets certificates and the CA certif
9393
The following commands should do the trick for you, by creating a fake CA, a fake user certificate, and a fake host certificate::
9494

9595
cd $DEVROOT/DIRAC
96-
git checkout release/integration
97-
source tests/Jenkins/utilities.sh
98-
generateCA
99-
generateCertificates 365
100-
generateUserCredentials 365
96+
docker run ghcr.io/diracgrid/diracx/certificates-generation:latest
10197
mkdir -p ~/.globus/
102-
cp $DEVROOT/user/*.{pem,key} ~/.globus/
98+
docker cp certificates-generation:/ca/certs/client.{pem,key} ~/.globus/
10399
mv ~/.globus/client.key ~/.globus/userkey.pem
104100
mv ~/.globus/client.pem ~/.globus/usercert.pem
105101

tests/CI/docker-compose.yml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
volumes:
2+
# Volume used to store the certificates of dirac
3+
certs_data:
24
# Volume used to store the config of diracx
35
diracx-cs-store:
46
# Volume used to store the pair of keys to sign the tokens
@@ -111,6 +113,15 @@ services:
111113
/entrypoint.sh
112114
pull_policy: always
113115

116+
dirac-init-certificates:
117+
image: ghcr.io/diracgrid/management/certificates-generation:latest
118+
container_name: dirac-init-certificates
119+
volumes:
120+
- certs_data:/ca/certs/
121+
entrypoint: |
122+
/entrypoint.sh
123+
pull_policy: always
124+
114125
dirac-server:
115126
image: ${CI_REGISTRY_IMAGE}/${HOST_OS}-dirac
116127
container_name: server
@@ -126,21 +137,24 @@ services:
126137
condition: service_started
127138
iam-login-service:
128139
condition: service_healthy
140+
dirac-init-certificates:
141+
condition: service_completed_successfully # Let the init container create the certificates
129142
diracx-init-key:
130143
condition: service_completed_successfully # Let the init container create the signing key
131144
diracx-init-cs:
132145
condition: service_completed_successfully # Let the init container create the cs
133146
ulimits:
134147
nofile: 8192
135148
volumes:
149+
- certs_data:/ca/certs
136150
- diracx-cs-store:/cs_store
137151
- diracx-key-store:/signing-key
138152
- certs_data:/ca/certs
139153
environment:
140154
- DIRACX_CONFIG_BACKEND_URL=git+file:///cs_store/initialRepo
141155
- DIRACX_SERVICE_AUTH_TOKEN_KEY=file:///signing-key/rs256.key
142-
pull_policy: always
143156
command: ["sleep", "infinity"] # This is necessary because of the issue described in https://github.com/moby/moby/issues/42275. What is added here is a hack/workaround.
157+
pull_policy: always
144158

145159

146160
dirac-client:
@@ -154,8 +168,10 @@ services:
154168
- certs_data:/ca/certs
155169
ulimits:
156170
nofile: 8192
157-
pull_policy: always
171+
volumes:
172+
- certs_data:/ca/certs
158173
command: ["sleep", "infinity"] # This is necessary because of the issue described in https://github.com/moby/moby/issues/42275. What is added here is a hack/workaround.
174+
pull_policy: always
159175

160176
dirac-pilot:
161177
image: ${CI_REGISTRY_IMAGE}/${HOST_OS}-dirac
@@ -165,6 +181,7 @@ services:
165181
depends_on:
166182
- dirac-server
167183
volumes:
184+
- certs_data:/ca/certs
168185
- type: bind
169186
source: ${CVMFS_DIR}
170187
target: /cvmfs

tests/Jenkins/config/ci/openssl_config_ca.cnf

Lines changed: 0 additions & 110 deletions
This file was deleted.

tests/Jenkins/config/ci/openssl_config_host.cnf

Lines changed: 0 additions & 37 deletions
This file was deleted.

tests/Jenkins/config/ci/openssl_config_user.cnf

Lines changed: 0 additions & 20 deletions
This file was deleted.

tests/Jenkins/dirac_ci.sh

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,7 @@ source "${TESTCODE}/DIRAC/tests/Jenkins/utilities.sh"
9090
installSite() {
9191
echo "==> [installSite]"
9292

93-
generateCA
94-
generateCertificates
95-
96-
echo -n > "${SERVERINSTALLDIR}/dirac-ci-install.cfg"
93+
# echo -n > "${SERVERINSTALLDIR}/dirac-ci-install.cfg"
9794
getCFGFile
9895

9996
echo "==> Fixing install.cfg file"
@@ -127,7 +124,30 @@ installSite() {
127124
bash "installer.sh"
128125
rm "installer.sh"
129126
echo "source \"$PWD/diracos/diracosrc\"" > "$PWD/bashrc"
130-
mv "${SERVERINSTALLDIR}/etc/grid-security/"* "${SERVERINSTALLDIR}/diracos/etc/grid-security/"
127+
128+
mkdir -p "${SERVERINSTALLDIR}/diracos/etc/grid-security/certificates/"
129+
mkdir -p "${SERVERINSTALLDIR}/user/"
130+
131+
echo "==> CAs and certificates"
132+
133+
# Copy the CA to the list of trusted CA
134+
cp "/ca/certs/ca.cert.pem" "${SERVERINSTALLDIR}/diracos/etc/grid-security/certificates/"
135+
136+
# Copy the cert and host key to the certificates directory
137+
cp /ca/certs/hostcert.pem "${SERVERINSTALLDIR}/diracos/etc/grid-security/"
138+
cp /ca/certs/hostkey.pem "${SERVERINSTALLDIR}/diracos/etc/grid-security/"
139+
140+
# Generate the hash link file required by openSSL to index CA certificates
141+
caHash=$(openssl x509 -in "${SERVERINSTALLDIR}/diracos/etc/grid-security/certificates/ca.cert.pem" -noout -hash)
142+
# We make a relative symlink on purpose (i.e. not the full path to ca.cert.pem)
143+
# because otherwise the BundleDeliveryClient will send the full path, which
144+
# will be wrong on the client
145+
ln -s "${SERVERINSTALLDIR}/diracos/etc/grid-security/certificates/ca.cert.pem" "${SERVERINSTALLDIR}/diracos/etc/grid-security/certificates/$caHash.0"
146+
147+
# Copy the user cert and key to the correct directory
148+
cp /ca/certs/client.pem "${SERVERINSTALLDIR}/user/"
149+
cp /ca/certs/client.key "${SERVERINSTALLDIR}/user/"
150+
131151
rm -rf "${SERVERINSTALLDIR}/etc"
132152
ln -s "${SERVERINSTALLDIR}/diracos/etc" "${SERVERINSTALLDIR}/etc"
133153
source diracos/diracosrc
@@ -136,7 +156,6 @@ installSite() {
136156
done
137157
cd -
138158

139-
140159
echo "==> Sourcing bashrc"
141160
source "${SERVERINSTALLDIR}/bashrc"
142161

@@ -212,13 +231,6 @@ fullInstallDIRAC() {
212231
cat "${SERVERINSTALLDIR}/diracos/etc/Production.cfg"
213232
fi
214233

215-
# Dealing with security stuff
216-
# generateCertificates
217-
if ! generateUserCredentials; then
218-
echo "ERROR: generateUserCredentials failed" >&2
219-
exit 1
220-
fi
221-
222234
if ! diracCredentials; then
223235
echo "ERROR: diracCredentials failed" >&2
224236
exit 1

0 commit comments

Comments
 (0)