Skip to content

Commit 27756ce

Browse files
authored
fix(goose): remove unsupported role startup option from connection string (#6312)
Removes `options=-crole=cloudsqlsuperuser` from the `goose` PostgreSQL connection string in `docker/goose/entrypoint.bash` (which is rejected by Cloud SQL / PgBouncer as an unsupported startup parameter) and documents configuring `ALTER ROLE ... SET role = 'cloudsqlsuperuser'` in `deployment/README.md`. <!-- AI-PR --> agy
1 parent 942b1c1 commit 27756ce

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

‎deployment/README.md‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,19 @@ Database schema migrations live in `go/internal/database/postgres/migrations/` a
9292
* **Staging (`oss-vdb-test`)**: Applied automatically by `build-and-stage.yaml` right after `terraform apply` using the `gcr.io/oss-vdb/goose` Cloud Builder image (see `docker/goose/`).
9393
* **Production (`oss-vdb` & `private-osv`)**: Applied automatically by `deploy-prod.yaml` at the release `$COMMIT_SHA` right before promoting the Cloud Deploy pipelines.
9494

95+
After the initial `terraform apply` creates the `deployment@oss-vdb.iam` Cloud SQL user on an instance, set its default login role to `cloudsqlsuperuser` once per instance (so tables created by CI/CD migrations are owned by the shared `cloudsqlsuperuser` role):
96+
97+
```bash
98+
# In one terminal (use us-central1 for oss-vdb / oss-vdb-test, or us-west2 for private-osv):
99+
cloud-sql-proxy "${PROJECT_ID}:us-central1:osv-db" \
100+
--auto-iam-authn \
101+
--impersonate-service-account=deployment@oss-vdb.iam.gserviceaccount.com
102+
103+
# In another terminal:
104+
psql "host=127.0.0.1 port=5432 user=deployment@oss-vdb.iam dbname=osv sslmode=disable" \
105+
-c 'ALTER ROLE "deployment@oss-vdb.iam" SET role = '\''cloudsqlsuperuser'\'';'
106+
```
107+
95108
To connect or run `goose` manually from your workstation via IAM authentication:
96109

97110
1. Install `cloud-sql-proxy` (via `gcloud components install cloud-sql-proxy`, `go install github.com/GoogleCloudPlatform/cloud-sql-proxy/v2@latest`, or the [standalone binary](https://cloud.google.com/sql/docs/postgres/connect-instance-auth-proxy#install)).
@@ -108,10 +121,15 @@ To connect or run `goose` manually from your workstation via IAM authentication:
108121
# Use us-central1 for oss-vdb / oss-vdb-test, or us-west2 for private-osv
109122
cloud-sql-proxy "${PROJECT_ID}:us-central1:osv-db" --auto-iam-authn
110123
```
111-
4. Run `goose` (if needed, setting `role=cloudsqlsuperuser` so any created/altered objects remain owned by `cloudsqlsuperuser`):
124+
4. Set your IAM user's default login role to `cloudsqlsuperuser` (once per instance):
125+
```bash
126+
psql "host=127.0.0.1 port=5432 user=$(gcloud config get-value account) dbname=osv sslmode=disable" \
127+
-c "ALTER ROLE \"$(gcloud config get-value account)\" SET role = 'cloudsqlsuperuser';"
128+
```
129+
5. Run `goose`:
112130
```bash
113131
goose -dir go/internal/database/postgres/migrations postgres \
114-
"host=127.0.0.1 port=5432 user=$(gcloud config get-value account) dbname=osv sslmode=disable options=-crole=cloudsqlsuperuser" \
132+
"host=127.0.0.1 port=5432 user=$(gcloud config get-value account) dbname=osv sslmode=disable" \
115133
status
116134
```
117135

‎docker/goose/entrypoint.bash‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ if [[ -n "${CLOUDSQL_INSTANCE:-}" ]]; then
4848
db_user="${PGUSER:-${active_account%.gserviceaccount.com}}"
4949
db_name="${PGDATABASE:-osv}"
5050
export GOOSE_DRIVER="${GOOSE_DRIVER:-postgres}"
51-
export GOOSE_DBSTRING="${GOOSE_DBSTRING:-host=127.0.0.1 port=5432 user=${db_user} dbname=${db_name} sslmode=disable options=-crole=cloudsqlsuperuser}"
51+
export GOOSE_DBSTRING="${GOOSE_DBSTRING:-host=127.0.0.1 port=5432 user=${db_user} dbname=${db_name} sslmode=disable}"
5252
fi
5353

5454
echo "Running: goose $*"

0 commit comments

Comments
 (0)