node.js - 谷歌云功能 : support for Google Cloud KMS

标签 node.js google-cloud-platform google-cloud-functions google-cloud-kms google-secret-manager

我正在使用带有 Pubsub 触发器的 Google Cloud Function (GCF),它向第三方 API 发送 HTTP 请求。

GCF 从不应了解第三方 API 的服务使用的 Pubsub 主题接收通知。

第三方 API 需要使用基本 HTTP 身份验证进行身份验证。

为了不必在我的源代码中对密码进行硬编码,我在每次部署我的函数时都使用 Google KMS 生成一个新的加密 key 。每次实例化函数时,我都使用 Google Cloud KMS 来解密 key 。

为了使用 KMS 解密,我必须向 NodeJS Google API 提供服务帐户的私钥。

我今天的主要问题是,如果我想让我的 GCF 正常工作,我必须将我的私钥推送到 GCloud Bucket。

是否可以使用 Runtime Configurator 或 Deployment Manager 为 Google Cloud Functions 配置 secret ?

谢谢。

最佳答案

截至 2019 年 12 月,在 Google Cloud 上存储和管理 secret 的首选方式是 Secret Manager :

$ echo -n "user:pass" | gcloud beta secrets create "my-basic-auth" \
  --data-file=- \
  --replication-policy "automatic"

您还可以通过 API 创建和管理 secret :

// Import the library
const {SecretManagerServiceClient} = require('@google-cloud/secret-manager');

// Create the client
const client = new SecretManagerServiceClient();

// Create the secret
const [secret] = await client.createSecret({
  parent: "projects/<YOUR-PROJECT-ID>",
  secretId:"my-basic-auth",
  secret: {
    replication: {
      automatic: {},
    },
  },
});

// Add the version with your data
const [version] = await client.addSecretVersion({
  parent: secret.name,
  payload: {
    data: Buffer.from("user:pass", "utf8"),
  },
});

然后,在您的云函数中:

const [version] = await client.accessSecretVersion({
  name:"projects/<YOUR-PROJECT-ID>/secrets/<MY-SECRET>/versions/1",
});

const auth = version.payload.data.toString('utf-8');

// auth is user:pass

用于部署 Cloud Function 的服务帐户需要 roles/secretmanager.secretAccessor 权限。

关于node.js - 谷歌云功能 : support for Google Cloud KMS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44506244/

相关文章:

javascript - Node.js server.address().address 返回::

javascript - 是否可以在单个 Node.js 服务器中执行多个 facebook Messenger bot

https - Kubernetes https服务暴露

ssl - 带有幻影的 Yandex-Tank TLS 请求

javascript - 如何向 watson 对话响应添加操作?

javascript - 每个 JS 文件在打开并保存在 Azure 上之前都会引发错误

docker - 如何使用 docker compose 部署到 google-cloud?

python - Cloud Run 客户端请求 IP 地址被代理 Python Fast API 覆盖

google-app-engine - Cloud Functions for Firebase 免费套餐中的 “No Outbound Networking” 到底是什么意思?

firebase - Firestore 聊天应用 - 构建消息主页