【问题标题】:Google Cloud KMS App Engine Encrypt not workingGoogle Cloud KMS App Engine 加密不起作用
【发布时间】:2020-08-11 08:13:43
【问题描述】:

我想使用多个 AppEngine 服务加密/解密 Google Cloud 项目中的一些敏感数据。我启用了 Cloud KMS API,并通过 IAM 将角色“Cloud KMS CryptoKey Encrypter/Decrypter”添加到 App Engine 服务帐户 ({projectId}@appspot.gserviceaccount.com)。

然后,我创建了一个环 (my-ring) 和一个环内的密钥 (my-key),接受默认轮换策略(90 天)。所以我有一个像“projects/{my-project-id}/locations/europe-west3/keyRings/my-ring/cryptoKeys/my-key”这样的密钥

我下载了 App 服务帐户 json 凭据,以便可以在本地调试代码。 GOOGLE_APPLICATION_CREDENTIALS 环境变量指向下载的文件。

当我尝试加密消息时,我收到以下错误:{"error":"invalid_grant","error_description":"Invalid grant: account not found"}

我的 Go 代码如下所示:

func encrypt(plainText []byte) (string, error) {
    ctx := context.Background()
    client, err := kms.NewKeyManagementClient(ctx)
    if err != nil {
        return "", err
    }
    req := &kmspb.EncryptRequest{Name: variables.EncryptionKey, Plaintext: plainText}
    result, err := client.Encrypt(ctx, req)
    if err != nil {
        fmt.Println(fmt.Errorf("encryption error %s", err))
        return "", err
    }
    return base64.URLEncoding.EncodeToString(result.Ciphertext), nil

}

我不知道我做错了什么。

【问题讨论】:

标签: go google-cloud-kms


【解决方案1】:

除了GOOGLE_APPLICATION_CREDENTIALS 指向另一个项目的帐户外,一切都很好。这只是我的错

【讨论】:

    猜你喜欢
    • 2017-04-11
    • 2019-09-15
    • 1970-01-01
    • 1970-01-01
    • 2020-01-12
    • 1970-01-01
    • 2018-01-23
    • 2012-06-02
    • 1970-01-01
    相关资源
    最近更新 更多