Why this checklist
Expired certificates cause outages that are easy to prevent. On OCI, certificates can be stored in three places, and no single console page shows them all:
| Where the certificate lives | How it gets there | Expiry visible in |
|---|---|---|
| Certificates service | Issued by an OCI private CA, or imported | oci certs-mgmt certificate get (time-of-validity-not-after) |
| Load balancer certificate bundle (legacy) | Uploaded directly to the load balancer | Not shown. You have to parse the PEM |
| API Gateway certificate | Uploaded to API Gateway for a custom domain | oci api-gateway certificate list (time-not-valid-after) |
Run this checklist once to build an inventory, then schedule the script at the end.
Before you start
- OCI CLI 3.x,
jqandopensslare installed. Cloud Shell has all three. - Your group can
inspectandreadcertificates, load balancers and API gateways in the tenancy, for exampleread leaf-certificate-family,read load-balancersandread api-gateway-family. Policy family names vary; check the IAM policy reference for your realm. - You've listed every active region your tenancy uses. Certificates are regional:
oci iam region-subscription list --query 'data[].{region:"region-name",status:status}' --output table
- You have the OCIDs of every compartment to scan:
TENANCY=$(oci iam compartment list --query 'data[0]."compartment-id"' --raw-output)
oci iam compartment list -c "$TENANCY" --compartment-id-in-subtree true --all \
--lifecycle-state ACTIVE --query 'data[].id' --raw-output | jq -r '.[]' > compartments.txt
echo "$TENANCY" >> compartments.txt
1. Certificates service
- List the certificates in each compartment, soonest expiry first:
oci certs-mgmt certificate list -c "$COMP" --all --lifecycle-state ACTIVE \
--sort-by EXPIRATIONDATE --sort-order ASC \
--query 'data.items[].{name:name,id:id,type:"config-type"}' --output table
- Get the expiry date and renewal rule for each one:
oci certs-mgmt certificate get --certificate-id "$CERT_ID" \
--query 'data.{name:name,type:"config-type",notAfter:"current-version".validity."time-of-validity-not-after",rules:"certificate-rules"}'
- Read
config-typebefore you plan any work. It decides who does the renewal:
config-type | Renewal |
|---|---|
ISSUED_BY_INTERNAL_CA | The service renews it automatically using the renewal rule (renewal-interval, advance-renewal-period) |
MANAGED_EXTERNALLY_ISSUED_BY_INTERNAL_CA | You submit a new CSR before expiry |
IMPORTED | Manual. You import the new certificate from your public CA as a new version |
- For
IMPORTEDcertificates, record who owns the public CA account and how the new certificate gets ordered. This is where most surprise expiries come from. - For auto-renewed certificates, check that the issuing CA is
ACTIVEand isn't close to expiry itself. A certificate can't be renewed past its CA's lifetime.
oci certs-mgmt certificate-authority list -c "$COMP" --all \
--query 'data.items[].{name:name,state:"lifecycle-state",id:id}' --output table
2. Load balancer listeners
A listener uses one of two kinds of certificate. Find out which one each HTTPS listener uses:
- Show the certificate used by each listener:
oci lb load-balancer get --load-balancer-id "$LB_ID" \
--query 'data.listeners.* | [?"ssl-configuration"].{listener:name,port:port,bundle:"ssl-configuration"."certificate-name",certIds:"ssl-configuration"."certificate-ids"}' \
--output json
certIds set means the listener uses the Certificates service, which section 1 already covers. bundle set means it uses a legacy load balancer certificate, and the API doesn't give you its expiry date.
- Read the expiry date from the legacy bundle PEM:
oci lb certificate list --load-balancer-id "$LB_ID" --all \
| jq -r '.data[] | "\(."certificate-name")\t\(."public-certificate")"' \
| while IFS=$'\t' read -r name pem; do
end=$(printf '%b' "$pem" | openssl x509 -noout -enddate | cut -d= -f2)
echo "$name expires: $end"
done
- Check the live endpoint as well. It shows what clients actually receive, including a wrong chain:
echo | openssl s_client -connect app.example.com:443 -servername app.example.com 2>/dev/null \
| openssl x509 -noout -subject -issuer -enddate
- Check hostname-based listeners separately. Each virtual hostname can have its own certificate, so test each one with its own
-servername.
3. API Gateway
- List the API Gateway certificates and their expiry dates:
oci api-gateway certificate list -c "$COMP" --all --lifecycle-state ACTIVE \
--query 'data.items[].{name:"display-name",expires:"time-not-valid-after",id:id}' --output table
- Map each certificate to its gateway. Gateways can also use a Certificates service certificate instead:
oci api-gateway gateway list -c "$COMP" --all \
--query 'data.items[].{gw:"display-name",host:hostname,certId:"certificate-id"}' --output table
4. Renew without an outage
- Certificates service, imported: import the new certificate as a new version of the existing certificate in the console, or with the
oci certs-mgmt certificate update-certificate-by-importing-config-detailscommand (checkoci certs-mgmt certificate --helpon your CLI version). Load balancers and gateways that reference the certificate OCID pick up the current version, so the listener config doesn't change. - Legacy load balancer bundle: you can't edit a bundle in place. Upload the new one under a new name, then repoint the listener:
oci lb certificate create --load-balancer-id "$LB_ID" \
--certificate-name app-2027 \
--public-certificate-file app.crt --private-key-file app.key --ca-certificate-file chain.crt
oci lb work-request list --load-balancer-id "$LB_ID" --limit 1 # wait for SUCCEEDED
# Then point the listener at app-2027 (console: Listener > Edit > SSL certificate),
# re-test with openssl s_client, and only then delete the old bundle.
Warning
Updating a listener through the CLI (
oci lb listener update) needs the full listener definition, including the backend set, protocol and port. Leave out a field and you change the listener. If you're unsure, change the certificate in the console, or copy the current values fromoci lb load-balancer getfirst.
Caution
Don't delete the old certificate or bundle until the live endpoint shows the new expiry date on every hostname. Never delete or disable a CA that still issues active certificates. Its certificates stop renewing.
- API Gateway uploaded certificate: create a new API Gateway certificate, update the gateway to use it, verify with
openssl s_client, then delete the old one. - Note what you renewed and the new expiry date in the inventory.
Prevent it next time
Schedule a scan that reports everything expiring within 30 days. For example, run it from a small instance with an instance principal, or from a Function, once a day:
#!/usr/bin/env bash
# cert-expiry-scan.sh: report OCI certificates expiring within N days
DAYS=${DAYS:-30}
LIMIT=$(date -u -d "+${DAYS} days" +%s)
while read -r COMP; do
for ID in $(oci certs-mgmt certificate list -c "$COMP" --all --lifecycle-state ACTIVE \
--query 'data.items[].id' --raw-output 2>/dev/null | jq -r '.[]?'); do
oci certs-mgmt certificate get --certificate-id "$ID" \
--query 'data.[name,"current-version".validity."time-of-validity-not-after"]' --raw-output \
| jq -r '@tsv' | while IFS=$'\t' read -r name end; do
[ "$(date -u -d "$end" +%s)" -lt "$LIMIT" ] && echo "CERTS $name $end"
done
done
oci api-gateway certificate list -c "$COMP" --all --lifecycle-state ACTIVE 2>/dev/null \
| jq -r '.data.items[]? | [."display-name", ."time-not-valid-after"] | @tsv' \
| while IFS=$'\t' read -r name end; do
[ "$(date -u -d "$end" +%s)" -lt "$LIMIT" ] && echo "APIGW $name $end"
done
done < compartments.txt
- Send the output to an OCI Notifications topic (
oci ons message publish --topic-id ... --body "$(./cert-expiry-scan.sh)") when it isn't empty. - Loop over every subscribed region (
--region) and add the legacy load balancer check from section 2. - Move legacy load balancer bundles to the Certificates service, so expiry dates are visible through the API and renewals don't need listener changes.
- Use internal CA issued certificates with renewal rules for internal endpoints, and keep public certificates as
IMPORTEDwith a named owner. - Add an external probe (
openssl s_clientfrom outside OCI, or your synthetic monitoring tool) for public hostnames. It catches certificates the inventory missed.
Get the weekly HubDatAI email
One email a week with everything new: posts, learning sessions and videos. Free, no spam, unsubscribe in one click. What you get