postgres: add Azure AD and GCP Cloud SQL IAM dynamic-auth backends - #262
Open
reyortiz3 wants to merge 1 commit into
Open
postgres: add Azure AD and GCP Cloud SQL IAM dynamic-auth backends#262reyortiz3 wants to merge 1 commit into
reyortiz3 wants to merge 1 commit into
Conversation
Adds two dynamic-auth backends alongside the existing AWS RDS IAM one, plus generalizes the backend-dispatch plumbing to support three (and future) backends cleanly instead of a single hardcoded check. - DynamicAuthAzureAD: Entra ID (formerly Azure AD) tokens for Azure Database for PostgreSQL, via azidentity.DefaultAzureCredential's normal resolution chain (env vars, workload identity, managed identity, Azure CLI). Construction is credential-free (lazy resolution deferred to GetToken), so it's unit-tested the same way the AWS backend is. - DynamicAuthGCPCloudSQLIAM: OAuth2 tokens for GCP Cloud SQL IAM database authentication, minted from ambient Application Default Credentials. This is the direct-TCP token-swap path, not the Cloud SQL Go connector (cloudsqlconn) — it requires the instance to have a reachable IP and does not get Cloud SQL's automatic mTLS tunnel; that's a deliberately separate, larger piece of work (a DialFunc-based extension point, not a BeforeConnect password swap), tracked in #261 as a follow-up. Unlike AWS/Azure, google.DefaultTokenSource resolves credentials eagerly rather than lazily, so its outcome is environment-dependent — this backend has no invocation-level unit test, and the comment at the bottom of azuread_test.go explains why, rather than silently omitting it. - Config.Validate, NewAuthToken, and NewDynamicAuthFunc's per-backend dispatch is generalized via singleDynamicAuthBackend/ countDynamicAuthBackends, which also newly rejects a config with more than one backend set (previously unreachable with only one backend to choose from). Closes #261.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #261.
Summary
Adds two dynamic-auth backends alongside the existing AWS RDS IAM one, and generalizes the backend-dispatch plumbing (
Config.Validate,NewAuthToken,NewDynamicAuthFunc) to support three backends cleanly viasingleDynamicAuthBackend/countDynamicAuthBackends, instead of a single hardcoded AWS check. This also newly rejects a config with more than one backend set — previously unreachable with only one backend to choose from, but a real ambiguity risk now that there are three.DynamicAuthAzureAD— Entra ID (formerly Azure AD) tokens for Azure Database for PostgreSQL, viaazidentity.DefaultAzureCredential's normal resolution chain (env vars, workload identity, managed identity, Azure CLI —AZURE_CLIENT_IDselects a user-assigned managed identity). SameBeforeConnecttoken-swap shape as AWS RDS IAM.DynamicAuthGCPCloudSQLIAM— OAuth2 tokens for GCP Cloud SQL IAM database authentication, minted from ambient Application Default Credentials. This is the direct-TCP token-swap path, not the Cloud SQL Go connector (cloudsqlconn): it requires the instance to have a reachable IP and does not get Cloud SQL's automatic mTLS tunnel. The connector is a structurally different piece of work (needs aDialFunc-based extension point this package doesn't have, not aBeforeConnectpassword swap) — deliberately out of scope here, per postgres: add Azure AD and GCP Cloud SQL IAM dynamic-auth backends #261.Testing notes (read before assuming symmetry between the two backends)
azidentity.NewDefaultAzureCredential's construction is credential-free — resolution is deferred to the firstGetTokencall — soazureADBeforeConnectis unit-tested the same wayawsRDSIAMBeforeConnectalready is (asserts a non-nil hook is returned; never invokes it, since invocation needs real credentials).google.DefaultTokenSourceresolves Application Default Credentials eagerly and errors immediately when none are found, unlike AWS/Azure. That makes even "does the constructor return a non-nil hook" environment-dependent — a machine with real GCP credentials configured would get a different result than this dev sandbox did. So there's deliberately no equivalent invocation-level test for the GCP backend; the comment at the bottom ofazuread_test.goexplains why, rather than silently omitting coverage with no trace of the decision.Verification
go build ./...,go vet ./...,golangci-lint run ./...— all clean.go test ./postgres/...— all pass, including new cases for both backends and the multi-backend-configured rejection.govulncheck ./postgres/...— no vulnerabilities in code added by this PR (one pre-existing, already-trackedgolang.org/x/crypto/openpgpfinding unrelated to this change and not reachable from it — see issue Drop the GO-2026-5932 openpgp exclusion once rekor releases the migration #231).go mod tidyrun;azcore/azidentitypromoted from indirect to direct deps;golang.org/x/oauth2/googleneeded no new module dependency (already required at v0.36.0).Not in this PR
cloudsqlconn) — separate design decision per postgres: add Azure AD and GCP Cloud SQL IAM dynamic-auth backends #261.toolhive-registry-server's independent dynamic-auth implementation onto this package — flagged in postgres: add Azure AD and GCP Cloud SQL IAM dynamic-auth backends #261, unaddressed here.