Cloud SQL Auth Proxy
$ cloud-sql-proxy 官方出品 低风险Cloud SQL Auth Proxy(cloud-sql-proxy)基于 Google IAM 凭证为 Cloud SQL PostgreSQL、MySQL 与 SQL Server 建立加密 TLS 隧道,无需配置公网 IP 白名单或静态证书。支持 --port、--auto-iam-authn 与 --structured-logs JSON 日志输出。
brew install cloud-sql-proxy cloud-sql-proxy 在本地绑定 TCP/Unix 套接字隧道供 psql/mysql 等客户端连接,属于网络传输守护进程而非 MCP 工具。
Agent 友好度体检单
当前为静态评估(本机尚未安装或尚未运行探针)。可在本地运行 npm run data:probe 并提交 data/probes/ 升级为实测证据。
FCRS-1.0 六维评分拆解
支持确定性的非交互参数(--port、--structured-logs、--auto-iam-authn),但本身是常驻前台隧道进程而非一次性查询 CLI。
- Supports
--structured-logsfor JSON log entries - Long-running daemon requires background execution (
IsDaemon) by agents
强制 mTLS 与 Google IAM 认证,避免数据库暴露公网端口或依赖静态密码。
- Replaces IP allowlisting with IAM-scoped TLS tunneling
静态 Go 单二进制,支持 Homebrew 与 macOS/Linux/Windows 官方下载。
- Available via
brew install cloud-sql-proxy
是本地 psql、mysql 与迁移工具安全连接 Cloud SQL 的标准桥梁。
- Supports automatic engine port detection and IAM DB login (
--auto-iam-authn)
Google Cloud 官方维护(GoogleCloudPlatform/cloud-sql-proxy),Apache-2.0 协议。
- Official GoogleCloudPlatform repository under Apache-2.0
Google Cloud 文档、README 与 --help 参考完整,但需注意 v1 与 v2 参数语法差异。
- Official Google Cloud documentation and GitHub README
安全边界、鉴权与放权指南
使用 Google 应用默认凭证(GOOGLE_APPLICATION_CREDENTIALS、gcloud auth application-default login 或 GCE/GKE 工作负载身份)。
Apache-2.0 开源代理免费;仅连接到已有的计费 Cloud SQL 实例。
# Cloud SQL Auth Proxy Agent Rules - Always start `cloud-sql-proxy` as a background daemon with explicit `--port` and `--structured-logs`. - Kill the proxy background task when finished; never hardcode service account JSON paths into repo files.
Agent 高频安全命令配方
只读查询(安全推荐)
cloud-sql-proxy --version
输出 v2 代理版本号而不开启本地网络监听。
cloud-sql-proxy my-project:us-central1:my-db --port 5432 --structured-logs --auto-iam-authn
在本地 5432 端口建立带 IAM 认证的 TLS 隧道并输出 JSON 日志行。
核心优势
- + 用 IAM 认证 TLS 隧道替代繁琐的公网 IP 白名单配置。
- +
--structured-logs提供可解析的 JSON 状态与连接日志。 - + 零依赖静态 Go 二进制。
注意事项与踩坑点
- ! 作为网络代理常驻运行,Agent 必须以后台守护模式启动并在用完后关闭。
- ! v2 位置参数语法(
cloud-sql-proxy <instance>)与旧版 v1(-instances=...)不兼容。