doushi1900 2018-12-19 18:39
浏览 158
已采纳

如何使用Google KMS创建服务帐户以访问GCP项目之间的秘密?

I've followed this tutorial: https://cloud.google.com/kms/docs/store-secrets

My next step was to have my apps read my secrets file from the storage bucket and decrypt safely at runtime. These apps run within various projects (staging, dev, production etc).

I've read the service account documentation over and over but can't quite understand the correct way forward.

What I found that worked was to simply add service accounts to MY_KMS_PROJECT and MY_STORAGE_PROJECT from the tutorial. I set them up to have access to read storage buckets and to decrypt KMS keys. Just by creating those service accounts, suddenly apps in other projects could read and decrypt. Is that how it's supposed to work?

I thought that I would have had to create a service account for each project that I want to have accessing the KMS projects from the tutorial? Or use IAM somehow to grant access? For example, how would I grant access to some apps within some projects and not others?

I'm attempting to now give access to apps when they are running in my local dev environment, which usually requires downloading a service account and pointing GOOGLE_APPLICATION_CREDENTIALS to the file. But it seems strange to me to download the service accounts from the MY_KMS_PROJECT or MY_STORAGE_PROJECT, especially since I already have a service account for accessing firebase. Are service accounts somehow global to all projects? Can they be combined? GOOGLE_APPLICATION_CREDENTIALS seems only good for pointing at a single service account.

Note: most of my apps are running on google app engine standard or flexible.

Here is the code from the apps within my projects that "just work" as described above:

client, err := google.DefaultClient(ctx, cloudkms.CloudPlatformScope)
if err != nil {
    log.Fatal(err)
}

// Create the KMS client.
kmsService, err := cloudkms.New(client)
if err != nil {
    log.Fatal(err)
}
....

And for accessing the bucket:

// Create the storage clientstorage
Client, err := storage.NewClient(ctx)
if err != nil {
    log.Fatal(err)
}
....
  • 写回答

2条回答 默认 最新

  • doujiao1814 2018-12-20 20:16
    关注

    This is what I discovered works. Until I hear that it's not correct or ideal, it's how I'm moving forward:

    1. Follow the "storing secrets" tutorial (https://cloud.google.com/kms/docs/store-secrets).

    Note that when creating the two accounts from the tutorial, there will be no service accounts automatically created since there is no compute or app engine instances by default.

    1. Go to IAM for the kms storage project and add any other projects with apps that you want to have access to download the encrypted secrets. Add them by their service account emails, with the role for viewing buckets.

    2. Go to IAM for the kms management project and do the same for any projects with apps that you want to be decrypting the shared secrets, via their service account emails.

    For Localhost development, use "gcloud auth application-default login" before starting your services.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大