Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

[DOC] Improve documentation for service account impersonation

Đang mở
#2,812 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Tài liệu
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
gcp, nodejs, typescript

Hướng nghiên cứu

Bắt đầu với quy trình gcloud auth application-default login --impersonate-service-account đã được báo cáo và định dạng application_default_credentials.json, sau đó so sánh với các ví dụ về initializeApp, certapplicationDefault. Ghi lại một ví dụ phát triển cục bộ hoạt động được cho firebase-admin v13.0.1, bao gồm thiết lập quyền cần thiết và biểu hiện của việc xác thực thành công.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

It seems like service account impersonation is the recommended way to authenticate for local development.

But it's not very clear how this is done in practice. Do I need to adapt my code for this?

I've run:
gcloud auth application-default login --impersonate-service-account SERVICE_ACCT_EMAIL
and I have a token in:
cat /Users/myuser/.config/gcloud/application_default_credentials.json

{
  "delegates": [],
  "service_account_impersonation_url": "https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/myserviceaccount@myproject.iam.gserviceaccount.com:generateAccessToken",
  "source_credentials": {
    "account": "",
    "client_id": "removed",
    "client_secret": "removed",
    "refresh_token": "removed",
    "type": "authorized_user",
    "universe_domain": "googleapis.com"
  },
  "type": "impersonated_service_account"
}

I have tried code like this (after having looked at #2800):

initializeApp({
    storageBucket: config.firebase.storageBucket,
    credential: cert(process.env['GOOGLE_APPLICATION_CREDENTIALS']),
    projectId: config.firebase.projectId,
  })

But then I got an error:

FirebaseAppError: Failed to parse service account json file: Error: Service account object must contain a string "project_id" property.

and this, I assumed this would pick up the ADC credentials file, notice its impersonation, and things would just work:

initializeApp({
    storageBucket: config.firebase.storageBucket,
    credential: applicationDefault(),
    projectId: config.firebase.projectId,
  })

But then I got this error:

"Getting metadata from plugin failed with error: Could not refresh access token: PERMISSION_DENIED: unable to impersonate: Permission 'iam.serviceAccounts.getAccessToken' denied on resource (or it may not exist).",

My local user has the Owner role in the GCP project. And has owner permissions on the service account. The service account has the Service Account Token Creator role.

Im using firebase-admin v13.0.1

Some working sample code for this would be very helpful.

Ngôn ngữ chính
TypeScript
Star
1.7k
Fork
419
Merge trung bình
4 ngày 20 giờ
Pull request đã merge (30 ngày)
16

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của firebase/firebase-admin-node

Tất cả issue của firebase/firebase-admin-node

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.