diff --git a/gcpkms/keysource.go b/gcpkms/keysource.go index 8ff51357d..3aa54b6e1 100644 --- a/gcpkms/keysource.go +++ b/gcpkms/keysource.go @@ -208,13 +208,14 @@ func (key *MasterKey) TypeToIdentifier() string { // It returns an error if the ResourceID is invalid, or if the setup of the // client fails. func (key *MasterKey) newKMSClient() (*kms.KeyManagementClient, error) { - re := regexp.MustCompile(`^projects/[^/]+/locations/[^/]+/keyRings/[^/]+/cryptoKeys/[^/]+$`) + re := regexp.MustCompile(`^projects/(?P[^/]+)/locations/[^/]+/keyRings/[^/]+/cryptoKeys/[^/]+$`) matches := re.FindStringSubmatch(key.ResourceID) if matches == nil { return nil, fmt.Errorf("no valid resource ID found in %q", key.ResourceID) } var opts []option.ClientOption + opts = append(opts, option.WithQuotaProject(matches[1])) switch { case key.credentialJSON != nil: opts = append(opts, option.WithCredentialsJSON(key.credentialJSON))