Skip to content

Fix CLoud Build SA#130

Merged
haroonc merged 1 commit intomainfrom
cb-fix
Apr 12, 2026
Merged

Fix CLoud Build SA#130
haroonc merged 1 commit intomainfrom
cb-fix

Conversation

@yeshwanth1993
Copy link
Copy Markdown
Contributor

Fixes #<issue_number_goes_here>

It's a good idea to open an issue first for discussion.

  • Tests pass
  • Appropriate changes to documentation are included in the PR

@yeshwanth1993 yeshwanth1993 requested a review from haroonc April 12, 2026 15:42
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the Cloud Build setup to grant the Cloud Build Service Agent impersonation permissions on the user-provided service account and removes the unused roles/cloudbuild.workerpools.use role. Feedback identifies a critical API incompatibility where project-level IAM methods are incorrectly applied to service account resources, and suggests removing the serviceAccount: prefix from the returned string to ensure compatibility with the Cloud Build API. Additionally, the service account validation logic is noted as being too restrictive for project IDs containing dots or colons.

return "", fmt.Errorf("unable to add iam.serviceAccountUser role to Cloud Build P4SA %s on SA %s err: %w", gcbP4sa, r, err)
}

return resolvedSA, nil
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The function currently returns resolvedSA, which includes the serviceAccount: prefix. However, the Cloud Build API's serviceAccount field for triggers expects either the service account email address or its full resource path, not the IAM member string format. Providing the prefix will likely cause the subsequent CreateBuildTrigger call to fail with an invalid argument error.

Suggested change
return resolvedSA, nil
return strings.TrimPrefix(resolvedSA, "serviceAccount:"), nil

Comment on lines +130 to +135
{"valid sa", "serviceAccount:test-sa@project.iam.gserviceaccount.com", true},
{"valid sa with dashes", "serviceAccount:my-sa-123@my-project-456.iam.gserviceaccount.com", true},
{"missing prefix", "test-sa@project.iam.gserviceaccount.com", false},
{"wrong prefix", "user:test-sa@project.iam.gserviceaccount.com", false},
{"missing domain", "serviceAccount:test-sa@project", false},
{"wrong domain", "serviceAccount:test-sa@project.com", false},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The validation logic for service accounts (and these corresponding tests) appears to be too restrictive. Google Cloud project IDs can contain dots and colons (e.g., for domain-scoped projects like example.com:my-project). The current regex [a-z0-9-]+ used in the implementation will reject valid service accounts from such projects. Consider updating the regex to support these valid project ID formats.

@haroonc haroonc merged commit 07b8efb into main Apr 12, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants