Skip to content

Ensure default service account is correctly set for Genkit monitoring… - #8760

Merged
joehan merged 2 commits into
firebase:masterfrom
prabalp:genkit_serviceAccount
Jun 17, 2025
Merged

joehan merged 2 commits into
firebase:masterfrom
prabalp:genkit_serviceAccount

Conversation

@prabalp

@prabalp prabalp commented Jun 15, 2025

Copy link
Copy Markdown
Contributor

IAM bindings:Fixes issue where an empty string could result in malformed IAM member serviceAccount: by properly checking index and replacing with the default service account.

Description

This is a bug, In this block inside ensureGenkitMonitoringRoles

const serviceAccounts = newEndpoints
  .map((endpoint) => endpoint.serviceAccount || "")
  .filter((value, index, self) => self.indexOf(value) === index);

const defaultServiceAccountIndex = serviceAccounts.indexOf("");
if (defaultServiceAccountIndex) {
  serviceAccounts[defaultServiceAccountIndex] = await gce.getDefaultServiceAccount(projectNumber);
}

If the first element is an empty string (""), then:

serviceAccounts.indexOf("") === 0

And so:

if (defaultServiceAccountIndex) {
  // ← this will NOT run, because 0 is falsy in JavaScript
}

So the "" does not get replaced with the real default service account, and you end up with:

["", "my-custom-sa@..."] → ["serviceAccount:", "serviceAccount:my-custom-sa@..."]

Solution

if (defaultServiceAccountIndex) is replaced with if (defaultServiceAccountIndex !== -1)

const defaultServiceAccountIndex = serviceAccounts.indexOf("");
if (defaultServiceAccountIndex !== -1) {
  serviceAccounts[defaultServiceAccountIndex] = await gce.getDefaultServiceAccount(projectNumber);
}

and .filter() is added in serviceAccounts

const members = serviceAccounts
  .filter((sa) => !!sa)
  .map((sa) => `serviceAccount:${sa}`);

… IAM bindings:Fixes issue where an empty string could result in malformed IAM member serviceAccount: by properly checking index and replacing with the default service account.
@google-cla

google-cla Bot commented Jun 15, 2025

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@joehan
joehan requested a review from taeold June 16, 2025 20:49
@bryanatkinson
bryanatkinson self-requested a review June 17, 2025 20:16
@joehan
joehan merged commit bd303d7 into firebase:master Jun 17, 2025
@github-project-automation github-project-automation Bot moved this from Approved [PR] to Done in [Cloud] Extensions + Functions Jun 17, 2025
joehan added a commit that referenced this pull request Jun 17, 2025
@joehan joehan mentioned this pull request Jun 17, 2025
joehan added a commit that referenced this pull request Jun 17, 2025
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.

3 participants