An authentication proxy for Google Cloud managed databases

db-auth-gateway

db-auth-gateway

An authentication proxy for Google Cloud managed databases. Based on the ideas of cloudsql-proxy but intended to be run as a standalone network accessible service rather than a sidecar.

We've been using cloudsql-proxy for several years now to power our db-operator project. It has been for the most part reliable but key differences between how we deploy it and Google's reference architecture have led to production issues.

We developed db-auth-gateway to address these issues and add a variety of wish list features such as improved observability, and testing.

Features

  • Connection draining during shutdown to support zero downtime deployments and load balancing.
  • Prometheus metrics support for improved observability.
  • Full testsuite including realistic Google service mocks.
  • Simplified modern code base.

Quickstart

Use docker-compose to start a local PostgreSQL instance, and Google API mock:

make start_mock

Then you can then run db-auth-gateway locally with:

db-auth-gateway --api-endpoint=http://localhost:8080 --credential-file=DISABLED \
--instance=my-project:my-region:my-database

db-auth-gateway will listen on port 5432 (by default) for SQL connections.

PGPASSWORD=mysecretpassword psql -h localhost -p 5432 -d postgres postgres

Flags

db-auth-gateway has a variety of command line flags for configuring its behavior:

Flag Default Description
--credential-file JSON file containing the Google Cloud credentials
--instance Fully qualified database instance to connect to (project:region:name)
--listen :5432 Address and port to listen on
--remote-port 3307 Port to connect to the remote server on
--max-connections 0 The maximum number of active connections. Defaults to 0 (unlimited)
--min-refresh-interval 1m The minimum amount of time to wait between API calls
--periodic-refresh-interval 5m Configuration is eagerly refreshed on a schedule. This is the nominal period between API calls.
--api-endpoint If specified the URL to use for API calls

Development

Prerequisites

Build

To build db-auth-gateway, simply run make without any arguments.

The resulting binary will be written to: ./target/db-auth-gateway.

make

Test

Before committing any code you should always lint and test your changes.

Code Linting

make lint

Running the Tests

First start the Google API mock using docker-compose:

make start_mock

Then run the tests:

make test

End to End Testing

You run the end to end tests with:

make e2e

The tests will start a local instance of db-auth-gateway and verify it is able to connect to and query the Postgres database, and Google API mock.

Acknowledgements

  1. The Go Gopher by Renee French, licensed under the CC BY 3.0.
  2. https://github.com/GoogleCloudPlatform/cloudsql-proxy
  3. https://github.com/jbenet/go-context
Similar Resources

Dbt-postgres-proxy - Proxy server which intercepts and compiles dbt queries on the fly

Dbt-postgres-proxy - Proxy server which intercepts and compiles dbt queries on the fly

dbt-postgres-proxy A reverse proxy for postgres which compiles queries in flight

Mar 4, 2022

Local proxy for authenticating requests to Cloud Run

Cloud Run Proxy is a small proxy to assist in authenticating as an end-user to Google Cloud Run. It leverages Cloud Run's existing Clo

Dec 21, 2022

Certificate authority and access plane for SSH, Kubernetes, web applications, and databases

Teleport is an identity-aware, multi-protocol access proxy which understands SSH, HTTPS, Kubernetes API, MySQL and PostgreSQL wire protocols.

Jan 9, 2023

Authenticating using Workload Identity Federation to Cloud Run, Cloud Functions

Authenticating using Workload Identity Federation to Cloud Run, Cloud Functions

Authenticating using Workload Identity Federation to Cloud Run, Cloud Functions This tutorial and code samples cover how customers that use Workload i

Dec 3, 2022

Go-Guardian is a golang library that provides a simple, clean, and idiomatic way to create powerful modern API and web authentication.

❗ Cache package has been moved to libcache repository Go-Guardian Go-Guardian is a golang library that provides a simple, clean, and idiomatic way to

Dec 23, 2022

Go login handlers for authentication providers (OAuth1, OAuth2)

Go login handlers for authentication providers (OAuth1, OAuth2)

gologin Package gologin provides chainable login http.Handler's for Google, Github, Twitter, Facebook, Bitbucket, Tumblr, or any OAuth1 or OAuth2 auth

Dec 30, 2022

Package goth provides a simple, clean, and idiomatic way to write authentication packages for Go web applications.

Goth: Multi-Provider Authentication for Go Package goth provides a simple, clean, and idiomatic way to write authentication packages for Go web applic

Dec 29, 2022

HTTP Authentication middlewares

goji/httpauth httpauth currently provides HTTP Basic Authentication middleware for Go. It is compatible with Go's own net/http, goji, Gin & anything t

Dec 23, 2022

[DEPRECATED] Go package authcookie implements creation and verification of signed authentication cookies.

Package authcookie import "github.com/dchest/authcookie" Package authcookie implements creation and verification of signed authentication cookies. Co

Dec 22, 2022
Comments
  • Ability to use as a library

    Ability to use as a library

    As currently written, all the logic lives inside /internal, which makes sense to limit your api exposure. How do you feel about potentially making at least some portion public for use as a library? I'm currently investigating the feasibility in the Vitess project. https://github.com/vitessio/vitess/issues/8103

A reverse proxy that provides authentication with Google, Github or other providers.
A reverse proxy that provides authentication with Google, Github or other providers.

A reverse proxy and static file server that provides authentication using Providers (Google, GitHub, and others) to validate accounts by email, domain

Jan 1, 2023
Authelia: an open-source authentication and authorization server providing two-factor authentication
Authelia: an open-source authentication and authorization server providing two-factor authentication

Authelia is an open-source authentication and authorization server providing two

Jan 5, 2022
Authentication Plugin for implementing Form-Based, Basic, Local, LDAP, OpenID Connect, OAuth 2.0, SAML Authentication
Authentication Plugin for implementing Form-Based, Basic, Local, LDAP, OpenID Connect, OAuth 2.0, SAML Authentication

Authentication Plugin for implementing Form-Based, Basic, Local, LDAP, OpenID Connect, OAuth 2.0, SAML Authentication

Jan 8, 2023
A simple passwordless authentication middleware that uses only email as the authentication provider
A simple passwordless authentication middleware that uses only email as the authentication provider

email auth A simple passwordless authentication middleware that uses only email as the authentication provider. Motivation I wanted to restrict access

Jul 27, 2022
Authorization and authentication. Learning go by writing a simple authentication and authorization service.

Authorization and authentication. Learning go by writing a simple authentication and authorization service.

Aug 5, 2022
Golang Skeleton With Fully Managed Versions For Kick Start GoLang Project Development
Golang Skeleton With Fully Managed Versions For Kick Start GoLang Project Development

Golang Skeleton With Fully Managed Versions For Kick Start GoLang Project Development There is no doubt that Golang’s good documentation and intellige

Dec 31, 2022
Oct 8, 2022
Server bridging Google's OAuth and service using Radius for authentication

Fringe Fringe is an easy workaround for Google Workplace users who need a Radius server to perform authentication on behalf of other services (e.g. 80

Mar 7, 2022
A simple passwordless proxy authentication middleware using email.
A simple passwordless proxy authentication middleware using email.

email proxy auth A simple passwordless proxy authentication middleware that uses only email as the authentication provider. Motivation I wanted to res

Jul 27, 2022
A standalone reverse-proxy to enforce Webauthn authentication
A standalone reverse-proxy to enforce Webauthn authentication

A standalone reverse-proxy to enforce Webauthn authentication. It can be inserted in front of sensitive services or even chained with other proxies (e

Dec 24, 2022