proxy

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2026 License: Apache-2.0 Imports: 17 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package proxy is the Cloud SQL in-container agent (FR-SQL-004..007). It is the entrypoint of every instance container: it starts PostgreSQL (the image's docker-entrypoint.sh, listening on 127.0.0.1:5433 and a unix socket) as a child process, waits until it accepts TCP connections, and then serves

  • :5432, a PostgreSQL-protocol-aware proxy that terminates TLS per the instance's SSL mode, asks the emulator whether the connection is allowed (authorized networks, SSL mode, connector enforcement), and either passes BUILT_IN users through to PostgreSQL (SCRAM over 127.0.0.1) or performs IAM database authentication and logs the user in over the unix socket (trust);
  • :3307, the Cloud SQL connector / Auth Proxy server side: TLS 1.3 with the instance's server certificate and a required client certificate signed by the instance's client CA, followed by the same logic.

Decisions are made by the emulator through a small HTTP endpoint (see LoginRequest) so that changes to authorized networks, users and IAM policies apply immediately.

Index

Constants

View Source
const (
	EnvControl = "GCPEMU_SQL_CONTROL" // base URL of the emulator's agent endpoint
	EnvKey     = "GCPEMU_SQL_KEY"     // per-instance shared secret
	KeyHeader  = "X-Gcpemu-Agent-Key"

	Dir          = "/gcpemu"
	ServerCert   = "server.crt" // server certificate chain (PEM)
	ServerKey    = "server.key"
	ClientCA     = "client-ca.crt"
	HBAFile      = "pg_hba.conf"
	SocketDir    = "/var/run/postgresql"
	InternalPort = 5433
	PublicPort   = 5432
	ConnectPort  = 3307
)

Environment variables and files the emulator provides to the agent.

View Source
const (
	ListenerDirect    = "direct"    // :5432
	ListenerConnector = "connector" // :3307
)

Listener names used in LoginRequest.

View Source
const (
	ActionDeny        = "deny"        // send Message as a FATAL error
	ActionPassthrough = "passthrough" // relay to PostgreSQL over TCP (password auth)
	ActionPassword    = "password"    // ask for a cleartext password, then call again
	ActionTrust       = "trust"       // authenticated: log in over the unix socket
)

Actions returned by the emulator.

View Source
const Name = "sql-proxy"

Name is the agent name registered with internal/agent.

Variables

View Source
var SSLRequest = []byte{0, 0, 0, 8, 0x04, 0xd2, 0x16, 0x2f}

SSLRequest is the 8-byte SSLRequest packet (used by readiness probes).

Functions

func Main

func Main(ctx context.Context, _ []string) error

Main is the agent entry point.

func PGCommand

func PGCommand() []string

PGCommand is the command line the agent runs for PostgreSQL.

Types

type LoginRequest

type LoginRequest struct {
	Listener string `json:"listener"`
	Local    string `json:"local"`  // local IP the client connected to
	Remote   string `json:"remote"` // client source IP
	TLS      bool   `json:"tls"`
	// ClientCert is the verified client certificate (DER), if any.
	ClientCert []byte `json:"clientCert,omitempty"`
	User       string `json:"user"`
	Database   string `json:"database"`
	// Password is set on the second call, after a cleartext password request.
	Password *string `json:"password,omitempty"`
}

LoginRequest is sent by the agent for every client startup message.

type LoginResponse

type LoginResponse struct {
	Action  string `json:"action"`
	Code    string `json:"code,omitempty"` // SQLSTATE for deny
	Message string `json:"message,omitempty"`
}

LoginResponse is the emulator's decision.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL