You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Enforce dedicated service account for Cloud Build triggers (#110)
* feat: enforce mandatory SA, slim down roles, and avoid using compute engine default SA
* feat: implement minimum required permissions for Cloud Build SA and Service Agents
Copy file name to clipboardExpand all lines: cicd-mcp-server/cloudbuild/cloudbuild.go
+55-16Lines changed: 55 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -91,7 +91,7 @@ type CreateTriggerArgs struct {
91
91
Locationstring`json:"location" jsonschema:"The Google Cloud location for the trigger."`
92
92
TriggerIDstring`json:"trigger_id" jsonschema:"The ID of the trigger."`
93
93
RepoLinkstring`json:"repo_link" jsonschema:"The Developer Connect repository link, use dev connect setup repo to create a connect and repo link"`
94
-
ServiceAccountstring`json:"service_account,omitempty" jsonschema:"The service account to use for the build. E.g. serviceAccount:name@project-id.iam.gserviceaccount.com optional"`
94
+
ServiceAccountstring`json:"service_account" jsonschema:"The service account to use for the build. E.g. serviceAccount:name@project-id.iam.gserviceaccount.com. This MUST be a dedicated service account, not the default Compute Engine service account."`
95
95
Branchstring`json:"branch,omitempty" jsonschema:"Create builds on push to branch. Should be regex e.g. '^main$'"`
96
96
Tagstring`json:"tag,omitempty" jsonschema:"Create builds on new tag push. Should be regex e.g. '^nightly$'"`
97
97
}
@@ -100,10 +100,13 @@ var createTriggerToolFunc func(ctx context.Context, req *mcp.CallToolRequest, ar
Copy file name to clipboardExpand all lines: skills/google-cicd-pipeline-design/references/how_to_create_cloudbuild_trigger.md
+15-7Lines changed: 15 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,24 +4,24 @@ This document outlines the standard, idempotent procedure for creating a Google
4
4
5
5
---
6
6
7
-
## ## Core Principle: Idempotency
7
+
## Core Principle: Idempotency
8
8
9
9
Every step in this process must be **idempotent**. This means the agent must **always check if a resource already exists** before attempting to create it. This prevents errors and ensures the process can be run multiple times safely.
10
10
11
11
---
12
12
13
-
## ## Prerequisite Checklist
13
+
## Prerequisite Checklist
14
14
15
15
The following dependencies must be satisfied in order before creating the trigger.
16
16
17
-
### ### 1. Ensure `cloudbuild.yaml` Exists
17
+
### 1. Ensure `cloudbuild.yaml` Exists
18
18
19
19
The trigger needs a build configuration file to execute.
20
20
21
21
***Action**: Check for a `cloudbuild.yaml` file at the root of the source repository.
22
22
***If it does not exist**: Generate one by translating the user-approved plan. The steps in the generated YAML must be a direct translation of the components defined in the plan's `stages` object. The specifics of the steps (e.g., using `pytest` vs. `mvn test`) should be informed by discovering the application archetype (e.g., by finding a `pyproject.toml` or `pom.xml`).
The `cloudbuild.yaml` file will reference an Artifact Registry repository to push container images. This repository must exist before a build can succeed.
27
27
@@ -30,7 +30,7 @@ The `cloudbuild.yaml` file will reference an Artifact Registry repository to pus
30
30
***Check** if this repository already exists in the target GCP project.
31
31
***If it does not exist**: Create it using the available tools.
32
32
33
-
### ### 3. Ensure Developer Connect and Repository Link Exist
33
+
### 3. Ensure Developer Connect and Repository Link Exist
34
34
35
35
Cloud Build triggers connect to source code via Developer Connect. The entire connection and repository link must be in place.
36
36
@@ -40,8 +40,16 @@ Cloud Build triggers connect to source code via Developer Connect. The entire co
40
40
4.**Check for Repository Link**: Check if a repository link for that specific URI already exists within the Developer Connect connection.
41
41
5.**Create Repository Link (if needed)**: If the link does not exist, create it. This link is the resource that the Cloud Build trigger will formally point to.
42
42
43
+
### 4. Ensure Dedicated Service Account Exists
44
+
45
+
Cloud Build triggers should **always** use a dedicated, user-managed service account instead of the default Compute Engine service account to follow the principle of least privilege. **CRITICAL: NEVER use the default Compute Engine service account (typically formatted as `[PROJECT_NUMBER]-compute@developer.gserviceaccount.com`), even if you observe existing triggers in the project using it.**
46
+
47
+
1.**Check for Service Account**: Check if a dedicated service account for Cloud Build (e.g., `cloud-build-runner@<PROJECT_ID>.iam.gserviceaccount.com`) already exists.
48
+
2.**Create Service Account (if needed)**: If no dedicated service account exists, create one using `gcloud iam service-accounts create`.
49
+
3.**Required Roles (Ensured Automatically)**: The `create_build_trigger` MCP tool will **automatically ensure** the necessary roles (e.g., `roles/logging.logWriter`, `roles/artifactregistry.writer`, `roles/developerconnect.tokenAccessor`, `roles/run.developer`, `roles/storage.admin`, `roles/serviceusage.serviceUsageConsumer`, `roles/cloudbuild.builds.editor`, `roles/cloudbuild.workerpools.use`, and specific IAM delegation on the default Compute SA) are granted to the relevant service accounts. You **do not** need to grant these permissions manually.
50
+
43
51
---
44
52
45
-
## ## Final Step: Creating the Trigger
53
+
## Final Step: Creating the Trigger
46
54
47
-
Once all prerequisites are met, the agent can create the trigger itself using the available tools.
55
+
Once all prerequisites are met, the agent can create the trigger itself using the `create_build_trigger` tool. **You MUST provide the email of the dedicated service account identified or created in Step 4 to the `service_account` parameter.**
0 commit comments