Google Cloud Composer 获取默认服务帐户私钥

发布于 2025-01-09 19:11:58 字数 785 浏览 1 评论 0原文

我正在使用 pymongo (来自气流挂钩)连接到 mongo 实例,该实例使用 google kms 作为密钥实现 FLE(字段级加密)。我们有一个具有服务帐户文件的虚拟机,这就是我们配置它的方式。

hook = MongoHook(self.source_conn_id)
creds = json.load(open(self.gcs_service_account_keypath))
kms_providers = {
  "gcp": {
  "email": creds['client_email'],
  "privateKey": creds['private_key'].replace(
    '-----BEGIN PRIVATE KEY-----\n', '').replace(
    '\n-----END PRIVATE KEY-----\n', '')
  }
            }
  auto_encryption_opts = AutoEncryptionOpts(
  kms_providers, key_vault_namespace=self.mongo_key_vault_namespace, bypass_auto_encryption=True)
  hook.extras = {'auto_encryption_opts': auto_encryption_opts }

现在我尝试在 Cloud Composer 中执行相同的操作,但我找不到如何从 Cloud Composer 中的默认服务帐户访问私钥。我可以导出服务帐户密钥,将其添加到秘密管理器并像这样访问它,但这似乎不是一个好主意。 我有什么想法可以访问它吗?

I'm using pymongo (from airflow hook) to connect to a mongo instance which implements FLE (Field Level Encryption) using google kms for the keys. We have a VM which has a service account file and this is how we configured it

hook = MongoHook(self.source_conn_id)
creds = json.load(open(self.gcs_service_account_keypath))
kms_providers = {
  "gcp": {
  "email": creds['client_email'],
  "privateKey": creds['private_key'].replace(
    '-----BEGIN PRIVATE KEY-----\n', '').replace(
    '\n-----END PRIVATE KEY-----\n', '')
  }
            }
  auto_encryption_opts = AutoEncryptionOpts(
  kms_providers, key_vault_namespace=self.mongo_key_vault_namespace, bypass_auto_encryption=True)
  hook.extras = {'auto_encryption_opts': auto_encryption_opts }

Now I'm trying to do the same in Cloud Composer but I can't find how to access the private key from the default service account in cloud composer. I could export the service account key, add it to secret manager and access it like that but it doesn't seem very good idea.
Any ideas how I can access it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

放我走吧 2025-01-16 19:11:58

服务帐户私钥分为三种类型。 Google 管理、用户管理和用户提供(导入)。

您无法直接从计算服务访问私钥,因为元数据服务器不提供对私钥的访问 - 只能访问从私钥创建的令牌。

标准建议是使用 IAM API 来签署 blob/JWT。

您的另一个选择是使用用户管理,您可以在其中下载服务帐户 JSON 密钥文件并将该文件提供给您的应用程序或从 Secret Manager 或类似服务作为机密加载。

There are three types of service account private keys. Google managed, user managed and user supplied (imported).

You cannot directly access the private key from a compute service as the metadata server does not provide access to private keys - only tokens created from private keys.

The standard recommendation is to use the IAM APIs to sign blobs/JWTs.

Your other option is to use user managed where you download the service account JSON key file and provide that file to your application or load as a secret from Secret Manager or a similar service.

波浪屿的海角声 2025-01-16 19:11:58

You can generate a service account key following these steps. Instead of using secret manager, you can put the private key in the GCS bucket associated to your environment and put it in your data folder: gs://bucket-name/data to make it accessible. For more information of utilization of Cloud storage bucket associated to your Cloud composer environment, you can refer to this documentation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文