Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

firebase init hosting:github, 404 error if the repo belongs to an organization #40

Open
JohnFitz opened this issue Oct 17, 2020 · 20 comments
Labels
ongoing This issue is taking a while, but that's ok

Comments

@JohnFitz
Copy link

JohnFitz commented Oct 17, 2020

First off, I'm brand new to firebase hosting and github actions, so it's entirely possible that I'm approaching this the wrong way, but I haven't found any mention of this being incorrect in the docs.

To reproduce

  1. Create an organization on Github.
  2. Upload your repo to your org and set it as the remote origin
  3. Locally, use the command firebase init hosting:github

I authenticate successfully, then I'm prompted to enter the name of the repo, and it even suggests the correct repo in the format my-org-name/my-repo-name. So, I enter that but get the error FirebaseError: HTTP Error: 404, Not Found

Analysis

Looking at the firebase-debug.log, it looks like the cli makes the assumption that the repo belongs to a user, which isn't correct in this case i.e. from what I entered, it's forming the request:
HTTP REQUEST GET https://api.github.com/repos/my-org-name/my-repo-name/actions/secrets/public-key?type=owner
but the API is expecting:
...api.github.com/repos/my-github-username/my-repo-name/...

However, if I enter my-github-username/my-repo-name at the prompt, I get the same error but that's because the repo doesn't exist under my account, it belongs to the org.

Maybe it's a limitation of Github's API? Or maybe your intention is that developers always fork the repo, so this is more of a documentation issue (or lack of knowledge on my behalf)?

To work around this, I'm going to transfer the repo to my account, but I thought I'd mention it here.

@TheBestMoshe
Copy link

I am having the same issue

@jhuleatt
Copy link
Collaborator

jhuleatt commented Oct 29, 2020

EDIT June 17, 2021: Take a look at @alkiko's comment below. You may not need to follow these manual service account creation steps!

Thanks for the report, @JohnFitz and @TheBestMoshe! And sorry for the delay in getting back to you. This is a CLI bug, so I've filed it here: firebase/firebase-tools#2763

The workaround is to manually set up this GitHub action yourself until that's fixed. To do that:

1. Create a service account that the action will use to deploy to Hosting

  1. Visit the GCP Service Accounts page and make sure the correct project (same name as your Firebase project) is selected in the top blue bar
  2. Click the "+ CREATE SERVICE ACCOUNT" button
  3. Give the service account a name, id, description. We recommend something like github-action-<my repository name>
  4. At the "Grant this service account access to project" step, choose the following roles that the service account will need to deploy on your behalf:
    • Firebase Authentication Admin
    • Firebase Hosting Admin
    • Cloud Run Viewer
    • API Keys Viewer
  5. Finish the service account creation flow

2. Get that service account's key and add it to your repository as a secret

  1. Create and download the new service account's JSON key
  2. Add that JSON key as a secret in your GitHub repository. We recommend a name like FIREBASE_SERVICE_ACCOUNT_<PROJECT_ID> (example: FIREBASE_SERVICE_ACCOUNT_MY_COOL_APP)

3. Add a workflow yaml file to your repository

  1. Add a yml file as described here. Be sure to reference your new secret for the firebaseServiceAccount option.

Please let me know if you get stuck in any part of the process. Happy to clarify any of the steps in this workaround.

(UPDATE Dec 23, 2020: this process is now documented here)

@najibghadri
Copy link

najibghadri commented Nov 7, 2020

I report this during a hackhaton :D : ALL you have to do is first grant Firebase CLI 3rd party github app in https://github.com/settings/applications and THEN do firebase init hosting:github. and enter it as organization/repo-name

If it's not already among your integrated apps you can run firebase init hosting:github on a repo that YOUR username owns, because that will prompt you with the website to authorize Firabse CLI.

@rbar2
Copy link

rbar2 commented Nov 16, 2020

@jhuleatt I used your steps to create a service account, create and download a key, add the key under "Repository secrets", add the workflow, and then create a PR to trigger the workflow. However, I still get an error:
Error: Input required and not supplied: firebaseServiceAccount

Screen Shot 2020-11-16 at 2 21 29 AM

I assumed it was an issue with this line in the workflow:
firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT }}"

so I also tried changing the line to the following and rerunning:
firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_MY_COOL_APP }}"
.. but the same error occurs.

Do you happen to know how to resolve the outstanding error from the steps?

@najibghadri
Copy link

@rbar2

jhuleatt I used your steps to create a service account, create and download a key, add the key under "Repository secrets", add the workflow, and then create a PR to trigger the workflow. However, I still get an error:
Error: Input required and not supplied: firebaseServiceAccount

Screen Shot 2020-11-16 at 2 21 29 AM

I assumed it was an issue with this line in the workflow:
firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT }}"

so I also tried changing the line to the following and rerunning:
firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_MY_COOL_APP }}"
.. but the same error occurs.

Do you happen to know how to resolve the outstanding error from the steps?

Did you try or already have what I described?

@rbar2
Copy link

rbar2 commented Nov 18, 2020

@najibghadri, thanks for the reply. I reran the test today and it didn't give me the same error. Perhaps it takes some time to propagate the secrets? I received a new error stating that the Firebase Hosting API needed to be enabled, so I enabled that, waited about 20 minutes (since the error mentioned it would take a few minutes to propagate), and then it worked ✅

Much appreciated

@TheBestMoshe
Copy link

hub app in https://github.com/settings/applications and THEN do firebase init hosting:github. and enter it as organization/repo-name

If it's not already among your integrated apps you can run firebase init hosting:github on a repo that YOUR username owns because that will prompt you with the website to authorize Firebase CLI.

@najibghadri I already see Firebase CLI in the approved applications list, and I am able to run firebase init hosting:github on personal repositories, yet I'm still getting the FirebaseError: HTTP Error: 404, Not Found when running on an organization repository.

@alkiko
Copy link

alkiko commented Dec 18, 2020

I got this error on org repos too.

The solution for me was:

  1. Open https://github.com/settings/connections/applications
  2. Select the Firebase CLI application
  3. Look for the section Organisation Access
  4. Click the "Grant" button next to the organisation you want to grant Firebase CLI access to

After that, I was able to run firebase init hosting:github

@jhuleatt jhuleatt added the ongoing This issue is taking a while, but that's ok label Dec 23, 2020
@imnickvaughn
Copy link

@alkiko Thank you, this worked for me. My organization was listed there but it was granted access (with a red x). You just have to press the Grant button and you can continue going through the Firebase CLI, with no extra steps. Easy Peezy, thank you.

@treeder
Copy link

treeder commented Dec 29, 2020

@alkiko 's answer worked me as well.

@nwatab
Copy link

nwatab commented Jan 11, 2021

@alkiko Thank you. It worked after granting Firebase CLI access to my GitHub organization

@SwastikGupta
Copy link

@alkiko Worked like a charm

@mesqueeb
Copy link

@jhuleatt you should edit your post with the "workaround" and just point people towards this post further down:

I got this error on org repos too.

The solution for me was:

  1. Open https://github.com/settings/connections/applications
  2. Select the Firebase CLI application
  3. Look for the section Organisation Access
  4. Click the "Grant" button next to the organisation you want to grant Firebase CLI access to

After that, I was able to run firebase init hosting:github

None of the complicated manual workaround is required when just following this post, it's way easier!

However, since your "workaround" is the first post appearing, I'm afraid many devs come here and first try this manual difficult method...

@augustineoliver
Copy link

I report this during a hackhaton :D : ALL you have to do is first grant Firebase CLI 3rd party github app in https://github.com/settings/applications and THEN do firebase init hosting:github. and enter it as organization/repo-name

If it's not already among your integrated apps you can run firebase init hosting:github on a repo that YOUR username owns, because that will prompt you with the website to authorize Firabse CLI.

This works. Just grant Friebase CLI access to your organisation account.

@itsnamangoyal
Copy link

I report this during a hackhaton :D : ALL you have to do is first grant Firebase CLI 3rd party github app in https://github.com/settings/applications and THEN do firebase init hosting:github. and enter it as organization/repo-name

If it's not already among your integrated apps you can run firebase init hosting:github on a repo that YOUR username owns, because that will prompt you with the website to authorize Firabse CLI.

Worked like charm!

@123MwanjeMike
Copy link

  1. Go to your Account Settings
  2. Select Applications
  3. Switch to the Authorized OAuth Apps tab
  4. Select Firebase CLI
  5. Under Organization access, grant it access to the Organisation

@anweshandev
Copy link

2. Add that JSON key

So do I literally copy the JSON key and paste in the text area... 🤔

@lorenzfischer0
Copy link

After following the steps recommend by alkiko I got the error "Error: HTTP Error: 403, Policy update access denied.". The issue seemed to be that I was't the owner of the firebase project, just an editor.

@driiftkiing
Copy link

In my case, I had to remove the forwarding slash / from autocomplete e.g. /user/repository to user/repository

@jeff-r-koyaltech
Copy link

It may help to run the firebase init hosting command twice, if you have trouble with the service account step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ongoing This issue is taking a while, but that's ok
Projects
None yet
Development

No branches or pull requests