Skip to main content

No project description provided

Project description

Azure Auth PgBouncer

Azure Auth PgBouncer is designed to make securing connections to Azure PostgreSQL databases with Entra ID a breeze.

It was inspired by the GCP Cloud SQL Auth Proxy, but instead of doing the hard work of proxying the traffic, it orchestrates PgBouncer to do it instead by rotating an access token and updating its configuration accordingly.

Installation

pipx

pipx install azure-auth-pgbouncer

Docker

docker pull ghcr.io/mmalecki/azure-auth-pgbouncer:latest

Usage

Locally

When starting Azure Auth PgBouncer locally, you will need to start the two processes (PgBouncer and token refresher) separately.

First, fire up the token refresher:

PID_FILE=pgbouncer.pid AUTH_FILE=users.txt PGUSER=<identity-name> azure-auth-pgbouncer

Then, once it's fetched its first token and users.txt appears in the directory, configure PgBouncer in a file named pgbouncer.ini, for example:

[databases]
* = host=<azure-postgresql-database-host>

[pgbouncer]
pool_mode = session
listen_port = 5432
listen_addr = 127.0.0.1
auth_type = trust
auth_file = users.txt
pidfile = pgbouncer.pid
server_tls_sslmode = verify-full

and launch it:

pgbouncer pgbouncer.ini

Please note that the database host needs to be accessible over network - this project only handles authentication, not network traversals. However, with server_tls_sslmode set to require (as opposed to verify-full), you should see no issues connecting to a proxy set up by, say, kubectl port-forward.

Additionally, PgBouncer limits the maximum password length to 2048 characters. The Azure CLI credential can be longer than that. In this case, you can expect to see the following error in PgBouncer logs:

ERROR password too long in auth file

With cloud use being the primary focus of this project, fixing this issue hasn't been a priority.

Docker

Due to the tight integration, PgBouncer and the token refresher come bundled in a single Docker container.

docker run -e PGHOST=<azure-postgresql-database-host> -e PGUSER=<identity-name> -it ghcr.io/mmalecki/azure-auth-pgbouncer:latest

No additional configuration is needed - the pgbouncer.ini file is generated by container's entrypoint.

On Kubernetes

As a sidecar

Add the following init container to your deployment/statefulset/...:

      initContainers:
        - name: azure-auth-pgbouncer
          image: ghcr.io/mmalecki/azure-auth-pgbouncer:v0.1.1
          imagePullPolicy: IfNotPresent
          restartPolicy: Always
          ports:
          - containerPort: 5432
            protocol: TCP
          env:
          - name: PGHOST
            value: <azure-postgresql-database-host>
          - name: PGUSER
            value: <identity-name>

As a deployment/statefulset/...

This method creates an unauthenticated PostgreSQL endpoint in your cluster, where only method of checking identity used is verifying the username. This may be fine for your use case, but you've been warned either way.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

azure_auth_pgbouncer-0.2.1.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

azure_auth_pgbouncer-0.2.1-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file azure_auth_pgbouncer-0.2.1.tar.gz.

File metadata

  • Download URL: azure_auth_pgbouncer-0.2.1.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.12.10 Linux/6.12.38+deb13-amd64

File hashes

Hashes for azure_auth_pgbouncer-0.2.1.tar.gz
Algorithm Hash digest
SHA256 a59ab5b5b978c877b3a708736fb4be8544a73639ca209bb2b2f843e5787b8933
MD5 f78bb5abf83e080299a5a5319708168c
BLAKE2b-256 9106ff599f9b0bd6d21c77fe90043519cc039ab590417bbf7a59f62c0160ae09

See more details on using hashes here.

File details

Details for the file azure_auth_pgbouncer-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: azure_auth_pgbouncer-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.12.10 Linux/6.12.38+deb13-amd64

File hashes

Hashes for azure_auth_pgbouncer-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 eba6158757fb49dc093921665cb76c9fc9d04d08c2dc8a49876903bc964fb8f1
MD5 16c6709035267085c6e9c52f9fe5c484
BLAKE2b-256 1d6e3f107d8e9c97e4214384403d147755e3ac071ae443ad0d5c95a2490efe76

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page