Skip to content

feat(go): add PGAdapter for PostgreSQL wire protocol proxy to DSQL#320

Draft
amaksimo wants to merge 7 commits intomainfrom
feature/dsql-pgadapter
Draft

feat(go): add PGAdapter for PostgreSQL wire protocol proxy to DSQL#320
amaksimo wants to merge 7 commits intomainfrom
feature/dsql-pgadapter

Conversation

@amaksimo
Copy link
Contributor

Summary

Adds a PostgreSQL wire protocol proxy (PGAdapter) that allows unmodified PostgreSQL clients like OpenFGA to connect to Aurora DSQL with automatic IAM authentication.

Problem: OpenFGA and other PostgreSQL clients use pgxpool.ParseConfig() which only recognizes postgres:// and postgresql:// schemes. When given a dsql:// URL, pgx falls back to Unix socket connections which fail.

Solution: A lightweight TCP proxy that:

  • Accepts standard PostgreSQL connections on localhost
  • Handles client authentication locally (no password required)
  • Connects to DSQL with IAM token authentication
  • Proxies all PostgreSQL wire protocol messages bidirectionally

This follows the same pattern as Google Spanner's PGAdapter.

Changes

  • dsql/token.go: Export ResolveCredentialsProvider for reuse by pgadapter
  • pgadapter/: New package implementing the PostgreSQL wire protocol proxy
    • config.go - Configuration types
    • adapter.go - Core adapter with ListenAndServe()
    • proxy.go - PostgreSQL protocol handling
    • adapter_test.go - Unit tests
  • cmd/dsql-pgadapter/: CLI command
  • example/test/pgadapter/: E2E integration test against real DSQL cluster
  • .github/workflows/go-pgx-integ-tests.yml: Updated CI to run pgadapter tests

Usage

# Build
go build -o bin/dsql-pgadapter ./cmd/dsql-pgadapter

# Start adapter
./bin/dsql-pgadapter --endpoint xxx.dsql.us-east-1.on.aws

# Connect with any PostgreSQL client (unchanged)
psql -h 127.0.0.1 -p 5432 -U admin -d postgres

# Or run OpenFGA (unchanged)
openfga run --datastore-uri "postgres://[email protected]:5432/postgres?sslmode=disable"

Test plan

  • Unit tests pass locally (go test ./pgadapter/...)
  • Unit tests pass locally (go test ./dsql/...)
  • E2E integration test passes against real DSQL cluster (CI will verify)
  • Manual test with OpenFGA (pending CI success)

Export ResolveCredentialsProvider with explicit parameters (region,
profile, customProvider) instead of the internal resolvedConfig struct.
This allows the pgadapter package to resolve credentials using the same
logic without depending on internal types.
Add pgadapter package that proxies PostgreSQL wire protocol to
Aurora DSQL with transparent IAM authentication. Clients connect
without credentials; the adapter handles token generation.
Add dsql-pgadapter CLI that provides a PostgreSQL wire protocol proxy
for Aurora DSQL. The CLI includes:
- Version flag (1.0.0)
- Required --endpoint flag for DSQL cluster endpoint
- Optional --region, --listen, --user, --database, --profile flags
- Verbose logging with --verbose flag
- Graceful shutdown on SIGINT/SIGTERM
Add tests for the pgadapter.New() function covering:
- Valid configuration with defaults applied
- Missing DSQLEndpoint error handling
- Invalid endpoint that cannot be parsed for region
- Custom configuration values override defaults
Add end-to-end integration test for pgadapter that:
- Starts adapter on random port (127.0.0.1:0)
- Polls for adapter ready state (up to 5 seconds)
- Connects using standard pgx (simulates OpenFGA)
- Tests SELECT 1, CREATE TABLE, INSERT, SELECT, DROP TABLE
- Verifies clean shutdown

Also adds testify dependency and local module replace directive
for development.
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.

2 participants