Skip to content

Firebase deployment without token fails #5340

Closed

Description

@JFGHT

Due to the new Firebase warning:

⚠ Authenticating with --token is deprecated and will be removed in a future major version of firebase-tools. Instead, use a service account key with GOOGLE_APPLICATION_CREDENTIALS: https://cloud.google.com/docs/authentication/getting-started

We decided to implement it as it should be.

[REQUIRED] Environment info

firebase-tools: 11.18.0

Platform: Github Actions with ubuntu-latest and pnpm.

[REQUIRED] Test case

name: Deploy to Firebase Hosting on merge
'on':
  push:
    branches:
      - main
jobs:
  build_and_deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: pnpm/action-setup@v2
        with:
          version: 7.18.2
          run_install: false

      - name: Get pnpm store directory
        id: pnpm-cache
        shell: bash
        run: |
          echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT

      - uses: actions/cache@v3
        name: Setup pnpm cache
        with:
          path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
          key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
          restore-keys: |
            ${{ runner.os }}-pnpm-store-

      - name: Install dependencies
        run: pnpm install

      - name: Run tests
        run: pnpm test:unit

      - name: Run build
        run: pnpm build

      - name: Install Functions Deps
        shell: bash
        run: |
          cd functions && pnpm i

      # Future code for deploying without token
      - name: Decoding base64 Credentials
        shell: bash
        run: echo ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_BASE64 }} | base64 --decode > credentials.json

      - name: Save credentials into environment variables
        run: echo "GOOGLE_APPLICATION_CREDENTIALS=./credentials.json" >> $GITHUB_ENV

      - name: Deploy to Firebase
        shell: bash
        # Using GOOGLE_APPLICATION_CREDENTIALS env
        run: |
          ./node_modules/.bin/firebase deploy --non-interactive

      - name: Remove credentials file
        if: success() || failure()
        run: rm credentials.json

[REQUIRED] Steps to reproduce

  • Generate the service account from the Firebase project.
  • Encode it into base64, save it in Github secrets as GOOGLE_APPLICATION_CREDENTIALS_BASE64.
  • Push anything to main branch.

[REQUIRED] Expected behavior

Firebase should deploy as expected.

[REQUIRED] What actually happens:

image

Activity

  1. google-oss-bot commented on Dec 15, 2022

    @google-oss-bot
    Collaborator

    This issue does not seem to follow the issue template. Make sure you provide all the required information.

  2. christhompsongoogle commented on Dec 20, 2022

    @christhompsongoogle
    Contributor

    Can you share your firebase json? which products are you deploying? This looks like a permissions issue

  3. bkendall commented on Dec 20, 2022

    @bkendall
    Contributor

    hey @JFGHT - would you be able to check the permissions that the SA has? I think by default it has 0 permissions, so it'll have to have some added to it. You can confirm the permissions issue by running with --debug as well and checking that output.

  4. added
    Needs: Author Feedback
    and removed on Dec 20, 2022
  5. JFGHT commented on Dec 21, 2022

    @JFGHT
    Author

    hey @JFGHT - would you be able to check the permissions that the SA has? I think by default it has 0 permissions, so it'll have to have some added to it. You can confirm the permissions issue by running with --debug as well and checking that output.

    [2022-12-21T09:40:29.474Z] <<< [apiv2][body] POST https://cloudresourcemanager.googleapis.com/v1/projects/X:testIamPermissions {"permissions":["datastore.indexes.list","firebase.projects.get","firebasehosting.sites.update"]}
    [2022-12-21T09:40:29.474Z] [iam] error while checking permissions, command may fail: FirebaseError: Authorization failed. This account is missing the following required permissions on project X:
    
      cloudfunctions.functions.create
      cloudfunctions.functions.delete
      cloudfunctions.functions.get
      cloudfunctions.functions.list
      cloudfunctions.functions.update
      cloudfunctions.operations.get
      datastore.indexes.create
      datastore.indexes.delete
      datastore.indexes.update
    

    Nice debugging log.

    I added those manually and then I got this:

    Identity and Access Management (IAM) API has not been used in project X before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/iam.googleapis.com/overview?project=X then retry.

    Enabled the API

    Then I got this:

    Error: Missing permissions required for functions deploy. You must have permission iam.serviceAccounts.ActAs on service account {name of the firebase project}@appspot.gserviceaccount.com.

    To address this error, ask a project Owner to assign your account the "Service Account User" role from this URL: url with {name of the firebase project}

    Added it and threw the same error.

    Added it to the generated SA and this error from above was gone but stiil:

    [2022-12-21T09:59:11.609Z] <<< [apiv2][body] POST https://firebaserules.googleapis.com/v1/projects/X:test {"error":{"code":403,"message":"The caller does not have permission","status":"PERMISSION_DENIED"}}

    Without any other sign of specific error.

  6. added and removed
    Needs: Author Feedback
    on Dec 21, 2022
  7. JFGHT commented on Jan 13, 2023

    @JFGHT
    Author

    Hey @bkendall, any news on this?

  8. emilbonnek commented on Feb 15, 2023

    @emilbonnek

    I had the same issue it got resolved for me by adding Cloud Run Admin and Service Account User to the SA as suggested here.

  9. mkue commented on Jun 6, 2023

    @mkue

    [2022-12-21T09:59:11.609Z] <<< [apiv2][body] POST https://firebaserules.googleapis.com/v1/projects/X:test {"error":{"code":403,"message":"The caller does not have permission","status":"PERMISSION_DENIED"}}

    I ran into the same issue when running:

    GOOGLE_APPLICATION_CREDENTIALS=credentials.json firebase deploy --only firestore:rules --project my-project

    I managed to resolve the same issue by adding the Firebase Rules Admin and Firebase Rules Firestore Service Agent roles to the service account.

  10. mwilliams1188 commented on Sep 29, 2023

    @mwilliams1188

    I can deploy locally using firebase deploy, but GitHub action is throwing this error: "Caller is missing permission 'iam.serviceaccounts.actAs' on service account [email protected]".

    It says add server account user, which I did. I also added Cloud Run Admin and I'm getting the same error no matter what permission I add.

    I'm using the webframeworks experiment (SvelteKit). I used firebase init (using the latest firebase-tools) which set all the configuration and created the service account, so all the configuration is default.

    Any idea what could be wrong here?

    Update: Seems like adding Cloud Run Service Agent resolved this, though the error doesn't make that clear

  11. robokozo commented on Oct 13, 2023

    @robokozo

    @mwilliams1188 I tried the same but I'm still encountering the same issue. The only difference is I'm trying to do the same with a nuxt webframeworks experiment :(

    Can you think of any other steps you might have taken to resolve it? I actually granted the account "Owner" permissions but without any luck. (I removed it after I verified it wasn't working)

  12. JFGHT commented on Dec 12, 2023

    @JFGHT
    Author

    @joehan Why was this closed? could you link a ref to the solution?

  13. ndpdarshana commented on Dec 12, 2023

    @ndpdarshana

    @joehan The solution is to create a service account and generate a service account key from the Google Cloud console, which can then be used to deploy Firebase.

    One key is generated, set the GOOGLE_APPLICATION_CREDENTIALS environment variable to the generated key file which will automatically used by firebase tools to deploy the project.

    https://stackoverflow.com/questions/59053919/login-to-firebase-using-gcloud-service-account

  14. johnnyoshika commented on Dec 27, 2023

    @johnnyoshika

    Is there a list of all permissions needed by the service account to deploy each Firebase service?

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