Skip to content

feat: add DescribeKey (KMS) and ListCertificates (ACM) query types - #53

Open
kaessert wants to merge 2 commits into
mainfrom
hive/kms-acm-query-types
Open

kaessert wants to merge 2 commits into
mainfrom
hive/kms-acm-query-types

Conversation

@kaessert

@kaessert kaessert commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Description of your changes

Adds two read-only query types.

DescribeKey resolves a KMS key to its metadata, notably the key ARN, from parameters.keyId. KMS accepts a key ID, key ARN, alias name (alias/platform/eks) or alias ARN, so the alias is resolved server-side. It returns one object: {keyId, arn, keyState, enabled, keyManager, keyUsage, keySpec, description, creationDate}. Cloud Control is no substitute: AWS::KMS::Alias lists every alias in the account and returns a key ID, not an ARN. A missing or empty keyId is fatal and the message names parameters.keyId.

ListCertificates lists ACM certificates and returns [{certificateArn, domainName, status, type, keyAlgorithm, inUse, notBefore, notAfter}]. Cloud Control does not model ACM certificates and the Tagging API returns no domain names, hence the direct call.

  • It reads all pages.
  • The only supported filter is domainName: an exact client-side match, values OR'd. Any other filter name is fatal. A wildcard certificate is matched as *.example.com; other subject alternative names are not matched.
  • parameters.statuses (csv) defaults to ISSUED.
  • parameters.keyTypes (csv) defaults to every key type. ACM's own default returns only RSA_1024/RSA_2048 and would silently hide an EC or RSA_4096 certificate.
  • Results are sorted newest notAfter first, ties broken by ARN, so [0] is the certificate to use mid-rotation and the output is stable across reconciles.

Both require a region and wrap AWS errors with the operation name (DescribeKey also with the key ID).

Other changes:

  • queryType enum extended and the package/input CRD regenerated with go generate.
  • README: table rows, a "Which one to use?" entry with the IAM actions (kms:DescribeKey, acm:ListCertificates), and the parameter and filter docs. The README also explains that both follow AWS on every reconcile, and that a status.* target with skipQueryWhenTargetHasData: true gives resolve-once semantics.
  • Examples: composition-kms-key.yaml and composition-acm-certificates.yaml, with example/Makefile and example/README.md entries. status.kmsKey is declared in example/definition.yaml, as an undeclared status target fails apply.
  • package/crossplane.yaml description updated.
  • New dependencies service/kms v1.63.0 and service/acm v1.52.0. They were chosen to match the already-pinned aws-sdk-go-v2 v1.48.0 core, so no core bump is pulled in.

Testing

Unit tests in aws_test.go, using the existing stub pattern:

  • TestDescribeKey, TestDescribeKeyRequiresKeyID
  • TestListCertificates (pagination, exact domainName match, ordering, defaults)
  • TestListCertificatesRequest (default ISSUED status and all key types on the request; statuses/keyTypes narrowing)
  • TestListCertificatesRejectsUnknownFilter
  • TestKMSACMAPIError, and both types added to the existing TestEc2RegionGuard table
  • TestRunFunctionKMSACMTargets (status.* and context.* targets)

Run with go test ./....

The two types were also exercised with crossplane render against a local AWS emulator: an alias resolves to the seeded key ARN, and an *.example.com filter returns only matching certificates, newest first. The emulator cannot show the ECDSA default, so that is covered only by TestListCertificatesRequest.

For reviewers

  • queryIntervalMinutes only applies to status.* targets. This is existing behaviour in fn.go, and I left it unchanged. The tests check that lastQueryTime is set on status targets and do not assert its absence on context targets.
  • domainName matches the certificate's primary domain only, not its other subject alternative names.

I have:

DescribeKey resolves a KMS key by key ID, key ARN, alias name or alias
ARN to its metadata (notably the key ARN). Cloud Control's
AWS::KMS::Alias lists every alias in the account and returns a key ID,
not an ARN.

ListCertificates reads all ACM certificate pages, matches the domainName
filter exactly client-side, defaults to ISSUED, requests every key type
(ACM's default silently drops all but RSA_1024/RSA_2048) and sorts
newest notAfter first, ties by ARN. Cloud Control does not model ACM
certificates and the Tagging API returns no domain names.
@kaessert
kaessert marked this pull request as ready for review December 4, 2026 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant