Can I add a domain to Firebase hosting via the API?
Asked Answered
C

5

7

I want to be able to add domains to Firebase hosting with the API instead of the web UI, is that possible?

I want to add potentially hundreds of domains, is there a domain limit per project in Firebase?

Chop answered 4/3, 2020 at 18:41 Comment(1)
From Firebase support: each Firebase account has a limit of 36 domains.Chop
C
3

As far as I can tell from the entire CLI documentation, there isn't any way to do this.

Lets take a step back and consider what the web UI process involves i.e. the generation of a TXT record to add to your DNS records, after verifying the presence of said TXT record on the domain, providing A records that you (authorized owner) add to allow redirecting to your firebase hosted site.

In my opinion, this very manual back and forth is necessary as a security measure. The only way it is taken out of the equation via the CLI is by providing a means for you to authenticate ownership of a domain (registered with any one of many domain registrars), and being granted authorization to change your A records. These are both outside the scope of Firebase, and could potentially introduce severe security flaws. Regardless, even if it existed, it would still have to be step-by-step and somewhat manual via CLI rather than the single command it sounds like you're looking for.

Charkha answered 4/3, 2020 at 19:40 Comment(3)
Thanks, but I don't understand how this would be a security issue. The CLI would be authenticated similarly to the web console. It's the same message interactions as the web interface just done in a terminal. But being able to programmatically get that TXT value, I could write a server that allows untrusted people to add domains to my Firebase console. They would add the A and TXT records to their own domain (or my server could use an API of the registrar to do it).Chop
Per my comment the back and forth (UI or CLI) is a security measure, while its automation introduces potential (not definite) security flaws. Think of it like verifying your bank account on PayPal or Venmo...the whole depositing pennies, verifying and withdrawing it is manual and time consuming by design. Now imagine an API that allowed you verify hundreds of accounts via CLI. In the first place owning hundreds of accounts would be an edge case (just like 100s of domains), and creating such an API to cater for it introduces potential security risks that might not be worth it.Charkha
Verifying accounts adds new message interactions that do not exist with the current banking system (userOwnsAccount(), accountIsActive()). If the banking system had these functions standardised I doubt Paypal and Venmo would keep the human interaction part. I think your right about the edge case - I think thats the only reason it does not have a CLI counterpart to the web UI.Chop
P
2

EDIT: It actually doesn't work. It's only possible to add a domain that has been added to the project before.

ORIGINAL: It's possible to add domains using Firebase Hosting Rest Api. I am not sure why they didn't put it on their official website but I checked today and it works. https://developers.google.com/resources/api-libraries/documentation/firebasehosting/v1beta1/java/latest/com/google/api/services/firebasehosting/v1beta1/FirebaseHosting.Sites.Domains.html

Pulchia answered 28/5, 2022 at 22:7 Comment(1)
Do you maybe have a code example for this? I keep getting domain x not associated with project when using thisPapa
M
1

It is not possible to add custom domains automatically through an API at this time.

Nor would it allow you to create a reseller or multi-tenant project (i.e. connect a large number of domains or subdomains dynamically) since you cannot connect more than about 36 domains connected to one project.

Milson answered 8/9, 2020 at 15:23 Comment(3)
Interesting comment, is this documented somewhere ? It has a massive impact on what I do. Thanks KatoLamplighter
Mentioned here but not in the quotas doc I see. I'll add a bug.Milson
@Milson limit 36 sites, not limit 36 custom domainsCarthusian
S
1

It's now possible (in beta):

https://firebase.google.com/docs/reference/hosting/rest/v1beta1/projects.sites.customDomains/create

You can also do it with Terraform:

https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/firebase_hosting_custom_domain

With wait_dns_verification = false I was able to do it, even with domains that are not associated with the project / GCP organization.

Subtype answered 30/4, 2024 at 3:22 Comment(0)
S
0

Answer that I've received from Firebase support:

There is no API yet that would allow you to add custom domains, it was requested as a feature before but unfortunately we have no more information on that - so for now, only the Console UI allows you to do it.

When it comes to the limits, in a project, a custom domain is attached to a site - there can be 36 sites per project, and for one site there is no hard limit, but we recommend not exceeding 20 custom domains. You can experience technical issues with SSL certs when you exceed 20 domains per site, which we won’t be able to troubleshoot since the system was not designed for such use cases.

Sowers answered 9/5, 2022 at 13:30 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.