Security

Cloud Asset Inventory

Tutorials

The RSA rumor is a good excuse to count your RSA keys

TL;DR: An NSA advisory and a rumor about faster RSA attacks make now a good time to inventory your asymmetric keys. One CloudQuery config syncs AWS, GCP and Azure into SQLite, and a handful of SQL queries list every RSA and elliptic curve key, certificate and stored private key.

Last week a rumor went around that an AI lab had found a fast way to break RSA on ordinary computers. No quantum computer needed. This week it stopped being only a rumor. On December 2 the NSA told owners, operators and vendors of National Security Systems to immediately accelerate their move to post-quantum cryptography. Later that day eight companies, including Amazon, Google, Microsoft and Oracle, backed the guidance.

Nobody has said RSA is broken. The joint ONCD, NSA and CISA statement says AI labs privately disclosed findings that affect some cryptography in use today, and that there's no immediate, widespread threat (summary). The findings aren't public. The advice is still to move now.

The first item on the NSA's list is an inventory of cryptographic dependencies, including public-key algorithms and digital signatures. Inventory is what we built CloudQuery for. The guidance is aimed at national security systems, but I'd treat it as a signal for everyone else.

So if we're to create an inventory of all our keys, how do we even start, and what are all the keys that could be affected?

In this article:

What's actually exposed

RSA and elliptic curve keys (ECDSA and Ed25519 included) fall to Shor's algorithm on a large enough quantum computer. A faster classical factoring method would only hit RSA. In both cases the inventory is the same: asymmetric keys and the certificates built on them. AES-256 is fine.

That also changes what "secrets" means here. AWS Secrets Manager encrypts secrets with symmetric KMS keys, so the stored secret isn't the weak spot. The weak spots are private keys and certificates, including the ones people stored as secrets.

Sync only what you need

Below is a CloudQuery config file. It syncs the tables we need from AWS, GCP and Azure into one SQLite database, so there's nothing to set up beyond the CloudQuery CLI. If you don't use one or more of the clouds, remove or comment out its section. Save it as config.yml:

kind: source
spec:
name: aws
path: cloudquery/aws
registry: cloudquery
version: "v36.0.1"
tables:
- aws_kms_keys
- aws_acm_certificates
- aws_ec2_key_pairs
- aws_elbv2_listeners
- aws_elbv2_listener_certificates
destinations: ["sqlite"]
---
kind: source
spec:
name: gcp
path: cloudquery/gcp
registry: cloudquery
version: "v24.5.1"
tables:
- gcp_kms_crypto_key_versions
- gcp_compute_ssl_certificates
destinations: ["sqlite"]
spec:
project_ids: ["my-project"]
---
kind: source
spec:
name: azure
path: cloudquery/azure
registry: cloudquery
version: "v23.5.4"
tables:
- azure_keyvault_certificate_policies
- azure_keyvault_secrets
- azure_keyvault_keys
- azure_keyvault_keyvaults
destinations: ["sqlite"]
---
kind: destination
spec:
name: sqlite
path: cloudquery/sqlite
registry: cloudquery
version: "v2.15.1"
spec:
connection_string: ./db.sql

Then run cloudquery sync config.yml. All tables are synced to the db.sql database, and sqlite3 db.sql is all you need to run the queries below.

If you have the AWS, gcloud and Azure CLIs installed and signed in, CloudQuery uses those credentials automatically. There's nothing to put in the config.

  • AWS: sign in with the AWS CLI. Read-only permissions are enough.
  • GCP: run gcloud auth application-default login. The account needs roles/viewer and roles/iam.securityAuditor. Leave out project_ids to sync every project it can see.
  • Azure: run az login. All visible subscriptions are synced unless you set subscriptions. That's fine for a one-off run. For a scheduled sync, use a service principal (AZURE_TENANT_ID, AZURE_CLIENT_ID, AZURE_CLIENT_SECRET).

AWS

KMS keys that are RSA or elliptic curve:

SELECT account_id, region, key_id, key_spec, key_usage, key_manager
FROM aws_kms_keys
WHERE key_state = 'Enabled'
AND (key_spec LIKE 'RSA%' OR key_spec LIKE 'ECC%' OR key_spec = 'SM2');

ACM only issues RSA and EC certificates, so everything is in scope. What I care about is what's attached to something:

SELECT account_id, region, domain_name, key_algorithm, not_after
FROM aws_acm_certificates
WHERE status = 'ISSUED' AND in_use_by IS NOT NULL AND in_use_by <> '[]'
ORDER BY not_after;

EC2 key pairs, which is where the old SSH keys live:

SELECT key_type, count(*) FROM aws_ec2_key_pairs GROUP BY key_type;

Load balancer listeners tell you which certificate terminates TLS, so you can see which of those RSA certificates are on the front door:

SELECT l.load_balancer_arn, l.port, l.ssl_policy, c.certificate_arn, a.key_algorithm
FROM aws_elbv2_listeners l
JOIN aws_elbv2_listener_certificates c ON c.listener_arn = l.arn
LEFT JOIN aws_acm_certificates a ON a.arn = c.certificate_arn
WHERE l.protocol IN ('HTTPS', 'TLS');

An empty key_algorithm means the certificate isn't in ACM (an IAM server certificate, for example), so it needs a look by hand.

GCP

SELECT project_id, name, algorithm, protection_level, state
FROM gcp_kms_crypto_key_versions
WHERE state = 'ENABLED'
AND (algorithm LIKE 'RSA%' OR algorithm LIKE 'EC%' OR algorithm LIKE 'KEM_ECDH%');

The not so cool: gcp_compute_ssl_certificates has the certificate as a PEM and no algorithm column. SQL can't parse a PEM, so let openssl do it:

sqlite3 -separator ' ' db.sql \
"SELECT project_id, name, replace(certificate, char(10), '|')
FROM gcp_compute_ssl_certificates WHERE certificate <> ''" |
while read -r project name pem; do
alg=$(echo "$pem" | tr '|' '\n' | openssl x509 -noout -text |
grep -E 'Public Key Algorithm|Public-Key' | tr -s ' ' | tr '\n' ' ')
echo "$project $name:$alg"
done

Each line shows the algorithm and key size, for example rsaEncryption with (2048 bit), or id-ecPublicKey with (256 bit). Rows with an empty certificate column are skipped.

Azure

Key Vault certificates carry their key type in the policy:

SELECT id,
key_properties->>'kty' AS key_type,
key_properties->>'key_size' AS key_size,
key_properties->>'crv' AS curve
FROM azure_keyvault_certificate_policies
WHERE key_properties->>'kty' IN ('RSA', 'RSA-HSM', 'EC', 'EC-HSM');

Private keys stored as plain secrets are harder. If people set a content type, you can find them:

SELECT id, content_type
FROM azure_keyvault_secrets
WHERE content_type IN ('application/x-pkcs12', 'application/x-pem-file')
AND managed IS NOT TRUE;

The managed filter drops the secrets Key Vault creates behind certificates, which the query above already covers. The rest only works as well as your team's labeling habits.

The other gap: azure_keyvault_keys has the key ID, attributes, tags and a managed flag. No key type. What it can do is count standalone keys per vault, and the vault tier narrows it down. Standard vaults only hold RSA and EC keys. Premium vaults can also hold symmetric AES keys.

SELECT v.name AS vault, v.properties->'sku'->>'name' AS sku, count(*) AS keys
FROM azure_keyvault_keys k
JOIN azure_keyvault_keyvaults v ON k.kid LIKE (v.properties->>'vaultUri') || '%'
WHERE k.managed IS NOT TRUE
GROUP BY 1, 2;

Every key in a standard vault is a quantum-vulnerable one. For a premium vault, az keyvault key show per key is the only way to tell. The managed filter drops the keys Key Vault creates behind certificates, which the certificate query already covers.

One list

Put the pieces together and you have the answer to Monday's question:

SELECT 'aws' AS cloud, arn AS resource, key_spec AS algorithm
FROM aws_kms_keys
WHERE key_state = 'Enabled'
AND (key_spec LIKE 'RSA%' OR key_spec LIKE 'ECC%' OR key_spec = 'SM2')
UNION ALL
SELECT 'aws', arn, key_algorithm FROM aws_acm_certificates WHERE status = 'ISSUED'
UNION ALL
SELECT 'aws', arn, key_type FROM aws_ec2_key_pairs
UNION ALL
SELECT 'gcp', name, algorithm
FROM gcp_kms_crypto_key_versions
WHERE state = 'ENABLED'
AND (algorithm LIKE 'RSA%' OR algorithm LIKE 'EC%' OR algorithm LIKE 'KEM_ECDH%')
UNION ALL
SELECT 'azure', id,
key_properties->>'kty' || '-' || coalesce(key_properties->>'key_size', key_properties->>'crv', '')
FROM azure_keyvault_certificate_policies
WHERE key_properties->>'kty' IN ('RSA', 'RSA-HSM', 'EC', 'EC-HSM');

What this won't find

These queries read metadata. They tell you a key exists and what algorithm it uses. They don't tell you what depends on it.

They also miss crypto inside your own applications and libraries, and anything outside these three clouds. TLS is a separate question: the load balancer query shows which policy each listener uses, but whether that policy offers a post-quantum key exchange is a lookup you'll have to do by hand.

What I'd do with the list

It depends on how RSA falls. If it takes a quantum computer, that's years away, so a certificate that expires in 90 days is a small problem and a KMS signing key nobody has touched in years is a bigger one. If the rumor turns out to be true and the attack runs on ordinary hardware, 90 days is a long time. Rotating to a new RSA key doesn't help either. Then the question is which keys you can move to another algorithm, and how fast.

Sort the list by what each key protects first, and by how long it lives second.

Key size matters too. According to coverage of the advisory, the NSA uses RSA-3072 or P-384 as the base size for root keys and allows RSA-2048 only where legacy support requires it. The size is already in key_spec, key_algorithm and the GCP algorithm column, and in key_size on Azure, so you can filter on it.

Then schedule the sync. The list is only useful if it's current when someone asks.

If you'd rather have an AI assistant do this with you, I put the same steps, config and queries in a skill you can hand to it. Copy this prompt into your assistant:

Fetch https://gist.github.com/pilvikala/c18f9e5c28c455fc995e54731a362052 and follow it to inventory the RSA and elliptic curve keys, certificates and private keys in our cloud accounts with CloudQuery. Ask me which of AWS, GCP and Azure we use before you start. Don't print or store any credentials.

Try CloudQuery yourself

Self-hosted, open source, and free to start. Or schedule a demo to see the managed version.

Related posts

Own your pipeline.
Own your data.