Skip to content

Commit 1330a8a

Browse files
committed
fix(gcpkms): Set quota project to API project
Like described in the linked issue, if the GCP KMS key is stored in project foo, but the service account is created in project bar, sops complains that KMS API is not enabled in project bar. The quota project used by default is the one encoded in the service account key. With this commit, the behavior changes, so the project where the KMS key and API reside, is read from the key ID and set via the quota project option. Fixes #1142 Signed-off-by: Johannes Rothe <mail@johannes-rothe.de>
1 parent bb710f3 commit 1330a8a

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

gcpkms/keysource.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,14 @@ func (key *MasterKey) TypeToIdentifier() string {
208208
// It returns an error if the ResourceID is invalid, or if the setup of the
209209
// client fails.
210210
func (key *MasterKey) newKMSClient() (*kms.KeyManagementClient, error) {
211-
re := regexp.MustCompile(`^projects/[^/]+/locations/[^/]+/keyRings/[^/]+/cryptoKeys/[^/]+$`)
211+
re := regexp.MustCompile(`^projects/(?P<project>[^/]+)/locations/[^/]+/keyRings/[^/]+/cryptoKeys/[^/]+$`)
212212
matches := re.FindStringSubmatch(key.ResourceID)
213213
if matches == nil {
214214
return nil, fmt.Errorf("no valid resource ID found in %q", key.ResourceID)
215215
}
216216

217217
var opts []option.ClientOption
218+
opts = append(opts, option.WithQuotaProject(matches[1]))
218219
switch {
219220
case key.credentialJSON != nil:
220221
opts = append(opts, option.WithCredentialsJSON(key.credentialJSON))

0 commit comments

Comments
 (0)