简体   繁体   English

使用 Secret Manager 中存储的秘密初始化 Firebase Admin SDK

[英]Initialize Firebase Admin SDK using secret stored in Secret Manager

I am trying to initialize the Firebase Admin SDK within a Cloud Run application, using a separate service account (ie not the default service account).我正在尝试使用单独的服务帐户(即不是默认服务帐户)在 Cloud Run 应用程序中初始化 Firebase Admin SDK。

The documentation suggests:文档建议:

import firebase_admin
from firebase_admin import credentials

cred = credentials.Certificate("path/to/serviceAccountKey.json")
firebase_admin.initialize_app(cred)

However, I would like to avoid packaging secrets into the Cloud Run container, so I am retrieving the json file from Secret Manager, and trying to create the credentials, and pass it into: firebase_admin.initialize_app(cred)但是,我想避免将机密打包到 Cloud Run 容器中,因此我从 Secret Manager 检索 json 文件,并尝试创建凭据,并将其传递到:firebase_admin.initialize_app(cred)

import firebase_admin
from google.cloud import secretmanager
from google.oauth2 import service_account

# Create credentials object then initialize the firebase admin client
sec_client = secretmanager.SecretManagerServiceClient()
name = sec_client.secret_version_path(GOOGLE_CLOUD_PROJECT_NUMBER, FIREBASE_SA_SECRET_NAME, "latest")
response = sec_client.access_secret_version(name)
service_account_info = json.loads(response.payload.data.decode('UTF-8'))
creds = service_account.Credentials.from_service_account_info(service_account_info)
firebase_admin.initialize_app(creds)

Error received:收到错误:

ValueError: Illegal Firebase credential provided. ValueError:提供了非法的 Firebase 凭据。 App must be initialized with a valid credential instance.必须使用有效的凭据实例初始化应用程序。

Any tips are appreciated.任何提示表示赞赏。

import firebase_admin
from google.cloud import secretmanager
from google.oauth2 import service_account

# Create credentials object then initialize the firebase admin client
sec_client = secretmanager.SecretManagerServiceClient()
name = sec_client.secret_version_path(GOOGLE_CLOUD_PROJECT_NUMBER, FIREBASE_SA_SECRET_NAME, "latest")
response = sec_client.access_secret_version(name)
service_account_info = json.loads(response.payload.data.decode('utf-8'))

# build credentials with the service account dict
creds = firebase_admin.credentials.Certificate(service_account_info)

# initialize firebase admin
firebase_app = firebase_admin.initialize_app(creds)

I am trying to initialize the Firebase Admin SDK within a Cloud Run application, using a separate service account (ie not the default service account).我正在尝试使用单独的服务帐户(即不是默认服务帐户)在 Cloud Run 应用程序中初始化 Firebase Admin SDK。

The documentation suggests:文档建议:

import firebase_admin
from firebase_admin import credentials

cred = credentials.Certificate("path/to/serviceAccountKey.json")
firebase_admin.initialize_app(cred)

However, I would like to avoid packaging secrets into the Cloud Run container, so I am retrieving the json file from Secret Manager, and trying to create the credentials, and pass it into: firebase_admin.initialize_app(cred)但是,我想避免将机密打包到 Cloud Run 容器中,因此我从 Secret Manager 中检索 json 文件,并尝试创建凭据,并将其传递到:firebase_admin.initialize_app(cred)

import firebase_admin
from google.cloud import secretmanager
from google.oauth2 import service_account

# Create credentials object then initialize the firebase admin client
sec_client = secretmanager.SecretManagerServiceClient()
name = sec_client.secret_version_path(GOOGLE_CLOUD_PROJECT_NUMBER, FIREBASE_SA_SECRET_NAME, "latest")
response = sec_client.access_secret_version(name)
service_account_info = json.loads(response.payload.data.decode('UTF-8'))
creds = service_account.Credentials.from_service_account_info(service_account_info)
firebase_admin.initialize_app(creds)

Error received:收到错误:

ValueError: Illegal Firebase credential provided. ValueError:提供了非法的 Firebase 凭据。 App must be initialized with a valid credential instance.应用程序必须使用有效的凭据实例进行初始化。

Any tips are appreciated.任何提示表示赞赏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将 Google Secret Manager 与 Firebase 函数和 Stripe(顶级)结合使用 - Using Google Secret Manager with Firebase Functions and Stripe (top level) 使用 pytest 模拟秘密经理 - mock secret manager using pytest 在 Java 的集成测试中使用 GCP Secret Manager - Using GCP Secret Manager in integration tests in Java 使用带有 .net 核心 mvc 的 aws 秘密管理器 - using aws secret manager with .net core mvc 从 Bitbucket 管道访问存储在 Google Secret Manager 中的环境变量 - Access environment variables stored in Google Secret Manager from Bitbucket pipelines 将 google secret manager secret 挂载到 KubernetesPodOperator - Mount google secret manager secret to KubernetesPodOperator Firebase云Function中Secret Manager的正确使用方法是什么? - What is the Correct Way to Use Secret Manager in Firebase Cloud Function? 如何使用无服务器从 Google Secrets Manager 获取秘密? - How to get secret from Google Secrets Manager using Serverless? 在 AWS 秘密管理器中存储 Ansible Vault 密码并在需要时使用它 - Storing Ansible Vault password in AWS secret manager and using it when required Terraform AWS Redshift 和 Secret Manager - Terraform AWS Redshift and Secret Manager
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM