Skip to content

10.1.5 Host Certificate EST Auto Renewal and Central Management

This section is for site administrators automating renewal of new IHEP CA host certificates or migration of legacy IHEP-2013 host certificates, without using the WebUI. By default, new-CA certificates are renewed throughsimplereenrollwithin45 daysof expiry; normal renewal does not revoke the old certificate. Both migration and renewal generate a new private key and CSR on the target host.

10.1.5.1 Install the script and CA public keys

The site administrator deploys the following files to the target host:

/usr/local/sbin/ihep-host-auto.sh/etc/grid-security/certificates/IHEP-2026-Root.pem/etc/grid-security/certificates/IHEP-2026-ICA.pem/etc/grid-security/certificates/IHEP-2013.pem # only needed for legacy Host migration

The script requires Bash, OpenSSL, curl, flock and GNU coreutils, and supports onlyunencrypted PEM host private keys. Host certificates and keys are normally stored in/etc/grid-security/, or in an application-specific directory. CA certificates are stored in the standard trust directory,/etc/grid-security/certificates/.

sudoinstall-oroot-groot-m0755ihep-host-auto.sh/usr/local/sbin/ihep-host-auto.shsudoinstall-d-oroot-groot-m0755/etc/grid-security/certificatessudoinstall-oroot-groot-m0644IHEP-2026-Root.pem/etc/grid-security/certificates/IHEP-2026-Root.pemsudoinstall-oroot-groot-m0644IHEP-2026-ICA.pem/etc/grid-security/certificates/IHEP-2026-ICA.pem

For legacy migration, save the old IHEP-2013 CA public key as/etc/grid-security/certificates/IHEP-2013.pem(mode0644; it contains no CA private key). Check that the current host key is password-less and safely permissioned: if openssl asks for a password or errors out, the key is unsuitable for this automation.

10.1.5.2 Manual run example

The example uses DIRAC host certificate paths.CURL_CA_CERTonly verifies the HTTPS server chain ofgridca.ihep.ac.cn; it can be omitted if the system CA already verifies it:

sudoenv\PKI_HOST=gridca.ihep.ac.cn\CERT_FILE=/opt/dirac/etc/grid-security/hostcert.pem\KEY_FILE=/opt/dirac/etc/grid-security/hostkey.pem\INSTALL_OWNER=diracINSTALL_GROUP=dirac\CERT_MODE=0444KEY_MODE=0400\CURL_CA_CERT=/etc/grid-security/certificates/est-ca.pem\/usr/local/sbin/ihep-host-auto.sh

The script first verifies that the current certificate and key match, then decides:

  • Current certificate issued by the IHEP-2013 CA: calls the migration endpoint and issues a new-CA Host certificate.
  • Current certificate issued by the new IHEP CA: calls the EST renewal endpoint only within 45 days of expiry.
  • Outside the renewal window: makes no change and exits successfully.

Do notsetALLOW_REPLACE=1in routine tasks; it is only for administrator-directed out-of-window reissue tests or incident handling. After the first successful issue, check the new serial number, expiry and install path in the output, then run:

opensslx509-in/opt/dirac/etc/grid-security/hostcert.pem-noout\-subject-issuer-dates-extsubjectAltName-extextendedKeyUsagetest"$(opensslx509-in/opt/dirac/etc/grid-security/hostcert.pem-noout-modulus|opensslsha256)"=\"$(opensslrsa-in/opt/dirac/etc/grid-security/hostkey.pem-noout-modulus|opensslsha256)"\&&echo'certificate and key match'

A host certificate should contain the DNS SANs, the responsible person's email SAN, and bothTLS Web Server AuthenticationandTLS Web Client Authenticationextended key usages.

10.1.5.3 Set up the cron job

  1. Run it manually once and confirm the output shows issuance or "not in renewal window".
  2. Confirm the target service can read the newly installedhostcert.pemandhostkey.pem.
  3. Edit root'scrontab -efor a daily run, e.g.:

    17 3 * * * /usr/local/sbin/ihep-host-auto.sh >>/var/log/ihep-host-auto.log 2>&1
  4. If the certificate is not in the default path, put the environment variables into a root-owned wrapper script that ordinary users cannot modify, and let cron call the wrapper. Save it as/usr/local/sbin/renew-dirac-host-cert, then runsudo chown root:rootandsudo chmod 0700:

    #!/usr/bin/env bashset-euopipefailexecenv\PKI_HOST=gridca.ihep.ac.cn\CERT_FILE=/opt/dirac/etc/grid-security/hostcert.pem\KEY_FILE=/opt/dirac/etc/grid-security/hostkey.pem\INSTALL_OWNER=diracINSTALL_GROUP=dirac\CERT_MODE=0444KEY_MODE=0400\CURL_CA_CERT=/etc/grid-security/certificates/est-ca.pem\RELOAD_CMD='systemctl reload dirac-service'\/usr/local/sbin/ihep-host-auto.sh

    Replacedirac-servicewith the real service unit; if the service has no safe reload command, do not configure a restart casually. Run the wrapper manually as root and verify the service before switching the cron line to the wrapper.

The script keeps backups of old files which may contain private keys: protect the backup directory at key level and clean it regularly; after a power loss or forced kill, first check the backups and that certificate/key match before restarting services.

10.1.5.4 Centralized management with Foreman + Puppet (certupdate-wrapper.sh)

For clusters managed by Foreman + Puppet, the wrapper scriptcertupdate-wrapper.shprovides centralized configuration for automatic host certificate migration and renewal.

Configure certificate and key paths, file ownership and service reload commands per node or host group in Foreman. Puppet uses these parameters to render an ERB template and deploy/usr/local/sbin/certupdate-wrapper.sh. The wrapper passes the configuration as environment variables toihep-host-auto.sh, which performs the migration or renewal.

To enable this for a node in Foreman:

  1. Edit the target node (or host group) in Foreman:

    Edit the node in Foreman

  2. Add thecertupdateclass to the node's Puppet ENC (class assignment):

    Add the certupdate class in the Puppet ENC

  3. OpenPuppet Class Parametersand set the certificate path, reload command and other parameters for the node (these become the environment variables in the wrapper):

    Edit Puppet Class Parameters: certificate path and reload command

The following ERB template illustrates how the wrapper works. Adapt the parameter names, file paths and service reload commands to the actual Puppet class before deployment:

#!/usr/bin/env bash# Managed by Puppet — certupdate-wrapper.sh (rendered from an ERB template; local changes are overwritten)set-euopipefail# Node configuration (delivered by Foreman Puppet Class Parameters)CERT_FILE="<%= @cert_file %>"KEY_FILE="<%= @key_file %>"INSTALL_OWNER="<%= @install_owner %>"INSTALL_GROUP="<%= @install_group %>"RELOAD_CMD="<%= @reload_cmd %>"LOG=/var/log/certupdate.log# Wait a random 0-30 minutes before each run to avoid hitting the CA server concurrentlysleep$((RANDOM%1800)){date'+%F %T certupdate start'envPKI_HOST=gridca.ihep.ac.cn\CERT_FILE="$CERT_FILE"KEY_FILE="$KEY_FILE"\INSTALL_OWNER="$INSTALL_OWNER"INSTALL_GROUP="$INSTALL_GROUP"\CERT_MODE=0444KEY_MODE=0400\CURL_CA_CERT=/etc/grid-security/certificates/est-ca.pem\RELOAD_CMD="$RELOAD_CMD"\/usr/local/sbin/ihep-host-auto.shdate'+%F %T certupdate done'}>>"$LOG"2>&1

Notes:

  • Random delay: each run first waits a random 0-30 minutes so that nodes do not hit the CA server concurrently.
  • Automatic migration/renewal: the wrapper finally callsihep-host-auto.sh, behaving the same as a manual run — an old IHEP-2013 certificate is migrated automatically, a new-CA certificate within 45 days of expiry is renewed automatically, and no change is made outside the renewal window.
  • Scheduled execution: the wrapper runs periodically from a cron job or systemd timer, also distributed by Puppet.
  • Logging: logs are written to/var/log/certupdate.logon the server.

10.1.5.5 Automatic IHEP-2013 Host migration

Legacy host migration and regular EST renewal use the same script. On the first run, the script authenticates with the old host certificate using mTLS (mutual TLS) and requests a new host certificate from:

https://gridca.ihep.ac.cn/.well-known/est/legacy-host/simpleenroll

The server verifies the old CA CRL, the old certificate chain and the consistency of the CSR with the old certificate's Subject, DNS SANs and email SAN. It uses the SAN email to look up ownership in LDAP. The old host certificate must be a non-CA certificate with exactly one email SAN and at least one DNS SAN; its CN must appear in the DNS SANs, and its DN must includeC=CNand follow the original IHEP Host DN structure. Migration is rejected if the old certificate is revoked, the CRL is missing or expired, the LDAP email does not exist, or the CSR changes the host name.

Each host name may be migrated only once.If a migration is interrupted, keep the script state/backup files and logs and contact the CA administrators for the corresponding workflow; do not delete the server-side migration record and blindly retry. After migration the new certificate is issued by the new IHEP CA; the next script run recognizes the new chain and switches to the regular EST renewal endpoint. The old certificate remains valid for its original lifetime for a smooth transition, butdo notmix old and new certificates into the samehostcert.pemfile.

FAQ

SeeFAQ.

AI 助手
快速提问 ×

有问题?输入后跳转到对话页继续交流

Baidu
map