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 ¶
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.
const ( ListenerDirect = "direct" // :5432 ListenerConnector = "connector" // :3307 )
Listener names used in LoginRequest.
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.
const Name = "sql-proxy"
Name is the agent name registered with internal/agent.
Variables ¶
var SSLRequest = []byte{0, 0, 0, 8, 0x04, 0xd2, 0x16, 0x2f}
SSLRequest is the 8-byte SSLRequest packet (used by readiness probes).
Functions ¶
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.