How to get certificates that were rotated within the last month.
search cancel

How to get certificates that were rotated within the last month.

book

Article ID: 450001

calendar_today

Updated On:

Products

VMware Tanzu Platform - Cloud Foundry

Issue/Introduction

We have an API to check which certificate will expire in a month: https://OPS-MANAGER-FQDN/api/v0/deployed/certificates?expires_within=6m

 

For an already rotated certificate, we don’t have an API. 

Environment

Opsman

Resolution

We can obtain certificates that have been rotated within the last month using the OM CLI. This involves getting a list of certificates and processing their creation dates. 

In your workspace, create a YAML file that represents your Tanzu Operations Manager environment. Give the file a name. For example:

touch om-cli-env.yml

Add the following content to the file. For more information about configuring the file, see Generating an Env File in the Platform Automation Toolkit documentation.

---

target: https://OPS-MANAGER-FQDN
username: OPS-MANAGER-USERNAME
password: OPS-MANAGER-PASSWORD

Where:

OPS-MANAGER-FQDN is the FQDN of your Tanzu Operations Manager deployment.
OPS-MANAGER-USERNAME is the user name that you use when you log into the Tanzu Operations Manager UI.
OPS-MANAGER-PASSWORD is the password that you use when you log into the Tanzu Operations Manager UI.

export OM_ENV=PATH-TO-WORKING-DIRECTORY/om-cli-env.yml

Run :

om -k --env=$OM_ENV curl -s --path=/api/v0/deployed/certificates | jq \

  --argjson cutoff "$(date -v-1m +%s)" '

    .certificates[]

    | select(.valid_from != null)

    | select((.valid_from | fromdateiso8601) >= $cutoff)

    | {

        property_reference: (.property_reference // .variable_path),

        valid_from: .valid_from,

        valid_until: .valid_until,

        issuer: .issuer

      }'

 

  • -v-1m: Subtracts 1 month.

  • -v-2m: Subtracts 2 months, -v-6m for 6 months, etc.