TerraformPilot

DevOps

Terraform Q-Day Inventory: Find RSA and ECC Keys in State

Q-Day is when quantum computers break RSA and elliptic curves. Use Terraform state and jq to list every KMS key, ACM certificate and TLS key before Y2Q.

LLuca Berton2 min read

Introduction

#

Q-Day is the day a quantum computer can break RSA and elliptic-curve cryptography. Y2Q ("years to quantum") is the countdown to it. Nobody knows the date. The NIST plan in IR 8547 gives the planning dates: these algorithms are deprecated after 2030 and disallowed after 2035.

The TLS policy inventory showed where your endpoints negotiate keys. This article finds the keys themselves: the asymmetric keys and certificates that your Terraform state already knows.

What Breaks and What Does Not

#
ResourceExampleOn Q-Day
Symmetric KMS keySYMMETRIC_DEFAULT (AES-256)Stays secure
Asymmetric KMS keyRSA_2048, ECC_NIST_P256Broken
ACM certificateRSA_2048, EC_prime256v1Signature can be forged
tls_private_keyRSA, ECDSA, ED25519Broken

Most KMS keys are symmetric. This is good news: the list of keys that need work is shorter than the list of all keys.

Step 1: Asymmetric KMS Keys

#
terraform show -json | jq -r '
  .. | objects
  | select(.type? == "aws_kms_key")
  | select(.values.customer_master_key_spec != "SYMMETRIC_DEFAULT")
  | [.address, .values.customer_master_key_spec, .values.key_usage] | @tsv'

Each line is a key that signs, verifies or wraps data with RSA or elliptic curves. Write down what uses it: code signing, JWT signing, envelope encryption for another system.

Step 2: ACM Certificates

#
terraform show -json | jq -r '
  .. | objects
  | select(.type? == "aws_acm_certificate")
  | [.address, .values.domain_name, .values.key_algorithm, .values.not_after] | @tsv'

Public certificates rotate in months, so the algorithm changes with a renewal. Imported certificates and private CA certificates with long lifetimes are the ones to mark.

Step 3: Keys Made by Terraform

#
terraform show -json | jq -r '
  .. | objects
  | select(.type? == "tls_private_key")
  | [.address, .values.algorithm, (.values.rsa_bits // .values.ecdsa_curve // "-")] | @tsv'

A tls_private_key resource also keeps the private key in state. That is a separate problem to solve, with or without quantum computers.

Step 4: One Report for All Workspaces

#
#!/usr/bin/env bash
# Usage: ./q-day-inventory.sh dir1 dir2 ...
set -euo pipefail
 
for dir in "$@"; do
  terraform -chdir="$dir" show -json | jq -r --arg ws "$dir" '
    .. | objects
    | select(.type? == "aws_kms_key" or .type? == "aws_acm_certificate" or .type? == "tls_private_key")
    | [$ws, .type, .address,
       (.values.customer_master_key_spec // .values.key_algorithm // .values.algorithm)]
    | @tsv'
done | grep -v "SYMMETRIC_DEFAULT" | sort

The output is a tab-separated list: workspace, resource type, address, algorithm.

Step 5: Make the Algorithm a Variable

#

When an algorithm name is typed in each resource, a migration is a search in every repository. Put it in one place:

variable "signing_key_spec" {
  description = "Key spec for asymmetric signing keys"
  type        = string
  default     = "ECC_NIST_P384"
}
 
resource "aws_kms_key" "signing" {
  description              = "Artifact signing key"
  key_usage                = "SIGN_VERIFY"
  customer_master_key_spec = var.signing_key_spec
}

A change of key spec replaces the key. Plan it like a key rotation: create the new key, move the consumers, then remove the old key. When your provider version supports a post-quantum key spec, you change one default and follow the same process.

How to Sort the List

#

Use Mosca's inequality. X is the number of years the protected data must stay secret, Y is the number of years your migration takes, Z is the number of years to Q-Day. If X + Y is larger than Z, that key is late.

  • Encryption and key wrapping with RSA: highest priority. Data that is wrapped today can be unwrapped after Q-Day.
  • Signing keys: lower priority. A forged signature needs the quantum computer at the time of the attack.
  • Long-lived roots: start early, because the replacement is slow.

Conclusion

#

You do not need the date of Q-Day to start. You need the list. Three jq commands on your state give it to you today.

For hybrid TLS policies and KMS details, see Terraform for Post-Quantum Cryptography: Migrate TLS and KMS.

#Terraform#Security#AWS#Cryptography#Post-Quantum#KMS

Share this article