Fix Firebase Functions Permissions
To fix the error: “Unable to retrieve the repository metadata for projects/your-project-id/locations/us-central1/repositories/gcf-artifacts”, follow these steps:
1. Enable the Artifact Registry API
First, you need to enable the Artifact Registry API for your project:
gcloud services enable artifactregistry.googleapis.com --project=your-project-id2. Grant the Cloud Functions Service Account the Required Permissions
The Cloud Functions service account needs the Artifact Registry Reader role:
# Get the project number (needed for service account identification)PROJECT_NUMBER=$(gcloud projects describe your-project-id --format="value(projectNumber)")
# Grant Artifact Registry Reader role to the Cloud Functions service accountgcloud projects add-iam-policy-binding your-project-id \ --member=serviceAccount:service-${PROJECT_NUMBER}@gcf-admin-robot.iam.gserviceaccount.com \ --role=roles/artifactregistry.reader3. Grant Additional Required Permissions
You may also need to grant the following permissions:
# Grant Storage Object Viewer rolegcloud projects add-iam-policy-binding your-project-id \ --member=serviceAccount:service-${PROJECT_NUMBER}@gcf-admin-robot.iam.gserviceaccount.com \ --role=roles/storage.objectViewer
# Grant Artifact Registry Repository Administrator role (if needed)gcloud projects add-iam-policy-binding your-project-id \ --member=serviceAccount:${PROJECT_NUMBER}@cloudbuild.gserviceaccount.com \ --role=roles/artifactregistry.admin4. Using Firebase Console (Alternative Method)
If you prefer using the Firebase Console:
- Go to the Firebase Console
- Select your project
- Go to Project Settings > Service accounts
- Click on “Manage service account permissions” (this will take you to Google Cloud Console)
- Find the service account named “App Engine default service account” or “Cloud Functions service account”
- Click on the edit icon (pencil)
- Add the following roles:
- Artifact Registry Reader
- Storage Object Viewer
5. Wait and Re-deploy
After setting permissions, wait a few minutes for them to propagate, then try deploying again:
firebase deploy --only functionsTroubleshooting Further Permission Issues
If you encounter additional permission issues, you might need to grant more roles to the service accounts:
# Cloud Build Service Accountgcloud projects add-iam-policy-binding your-project-id \ --member=serviceAccount:${PROJECT_NUMBER}@cloudbuild.gserviceaccount.com \ --role=roles/cloudfunctions.developer
# Cloud Functions Service Account - Service Agent rolegcloud projects add-iam-policy-binding your-project-id \ --member=serviceAccount:service-${PROJECT_NUMBER}@gcf-admin-robot.iam.gserviceaccount.com \ --role=roles/cloudfunctions.serviceAgentRemember to replace your-project-id with your actual project ID if it’s different.