No description
Find a file
Tauhid Anjum 1a5401859b
Merge pull request #91 from hashicorp/workload_identity
Adding support for Workload Identity in Azure
2026-01-08 11:07:17 +05:30
.github Upgrade go version to 1.24 2025-07-14 10:10:30 +05:30
.gitignore adding newline in gitignore file 2025-07-14 10:11:17 +05:30
.go-version Upgrade go version to 1.24 2025-07-14 10:10:30 +05:30
aws.go [COMPLIANCE] Update Copyright and License Headers 2025-12-09 11:06:21 +00:00
azure.go [COMPLIANCE] Update Copyright and License Headers 2025-12-09 11:06:21 +00:00
CODEOWNERS Addressing security review feedbacks 2025-04-30 13:30:16 +05:30
default.go Merge pull request #91 from hashicorp/workload_identity 2026-01-08 11:07:17 +05:30
gcp.go [COMPLIANCE] Update Copyright and License Headers 2025-12-09 11:06:21 +00:00
go.mod Bump github.com/aws/aws-sdk-go-v2/config from 1.29.18 to 1.31.2 2025-08-28 07:40:15 +00:00
go.sum Bump github.com/aws/aws-sdk-go-v2/config from 1.29.18 to 1.31.2 2025-08-28 07:40:15 +00:00
LICENSE [COMPLIANCE] Update Copyright and License Headers 2025-12-09 11:06:21 +00:00
mocks_test.go [COMPLIANCE] Update Copyright and License Headers 2025-12-09 11:06:21 +00:00
pgmultiauth.go [COMPLIANCE] Update Copyright and License Headers 2025-12-09 11:06:21 +00:00
pgmultiauth_integration_test.go [COMPLIANCE] Update Copyright and License Headers 2025-12-09 11:06:21 +00:00
pgmultiauth_test.go [COMPLIANCE] Update Copyright and License Headers 2025-12-09 11:06:21 +00:00
README.md Adding support for Workload Identity in Azure 2025-12-10 10:40:20 +05:30

go-pgmultiauth

pgmultiauth is a Go module that simplifies and streamlines authentication with PostgreSQL databases using multiple authentication methods. It provides a unified interface for connecting to PostgreSQL databases using various authentication mechanisms.

Features

  • Multiple Authentication Methods: Support for AWS, GCP, and Azure authentication.
  • Connection Management: Handles token refresh and reconnection logic automatically
  • Multiple consumption mechanism: Supports various handlers like *sql.DB, driver.Connector, *pgxpool.Pool etc

Authentication Methods

The module currently supports:

Installation

go get github.com/hashicorp/go-pgmultiauth

Usage

Using with database/sql.DB


authConfig := NewConfig(
    connString,
    WithAWSConfig(awsConfig),
)

db, err := pgmultiauth.Open(ctx, authConfig)
if err != nil {
    // handle error
}
defer db.Close()

// Use db as a standard database/sql.DB

Using with pgx connection pool

pool, err := pgmultiauth.NewDBPool(ctx, authConfig)
if err != nil {
    // handle error
}
defer pool.Close()

// Use pool as a standard pgx.Pool

Using BeforeConnect function of pgxpool.Config

beforeConnect, err := pgmultiauth.BeforeConnectFn(ctx, authConfig)
if err != nil {
    // handle error
}

poolConfig := pgxpool.Config{
    ConnConfig: connConfig,
    BeforeConnect: beforeConnect,
    ..
    ..
}

Using driver.Connector

dbConnector, err := pgmultiauth.GetConnector(ctx, dbAuthConfig)
if err != nil {
    // handle error
}

db := sql.OpenDB(dbConnector)

Contributing

Thank you for your interest in contributing! Please refer to CONTRIBUTING.md for guidance.