provider-sql icon indicating copy to clipboard operation
provider-sql copied to clipboard

feat: add AWS IAM database authentication for MySQL and PostgreSQL

Open michielvha opened this issue 5 months ago • 0 comments

Description of your changes

This adds AWS IAM database authentication for Aurora/RDS MySQL and PostgreSQL. When it is enabled the provider connects using a short-lived IAM token instead of a static password, so combined with EKS Pod Identity or IRSA there is no static database credential to manage.

It adds a new AWSIAMAuth value to the credentials.source enum, alongside the existing *ConnectionSecret sources. When it is selected:

  • the connection secret only needs endpoint, port and username (no password);
  • a token is generated at connect time with aws-sdk-go-v2/feature/rds/auth and used as the password;
  • TLS is enforced, and for MySQL allowCleartextPasswords=true is set, which the AWSAuthenticationPlugin requires.

An optional region field is added, with fallback to a region key in the secret and then to the controller's AWS environment.

Scope is provider authentication only, as discussed in #347. Creating the IAM-enabled database users themselves stays a separate, out-of-band step, and is already possible through the existing Role/Grant resources.

On the RDS certificate authority: following the discussion with @kkendzia and @phmcder, the Amazon RDS CA is treated as an external dependency rather than bundled in the provider. Operators make it available to the provider pod (for example with trust-manager, or a mounted secret) and choose the verification mode through the existing tls / sslMode fields. If neither is configured the connection is still encrypted but unverified. This is documented in docs/aws-iam-auth.md, with example ProviderConfigs under examples/{cluster,namespaced}/{mysql,postgresql}/config_iam.yaml.

Fixes #347

I have:

  • [x] Read and followed Crossplane's contribution process.
  • [x] Run make reviewable to ensure this PR is ready for review.

How has this code been tested

  • Unit tests for the new awsiam package (region resolution, host:port assembly, token injection, error paths), the MySQL cleartext DSN, and the IAM branch in the cluster reconcilers and the namespaced providers. The injection sits behind a small package-level seam so that path is covered without any AWS access.
  • gofmt, goimports, go vet, golangci-lint and code generation are all clean, and the full test suite passes.
  • End to end against real RDS (MySQL 8.0 and PostgreSQL 16 with IAM authentication enabled): the provider's own client code generates a token and connects for both engines.

michielvha avatar Jun 20 '26 04:06 michielvha