Skip to content

Commit

Permalink
feat: use a container for creating the CA and server certificate
Browse files Browse the repository at this point in the history
  • Loading branch information
fstagni committed Jan 23, 2025
1 parent 3d1ca28 commit 8601df3
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 364 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,9 @@ the private key. You will need two different sets certificates and the CA certif
The following commands should do the trick for you, by creating a fake CA, a fake user certificate, and a fake host certificate::

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

Expand Down
21 changes: 19 additions & 2 deletions tests/CI/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
volumes:
# Volume used to store the certificates of dirac
certs_data:
# Volume used to store the config of diracx
diracx-cs-store:
# Volume used to store the pair of keys to sign the tokens
Expand Down Expand Up @@ -101,6 +103,16 @@ services:
command: /home/dirac/LocalRepo/ALTERNATIVE_MODULES/DIRAC/tests/CI/check_db_initialized.sh
pull_policy: always

dirac-init-certificates:
image: ghcr.io/diracgrid/diracx/secret-generation:latest
container_name: dirac-init-certificates
volumes:
# As the images don't run as root we need to change the permissions of the /ca/ directory as well
- certs_data:/ca/certs/
entrypoint: |
/entrypoint.sh
pull_policy: always

dirac-server:
image: ${CI_REGISTRY_IMAGE}/${HOST_OS}-dirac
container_name: server
Expand All @@ -116,20 +128,23 @@ services:
condition: service_started
iam-login-service:
condition: service_healthy
dirac-init-certificates:
condition: service_completed_successfully # Let the init container crete the certificates
diracx-init-key:
condition: service_completed_successfully # Let the init container create the signing key
diracx-init-cs:
condition: service_completed_successfully # Let the init container create the cs
ulimits:
nofile: 8192
volumes:
- certs_data:/ca/certs
- diracx-cs-store:/cs_store
- diracx-key-store:/signing-key
environment:
- DIRACX_CONFIG_BACKEND_URL=git+file:///cs_store/initialRepo
- DIRACX_SERVICE_AUTH_TOKEN_KEY=file:///signing-key/rs256.key
pull_policy: always
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.
pull_policy: always


dirac-client:
Expand All @@ -141,8 +156,10 @@ services:
- dirac-server
ulimits:
nofile: 8192
pull_policy: always
volumes:
- certs_data:/ca/certs
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.
pull_policy: always

dirac-pilot:
image: ${CI_REGISTRY_IMAGE}/${HOST_OS}-dirac
Expand Down
110 changes: 0 additions & 110 deletions tests/Jenkins/config/ci/openssl_config_ca.cnf

This file was deleted.

37 changes: 0 additions & 37 deletions tests/Jenkins/config/ci/openssl_config_host.cnf

This file was deleted.

20 changes: 0 additions & 20 deletions tests/Jenkins/config/ci/openssl_config_user.cnf

This file was deleted.

38 changes: 25 additions & 13 deletions tests/Jenkins/dirac_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,7 @@ source "${TESTCODE}/DIRAC/tests/Jenkins/utilities.sh"
installSite() {
echo "==> [installSite]"

generateCA
generateCertificates

echo -n > "${SERVERINSTALLDIR}/dirac-ci-install.cfg"
# echo -n > "${SERVERINSTALLDIR}/dirac-ci-install.cfg"
getCFGFile

echo "==> Fixing install.cfg file"
Expand Down Expand Up @@ -127,7 +124,30 @@ installSite() {
bash "installer.sh"
rm "installer.sh"
echo "source \"$PWD/diracos/diracosrc\"" > "$PWD/bashrc"
mv "${SERVERINSTALLDIR}/etc/grid-security/"* "${SERVERINSTALLDIR}/diracos/etc/grid-security/"

mkdir -p "${SERVERINSTALLDIR}/diracos/etc/grid-security/certificates/"
mkdir -p "${SERVERINSTALLDIR}/user/"

echo "==> CAs and certificates"

# Copy the CA to the list of trusted CA
cp "/ca/certs/ca.cert.pem" "${SERVERINSTALLDIR}/diracos/etc/grid-security/certificates/"

# Copy the cert and host key to the certificates directory
cp /ca/certs/hostcert.pem "${SERVERINSTALLDIR}/diracos/etc/grid-security/"
cp /ca/certs/hostkey.pem "${SERVERINSTALLDIR}/diracos/etc/grid-security/"

# Generate the hash link file required by openSSL to index CA certificates
caHash=$(openssl x509 -in "${SERVERINSTALLDIR}/diracos/etc/grid-security/certificates/ca.cert.pem" -noout -hash)
# We make a relative symlink on purpose (i.e. not the full path to ca.cert.pem)
# because otherwise the BundleDeliveryClient will send the full path, which
# will be wrong on the client
ln -s "${SERVERINSTALLDIR}/diracos/etc/grid-security/certificates/ca.cert.pem" "${SERVERINSTALLDIR}/diracos/etc/grid-security/certificates/$caHash.0"

# Copy the user cert and key to the correct directory
cp /ca/certs/client.pem "${SERVERINSTALLDIR}/user/"
cp /ca/certs/client.key "${SERVERINSTALLDIR}/user/"

rm -rf "${SERVERINSTALLDIR}/etc"
ln -s "${SERVERINSTALLDIR}/diracos/etc" "${SERVERINSTALLDIR}/etc"
source diracos/diracosrc
Expand All @@ -136,7 +156,6 @@ installSite() {
done
cd -


echo "==> Sourcing bashrc"
source "${SERVERINSTALLDIR}/bashrc"

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

# Dealing with security stuff
# generateCertificates
if ! generateUserCredentials; then
echo "ERROR: generateUserCredentials failed" >&2
exit 1
fi

if ! diracCredentials; then
echo "ERROR: diracCredentials failed" >&2
exit 1
Expand Down
Loading

0 comments on commit 8601df3

Please sign in to comment.