Skip to content

Unable to deploy function with service account parameter #5224

Closed

Description

@taeold
    Hi @inlined ,

I'm trying using parameterized codebases but I have this failure :

[2022-11-07T10:54:51.173Z] Got response from /__/functions.yaml Failed to generate manifest from function source: TypeError: serviceAccount.includes is not a function
[2022-11-07T10:54:51.177Z] Failed to parse functions.yamlincomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line at line 1, column 60:
     ...  from function source: TypeError: serviceAccount.includes is not ... 
                                         ^ {"name":"YAMLException","reason":"incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line","mark":{"name":null,"buffer":"Failed to generate manifest from function source: TypeError: serviceAccount.includes is not a function\n\u0000","position":59,"line":0,"column":59},"message":"incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line at line 1, column 60:\n     ...  from function source: TypeError: serviceAccount.includes is not ... \n                                         ^"}
[2022-11-07T10:54:51.181Z] shutdown requested via /__/quitquitquit


Error: Failed to load function definition from source: Failed to generate manifest from function source: TypeError: serviceAccount.includes is not a function
Error: Process completed with exit code 1.

In my code, I have this :

const {defineString} = require("firebase-functions/params");

const configuration = {
   ...,
   runtimeOptions: {
        serviceAccount: defineString("CF_SERVICE_ACCOUNT", {default: "default"}),
   }
}

The CF_SERVICE_ACCOUNT is configured in my functions/.env.[default|preproduction|production] like this : CF_SERVICE_ACCOUNT=cloud-functions-runner@<PROJECT_ID>.iam.gserviceaccount.com

Do you have an idea where I made a mistake ?

I upgraded to the latest Firebase tools CLI : 11.16.0

Originally posted by @fgruchala in firebase/firebase-functions#1275 (comment)

Activity

  1. fgruchala commented on Nov 7, 2022

    @fgruchala

    Thanks @taeold 👍🏻 for creating this new issue

  2. IchordeDionysos commented on Nov 9, 2022

    @IchordeDionysos
    Contributor

    @taeold In general, I would have expected to configure all config via params...

    For us, this is a blocking feature, as we no longer can supply the service account with the prefix:
    serviceAccount@, which depending on the project, would either resolve to serviceAccount@prod-project... or serviceAccount@stage-project...

  3. fgruchala commented on Nov 14, 2022

    @fgruchala

    @taeold do you have some visibility about this issue ?

  4. taeold commented on Nov 14, 2022

    @taeold
    ContributorAuthor

    @fgruchala Sorry for the silence. We are actively working on getting service account parametrizable and going through internal process to get the API approved. Will keep you all posted.

  5. fgruchala commented on Nov 21, 2022

    @fgruchala

    @taeold @Berlioz do you have any information ?

  6. taeold commented on Nov 21, 2022

    @taeold
    ContributorAuthor

    WIP #5234

  7. fgruchala commented on Nov 21, 2022

    @fgruchala

    WIP #5234

    Huge thanks

  8. Hibrix-net commented on Feb 25, 2023

    @Hibrix-net

    Any news here? I'm also unable to parameterize serviceAccount within runWith ...

  9. IchordeDionysos commented on Mar 26, 2023

    @IchordeDionysos
    Contributor

    @taeold is something similar planned for the function region?

  10. stfsy commented on Aug 18, 2023

    @stfsy
    Contributor

    @Hibrix-net @fgruchala I faced the same challenge.

    For now, I resorted to using the GCLOUD_PROJECT env var to construct the actual service account name at deployment time. Of course, this is only a possible solutions if the service accounts have the same name.

    import { defineString } from 'firebase-functions/params';
    import { setGlobalOptions } from 'firebase-functions/v2/options';
    
    const gcpCloudRegionParam = defineString("DSQ_GCP_CLOUD_REGION")
    
    setGlobalOptions({
        region: [gcpCloudRegionParam],
        serviceAccount: `cloud-run-functions@${process.env.GCLOUD_PROJECT}.iam.gserviceaccount.com`
    })
  11. IchordeDionysos commented on Aug 21, 2023

    @IchordeDionysos
    Contributor

    Do you know if this is fixed now? I remember a PR from @taeold about it in the past, if I'm not mistaken.

  12. stfsy commented on Aug 21, 2023

    @stfsy
    Contributor

    @IchordeDionysos not fixed. I just tried a few days ago and it didn't work.

  13. IchordeDionysos commented on Aug 21, 2023

    @IchordeDionysos
    Contributor
  14. stfsy commented on Aug 21, 2023

    @stfsy
    Contributor

    @IchordeDionysos yeah but an expression is not a param, I guess.

    I wrote a blog post about the issue yesterday: https://medium.com/@stfsy/different-service-accounts-for-firebase-functions-per-stage-e667db4059e4. Gist is the serviceAccount parameter does not get resolved, but merely copied as is:

    proto.copyIfPresent(
    bkEndpoint,
    bdEndpoint,
    "environmentVariables",
    "labels",
    "secretEnvironmentVariables",
    "serviceAccount"
    );

    Thus, when passing a param instead of a string value, the param expression will be used and not the value that could be.

    You can see in branch that was created for the PR this line was added to actually resolve the value of the serviceAccount param

    proto.copyIfPresent(
    bkEndpoint,
    bdEndpoint,
    "environmentVariables",
    "labels",
    "secretEnvironmentVariables"
    );
    r.resolveStrings(bkEndpoint, bdEndpoint, "serviceAccount");

    I added this line to the current firebase-tools version and it works pretty fine. The whole refactoring that was started for the serviceAccount param is not really necessary to fix this issue in my opinion.

    I am using v2 functions.

  15. imanabu commented on Mar 23, 2025

    @imanabu

    23-Mar-2025

    This still does not work.

       {
         "functions": {
           "source": "functions",
           "serviceAccount": "your-firebase-service-account@your-project-id.iam.gserviceaccount.com"
         }
       }
    

    I am running into an issue where "firebase deploy --only functions:my_func (example) deploys to the Cloud function's default service account, and not the service account shown on the Firebase Console. I do not know why this happens, but the fact that the override as above does not work means, I am stuck with this issue. Note that I have several non-org accounts and for those projects the service account of the Firebase Console is used right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions