Skip to content

Commit aeb85d9

Browse files
committed
fix(postgres/iam): explicitly set billing-project flag for projects subcommands
All invocations to Google Cloud APIs must be attributed to a project, subject to billing and quotas. The `projects` subcommand invokes an API that is _non-resource-oriented_, which means that the API doesn't have a clear association with a Google project. When using this subcommand in the `gcloud` CLI, usage will thus be attributed to the client's project, as we're authenticating using its OAuth client ID. This is of course owned by a Google controlled project, namely `project_number:32555940559`. As the client and project is shared by all installations of gcloud, this means that everyone is subject to the same quotas for that project. To alleviate resource quota issues, we set the `--billing-project` flag explicitly for relevant `gcloud projects` subcommands to the same project that is operated on. See also https://jpassing.com/2022/10/31/which-project-quota-are-my-api-calls-charged-against/.
1 parent 3864e8a commit aeb85d9

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

pkg/postgres/iam.go

+3
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ func grantUserAccess(ctx context.Context, projectID, role string, duration time.
103103
projectID,
104104
"--member", "user:" + email,
105105
"--role", role,
106+
"--billing-project", projectID,
106107
}
107108

108109
if duration > 0 {
@@ -130,6 +131,7 @@ func cleanupPermissions(ctx context.Context, projectID, email, role, conditionNa
130131
"get-iam-policy",
131132
projectID,
132133
"--format", "json",
134+
"--billing-project", projectID,
133135
}
134136
cmd := exec.CommandContext(ctx, "gcloud", args...)
135137
out, err := cmd.Output()
@@ -173,6 +175,7 @@ OUTER:
173175
"--member", "user:" + email,
174176
"--role", role,
175177
"--condition", expr,
178+
"--billing-project", projectID,
176179
}
177180
cmd = exec.CommandContext(ctx, "gcloud", args...)
178181
buf := &bytes.Buffer{}

0 commit comments

Comments
 (0)