Skip to content

Commit 5184d1a

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 53cc5fd commit 5184d1a

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
@@ -280,13 +280,14 @@ func (key *MasterKey) TypeToIdentifier() string {
280280
// It returns an error if the ResourceID is invalid, or if the setup of the
281281
// client fails.
282282
func (key *MasterKey) newKMSClient(ctx context.Context) (*kms.KeyManagementClient, error) {
283-
re := regexp.MustCompile(`^projects/[^/]+/locations/[^/]+/keyRings/[^/]+/cryptoKeys/[^/]+$`)
283+
re := regexp.MustCompile(`^projects/(?P<project>[^/]+)/locations/[^/]+/keyRings/[^/]+/cryptoKeys/[^/]+$`)
284284
matches := re.FindStringSubmatch(key.ResourceID)
285285
if matches == nil {
286286
return nil, fmt.Errorf("no valid resource ID found in %q", key.ResourceID)
287287
}
288288

289289
var opts []option.ClientOption
290+
opts = append(opts, option.WithQuotaProject(matches[1]))
290291
switch {
291292
case key.tokenSource != nil:
292293
opts = append(opts, option.WithTokenSource(key.tokenSource))

0 commit comments

Comments
 (0)