Skip to content

Failed to deploy with serviceAccount as StringParam defined in .env file #6365

Closed

Description

@ZakarY2HM6f

Environment info

firebase-tools:
12.5.4

Platform:
macOS

Test case

.env

SERVICE_ACCOUNT=(service account here)

index.js

const {defineString} = require("firebase-functions/params");
const {setGlobalOptions} = require("firebase-functions/v2/options");
const {onRequest} = require("firebase-functions/v2/https");

const serviceAccount = defineString("SERVICE_ACCOUNT");

setGlobalOptions({
  serviceAccount: serviceAccount,
});

exports.sayHello = onRequest(
  (req, res) => {
    res.status(200).send("Hello world!");
  }
);

↑ this does not work, but this works ↓

workaround.js

...

setGlobalOptions({
  serviceAccount: serviceAccount.value(),
});

exports.sayHello = onRequest(
  (req, res) => {
    res.status(200).send("Hello world!");
  }
);

Steps to reproduce

firebase deploy

Expected behavior

to just deploy normally

Actual behavior

for index.js, the output:

...
⚠  functions: HTTP Error: 400, {{ params.SERVICE_ACCOUNT }} should be a valid email or unique id.
⚠  functions:  failed to update function projects/***/locations/***/functions/sayHello
Failed to update function projects/***/locations/***/functions/sayHello
...

for workaround.js, the output:

...
i  functions: Loading and analyzing source code for codebase default to determine what to deploy
Serving at port 8079

{"severity":"WARNING","message":"params.SERVICE_ACCOUNT.value() invoked during function deployment, instead of during runtime."}

{"severity":"WARNING","message":"This is usually a mistake. In configs, use Params directly without calling .value()."}
{"severity":"WARNING","message":"example: { memory: memoryParam } not { memory: memoryParam.value() }"}
...

workaround deploys sucessfully, but its suggestions (without .value()) fails, as shown in index.js

On error, hard-coded values are printed out as is, while StringParam is shown as {{ params.SERVICE_ACCOUNT }}, suggesting the CLI may not have evaluated the Param as a string before validating and using the value.

Activity

  1. ZakarY2HM6f commented on Sep 16, 2023

    @ZakarY2HM6f
    Author

    actually the workaround does not work. It just used the default Compute Engine service account again.
    currently hard-coding it in, but it is not ideal for working the git and .gitignore

  2. colerogers commented on Sep 21, 2023

    @colerogers
    Contributor

    Hi @ZakarY2HM6f thanks for raising this, it looks like we don't treat service accounts as params in the firebase CLI. I made a fix for that in #6389 and we'll try to merge that in as soon as possible. Thanks!

  3. artberri commented on Apr 4, 2024

    @artberri

    @colerogers it is happening again to me in version 13.6.1. Could there be a regression?

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions