Mastering Certificate Revocation, CRL Rotation, and Tidy Operations in HashiCorp Vault
HashiCorp Vault is a prominent secret management tool that is designed to handle various secret types, including SSL/TLS certificates. As a system administrator or a developer, you may occasionally need to revoke certificates and/or rotate Certificate Revocation Lists (CRLs) in Vault. This article outlines the steps to delete certificates and rotate CRLs within the HashiCorp Vault environment.
If you need to create a quick two-level PKI Dev environment check this article: Create A Quick PKI HashicorpVault Dev Server
Generate a test certificate
Using the guide above let’s create a simple certificate:
vault write pki_int/issue/example-dot-com common_name="client3.example.com"
Output:
Key Value
--- -----
ca_chain [-----BEGIN CERTIFICATE-----
MIIDpjCCAo6gAwIBAgIUKuMdTyvkdQzumaXTQs2WVfVjAkUwDQYJKoZIhvcNAQEL
BQAwFjEUMBIGA1UEAxMLZXhhbXBsZS5jb20wHhcNMjMwNzExMTQxMzA0WhcNMjgw
NzA5MTQxMzM0WjAtMSswKQYDVQQDEyJleGFtcGxlLmNvbSBJbnRlcm1lZGlhdGUg
QXV0aG9yaXR5MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1WK24feB
Yppc1ADB6z8EKaA976irkZj+BnfpOU5sLB0L2PeCWj+ULT4hKf7aPMhAyjE4LqE4
Xid+i0Q1dLMV2hL2o6AtukZChjRbMgkTsoF4ek2NYRl6j2OjquwJ9Oz0bhYWKoMH
J2PVqT34Fhpp/uoQnLfbae8r6nWpmnphHBzE542e0cA3FXKb94tXmmRisaPcwJIZ
M325Oaq2m4/MuGyQq7UMuLIqEGCKoOFLr1gpDoZGdA1BKfDGxqAtcB8UITg/Pw8l
Bods1eLJHa2rgyR0kyfFqGSpqyDhi/BBSYjrf8c2D45B+OX8cmjyYbfcNveCYpWI
uA0F3nW6qT7dbQIDAQABo4HUMIHRMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMBAf8E
BTADAQH/MB0GA1UdDgQWBBSLFvPdQ84EZPRQHwBsLtS048fNwjAfBgNVHSMEGDAW
gBS0JVABj3P8T0KDNpz4l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cMVKps8r1dCtkM1zpmumiqdHjD58O4DzqrVriDH
TndZONai87/kbD7RNSoVz7so0fD8q3XbxefJyrCUQXKuCs5O0dxonUJ2JofMwWRu
3xmck0StPtuCQbl2acssiIUCgYA5hE8iiABkWjNQ3Z+uSwnspWBGCR2qyC+d52oU
eX8YY5I8z7KLIVLRaLI2JLgC1LbNOFLojsWI3t3Ik3VL9kOIAIQ4rJuXrekJWxfi
O6o9CzEAEjqJhtzYJgEvWDEgXhSfwfL4I1mwCQMDGlIzUhIfz6kduLfgm9c6C1Uk
gKClPQKBgBMMCb1nOpsi7wa23ySeRzo7d0Q1E9pBYJiBg5gZmrTksljHLcw3o3sL
MLzQNppDv4ZbUQS42Ysj/8wtwJh0SEHCUaOJvukvyKMjGD5uqTQHisDW36nl6BqV
B2DkDG/xFRLyLNUyNv54zWFdsv4+6UyM5aPrmIW7Z369zpI/5E5r
-----END RSA PRIVATE KEY-----
private_key_type rsa
serial_number 30:6e:65:c7:e9:01:1a:fd:b5:70:41:1a:cb:25:a3:79:bb:df:9e:da
Let’s Revoke That Certificate
Now that we have a test certificate let’s do the following:
- Revoke the serial number of the certificate
- Rotate the CRL (Generate a new CRL)
# Revoke
vault write pki_int/revoke serial_number=30:6e:65:c7:e9:01:1a:fd:b5:70:41:1a:cb:25:a3:79:bb:df:9e:da
# Output
Key Value
--- -----
revocation_time 1689087505
revocation_time_rfc3339 2023-07-11T14:58:25.136955428Z
# Rotate CRL
vault read pki_int/crl/rotate
# Output
Key Value
--- -----
success true
# Generate CRL
curl http://127.0.0.1:8200/v1/pki_int/crl -o crl.pem
# Open CRL with OpenSSL
openssl crl -in crl.pem -text
# Output
openssl crl -in crl.pem -text
Certificate Revocation List (CRL):
Version 2 (0x1)
Signature Algorithm: sha256WithRSAEncryption
Issuer: CN = example.com Intermediate Authority
Last Update: Jul 11 15:37:02 2023 GMT
Next Update: Jul 14 15:37:02 2023 GMT
CRL extensions:
X509v3 Authority Key Identifier:
8B:16:F3:DD:43:CE:04:64:F4:50:1F:00:6C:2E:D4:B4:E3:C7:CD:C2
Revoked Certificates:
Serial Number: 306E65C7E9011AFDB570411ACB25A379BBDF9EDA
Revocation Date: Jul 11 14:58:25 2023 GMT
Signature Algorithm: sha256WithRSAEncryption
Signature Value:
b5:d4:db:f7:b7:29:3d:91:85:e4:be:d2:6b:92:d3:8b:78:4d:
5d:71:1f:f6:cf:04:1c:af:6e:35:07:98:7a:91:0e:f1:36:b2:
77:fe:1a:e5:ee:bb:7c:3a:01:9e:f6:c9:e2:9b:af:fd:4c:24:
ad:5b:d7:2b:15:6f:a1:9c:c1:3e:87:95:64:f6:54:1b:3c:17:
bb:a8:85:de:65:6b:ac:e7:aa:ee:47:15:ef:1d:12:ff:fe:4e:
32:46:b8:43:03:06:e3:91:fe:80:e1:2f:9d:30:e4:86:1c:f9:
d9:f8:e6:ba:b6:d9:ff:a9:cf:05:1f:21:75:c8:72:cb:77:3c:
9f:7c:2b:a1:0a:24:17:1d:e4:e9:7a:9e:c5:21:8b:13:66:43:
ec:76:c2:ea:d8:a6:66:0f:d3:94:25:e4:8e:ad:ff:f0:0a:19:
06:f7:90:7e:63:09:04:d0:96:65:92:d0:76:3c:ab:f3:e6:42:
75:40:f6:da:c8:18:4c:27:e1:fb:6a:78:78:f5:16:1a:fc:fc:
ad:32:94:a4:d4:48:de:78:a8:8f:22:40:96:ce:a9:6f:b5:be:
e6:43:fc:0e:24:42:e1:94:09:58:90:9a:10:c2:16:83:d1:f3:
c5:63:81:9c:5a:63:bd:72:f1:90:ea:18:68:75:5d:e9:8b:a8:
85:19:f3:68
-----BEGIN X509 CRL-----
MIIBxDCBrQIBATANBgkqhkiG9w0BAQsFADAtMSswKQYDVQQDEyJleGFtcGxlLmNv
bSBJbnRlcm1lZGlhdGUgQXV0aG9yaXR5Fw0yMzA3MTExNTM3MDJaFw0yMzA3MTQx
NTM3MDJaMCcwJQIUMG5lx+kBGv21cEEayyWjebvfntoXDTIzMDcxMTE0NTgyNVqg
IzAhMB8GA1UdIwQYMBaAFIsW891DzgRk9FAfAGwu1LTjx83CMA0GCSqGSIb3DQEB
CwUAA4IBAQC11Nv3tyk9kYXkvtJrktOLeE1dcR/2zwQcr241B5h6kQ7xNrJ3/hrl
7rt8OgGe9snim6/9TCStW9crFW+hnME+h5Vk9lQbPBe7qIXeZWus56ruRxXvHRL/
/k4yRrhDAwbjkf6A4S+dMOSGHPnZ+Oa6ttn/qc8FHyF1yHLLdzyffCuhCiQXHeTp
ep7FIYsTZkPsdsLq2KZmD9OUJeSOrf/wChkG95B+YwkE0JZlktB2PKvz5kJ1QPba
yBhMJ+H7anh49RYa/PytMpSk1EjeeKiPIkCWzqlvtb7mQ/wOJELhlAlYkJoQwhaD
0fPFY4GcWmO9cvGQ6hhodV3pi6iFGfNo
-----END X509 CRL-----
- The first code block uses HashiCorp Vault’s API to revoke a specific certificate, identified by its serial number, resulting in the certificate’s revocation time being returned in both UNIX timestamp format and RFC3339 format.
- The second block of code invokes a command to rotate the Certificate Revocation List (CRL), an important process to ensure the list’s freshness, and it confirms the successful operation with a
true
return. - Vault’s CRL is automatically updated upon revocation and is available immediately through the API endpoint (
/v1/pki/crl
) without the need for manual rotation. Manual rotation of the CRL (via the/pki_int/crl/rotate
endpoint) is not typically necessary. This would only be required in specific circumstances, such as a compromised private key that was used to sign the CRL. - The last part of the code generates the updated CRL, retrieves it through an HTTP request, and saves it to a local file (
crl.pem
). This CRL file is then opened with OpenSSL, revealing the details of the revoked certificates, their serial numbers, revocation dates, and other related information.
The Certificate Is Revoked, Now What?
When a certificate is revoked, it is added to a Certificate Revocation List (CRL). However, the revocation does not automatically prevent the certificate from being used on a server or client, it’s more of a flag that the certificate should not be trusted.
For a third-party to know whether a certificate has been revoked, their software (such as a web browser or a server software) must check the revocation status of the certificate. This can be done by checking the CRL: The software can download the CRL from the CA and see if the certificate is listed there. The CRL is simply a list of all certificates that have been revoked by the CA.
So if a revoked certificate is still being used, its ongoing usage would typically not be directly visible to the issuer. However, when a client (for example, a browser) encounters the revoked certificate, it can verify its status against the CRL and refuse to trust the certificate.
Below is a bash script that downloads the CRL, and checks if the certificate in question is revoked.
#!/bin/bash
# Define Vault server URL and PKI path
VAULT_ADDR="http://127.0.0.1:8200/v1"
PKI_PATH="pki_int"
# Certificate to check
CERT_FILE="mycert.pem"
# Download CRL
echo "Downloading CRL..."
curl -s "${VAULT_ADDR}/${PKI_PATH}/crl" -o crl.pem
# Extract serial number of the certificate
echo "Extracting certificate serial number..."
SERIAL_NUMBER=$(openssl x509 -in ${CERT_FILE} -noout -serial | cut -d= -f 2)
# Check if certificate serial number exists in the CRL
echo "Checking certificate status..."
if openssl crl -in crl.pem -noout -text | grep -q "${SERIAL_NUMBER}"; then
echo "Certificate ${SERIAL_NUMBER} has been revoked."
else
echo "Certificate ${SERIAL_NUMBER} is still valid."
fi
Deleting VS Tidy in Vault
Deleting, as the term suggests, would mean the complete removal of the certificate from Vault’s storage. In some older versions of Vault, it is not possible to delete a certificate once it is issued. This approach ensures that there is an audit trail and allows for tracking all issued certificates even after their expiration or revocation. This is important from a security perspective as it helps maintain a record of all issued certificates which can be useful for audit or troubleshooting purposes.
Tidying, on the other hand, is an operation Vault performs to clean up its storage. The tidy
operation in Vault's PKI Secrets Engine is responsible for removing certificates that are expired and are not found in the Certificate Revocation List (CRL). This operation helps keep Vault's storage lean and efficient by removing certificates that are no longer needed. It's important to note that tidying doesn't affect the CRL, so any certificate that's been revoked will still be listed there, even if the certificate itself is removed.
To test the tidy operation let’s generate a 1 min certificate adding ttl=60
vault write pki_int/issue/example-dot-com common_name="client3.example.com" ttl=60
Key Value
--- -----
ca_chain [-----BEGIN CERTIFICATE-----
MIIDpjCCAo6gAwIBAgIUKuMdTyvkdQzumaXTQs2WVfVjAkUwDQYJKoZIhvcNAQEL
BQAwFjEUMBIGA1UEAxMLZXhhbXBsZS5jb20wHhcNMjMwNzExMTQxMzA0WhcNMjgw
NzA5MTQxMzM0WjAtMSswKQYDVQQDEyJleGFtcGxlLmNv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21:f0:58:48:57:ad:ec:ea:bc:70:d7:45:e8:11
We can check if it has expired using something like:
CERTIFICATE=$(vault read -format=json pki_int/cert/45:94:9b:f6:2f:2c:21:f0:58:48:57:ad:ec:ea:bc:70:d7:45:e8:11 | jq -r .data.certificate)
echo "$CERTIFICATE" | openssl x509 -noout -enddate
# Output
notAfter=Jul 13 10:54:55 2023 GMT
Now we’ll tidy the expired certificates
vault write pki_int/tidy tidy_cert_store=true tidy_revoked_certs=true safety_buffer="1m"
# Output
WARNING! The following warnings were returned from Vault:
* Tidy operation successfully started. Any information from the operation
will be printed to Vault's server logs.
The tidy function takes two parameters: tidy_cert_store
and tidy_revocation_list
. When set to true, tidy_cert_store
removes expired certificates from the backend storage, while tidy_revocation_list
deletes expired entries from the revocation list. It’s important to note that these operations are quite resource-intensive and can affect Vault’s performance if run frequently or during peak times. Therefore, they should be used judiciously and preferably scheduled during off-peak hours.
The safety_buffer
parameter is specified as a duration (in this case, "1m" for 1 minute), and is meant to provide a margin of safety while tidying up.
What this means is that the tidy operation will consider a certificate as expired and ready for deletion only if the certificate’s expiration date is at least the specified safety_buffer
duration in the past. In this specific case, with a safety_buffer
of "1m", the tidy operation will only delete certificates that expired more than 1m ago.
After the tidy command has been run, if you run the same operation to retrieve the expiration date, calling the certificate, the certificate won’t be there any more.
CERTIFICATE=$(vault read -format=json pki_int/cert/45:94:9b:f6:2f:2c:21:f0:58:48:57:ad:ec:ea:bc:70:d7:45:e8:11 | jq -r .data.certificate)
echo "$CERTIFICATE" | openssl x509 -noout -enddate
# Output
No value found at pki_int/cert/45:94:9b:f6:2f:2c:21:f0:58:48:57:ad:ec:ea:bc:70:d7:45:e8:11
tldr:
The article provides a comprehensive guide on how to revoke SSL/TLS certificates, rotate Certificate Revocation Lists (CRLs), and tidy expired certificates in HashiCorp Vault, thereby optimizing certificate management and storage efficiency.