fix(gcpkms): Set quota project to API project#1697
fix(gcpkms): Set quota project to API project#1697felixfontein merged 2 commits intogetsops:mainfrom
Conversation
|
This is a lovely PR, bummed to find it sitting unmerged after hitting this same issue. Anything I can do to help? |
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 getsops#1142 Signed-off-by: Johannes Rothe <mail@johannes-rothe.de>
|
I just rebased, the change is waiting for someone to review and merge :) |
|
Kk maybe this will help. Here's a manual test of this fix. Before$ sops --version
sops 3.11.0 (latest)
[warning] Note that in a future version, sops will no longer check whether the current version is the latest when asking for sops' version. If you want to explicitly check for the latest version, add the `--check-for-updates` option to `sops --version`. This will hide this deprecation warning and will always check, even if the default behavior changes in the future.
$ cat ~/.config/gcloud/application_default_credentials.json | jq '.quota_project_id'
"gpo-eng-stage"^^ as noted by @haizaar on #1142 - if the application default creds have a quota project ID set, sops will execute the KMS API call against this GCP project. $ cat .sops.yaml
creation_rules:
- path_regex: secrets.stage.env
gcp_kms: 'projects/gpo-bootstrap-2/locations/global/keyRings/sops-stage/cryptoKeys/sops-stage'^^ my sops config references a key in a project called $ sops encrypt secrets.stage.env
Could not generate data key: [failed to encrypt new data key with master key "projects/gpo-bootstrap-2/locations/global/keyRings/sops-stage/cryptoKeys/sops-stage": failed to encrypt sops data key with GCP KMS key: rpc error: code = PermissionDenied desc = Cloud Key Management Service (KMS) API has not been used in project gpo-eng-stage before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/cloudkms.googleapis.com/overview?project=gpo-eng-stage then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.
error details: name = ErrorInfo reason = SERVICE_DISABLED domain = googleapis.com metadata = map[activationUrl:https://console.developers.google.com/apis/api/cloudkms.googleapis.com/overview?project=gpo-eng-stage consumer:projects/gpo-eng-stage containerInfo:gpo-eng-stage service:cloudkms.googleapis.com serviceTitle:Cloud Key Management Service (KMS) API]
error details: name = Help desc = Google developers console API activation url = https://console.developers.google.com/apis/api/cloudkms.googleapis.com/overview?project=gpo-eng-stage
error details: name = LocalizedMessage locale = en-US msg = Cloud Key Management Service (KMS) API has not been used in project gpo-eng-stage before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/cloudkms.googleapis.com/overview?project=gpo-eng-stage then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.]^^ since the KMS API is not enabled in my default quota project, the call fails. After$ git fetch origin pull/1697/head:pr-1697
remote: Enumerating objects: 7, done.
remote: Counting objects: 100% (7/7), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 4 (delta 2), reused 4 (delta 2), pack-reused 0 (from 0)
Unpacking objects: 100% (4/4), 723 bytes | 144.00 KiB/s, done.
From https://github.com/getsops/sops
* [new ref] refs/pull/1697/head -> pr-1697
$ git checkout pr-1697
Previous HEAD position was 168736311 Merge pull request #1960 from felixfontein/release-3.11.0
Switched to branch 'pr-1697'
$ go mod vendor
$ make install
$ ls -alh $(which sops)
-rwxr-xr-x 1 rsa staff 64M Dec 6 14:04 /Users/rsa/go/bin/sops
$ cat ~/.config/gcloud/application_default_credentials.json | jq '.quota_project_id'
"gpo-eng-stage"^^ nothing up my sleeve, I haven't removed the quota project from my config. $ sops encrypt secrets.stage.env
FOO=ENC[AES256_GCM,data:Vp/O,iv:dUg3Fk08wmuLQO+frKtGxtRjO4L4NRjC7LRZc18SBr0=,tag:51dTO7CKQaGXQSwzpaG5dg==,type:str]
sops_gcp_kms__list_0__map_created_at=2025-12-06T19:04:48Z
sops_gcp_kms__list_0__map_enc=CiQA2wUFSfdnLQ9Jp8h9aHw5bpIkGIuWGIBQrZ/dCyTfBqoNy1ASSQAv0ygTdz3jBcOLwg6DouLFM2per/DBFwbQ0I4LUX9/VUOuqt79GZ2YuUvpFED06ARnlhEcXvZTzQ8Y/G0M9n9aYxuVED4x6cg=
sops_gcp_kms__list_0__map_resource_id=projects/gpo-bootstrap-2/locations/global/keyRings/sops-stage/cryptoKeys/sops-stage
sops_lastmodified=2025-12-06T19:04:48Z
sops_mac=ENC[AES256_GCM,data:yyU4JSe0/EFpkGtG3bdUCdJ5mLIIqw0nF+MOjT0QewygNGVWJGsptoljN43ZKSTj4OdZla2ocCaNfk5CYRQESU8zJv6d+UWoG2zrvi2MzFA8TNwuhtObbftUWRqAdW+4xxcqp6EuXhS1UJQ+Qj1+1GLSU6hUoifN9Hw1l/rRdBg=,iv:IJA/4qJGyM6lPg2MerW5tEhVwt71wvMvS2Qfe3PCZMQ=,tag:b4I92AeKh1OJSt505BwObA==,type:str]
sops_unencrypted_suffix=_unencrypted
sops_version=3.11.0🚀 |
|
@onjen @rsalmond @sabre1041 thanks for fixing this! |
|
We use Our stores:
yaml:
indent: 2
creation_rules:
- path_regex: hb/it/.*
gcp_kms: projects/REDACTED/locations/europe-west3/keyRings/sops-hsm/cryptoKeys/hb-itThis is what I run locally for the default credentials: gcloud auth application-default login --scopes=https://www.googleapis.com/auth/chat.messages,openid,https://www.googleapis.com/auth/userinfo.email,https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/chat.messages.createAnd this returns cat ~/.config/gcloud/application_default_credentials.json | jq '.quota_project_id'This was working prior to @onjen or @sabre1041, do you have time to have a look here? |
|
I couldn't tell you why it was working previously, but I know that the |
|
I have the same issue than @moritzschmitz-oviva, fails since
|
|
Heya, I'm not a maintainer (or even a contributor) to sops but I sorta kinda understand how it works with GCP. If you wanna open a new issue with steps to repro (help me get a brand new GCP project into a state that matches your environment) and tag me on it and I'll spend some time next week trying to investigate. |
|
@rsalmond, I created a new issue here: #2088 (comment). Just FYI 😆. I added a guide on how to reproduce at the end. |
Revert "Merge pull request #1697 from onjen/fix-1142"
|
We reverted the change for now; there's now a discussion #2108 about how the behavior should be. |
* Delete temporary file on termination. Signed-off-by: Felix Fontein <felix@fontein.de> * build(deps): Bump the ci group with 4 updates Bumps the ci group with 4 updates: [actions/download-artifact](https://github.com/actions/download-artifact), [github/codeql-action](https://github.com/github/codeql-action), [anchore/sbom-action](https://github.com/anchore/sbom-action) and [sigstore/cosign-installer](https://github.com/sigstore/cosign-installer). Updates `actions/download-artifact` from 8.0.0 to 8.0.1 - [Release notes](https://github.com/actions/download-artifact/releases) - [Commits](actions/download-artifact@70fc10c...3e5f45b) Updates `github/codeql-action` from 4.32.6 to 4.33.0 - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](github/codeql-action@0d579ff...b1bff81) Updates `anchore/sbom-action` from 0.23.0 to 0.23.1 - [Release notes](https://github.com/anchore/sbom-action/releases) - [Changelog](https://github.com/anchore/sbom-action/blob/main/RELEASE.md) - [Commits](anchore/sbom-action@17ae174...57aae52) Updates `sigstore/cosign-installer` from 4.0.0 to 4.1.0 - [Release notes](https://github.com/sigstore/cosign-installer/releases) - [Commits](sigstore/cosign-installer@faadad0...ba7bc0a) --- updated-dependencies: - dependency-name: actions/download-artifact dependency-version: 8.0.1 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: ci - dependency-name: github/codeql-action dependency-version: 4.33.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: ci - dependency-name: anchore/sbom-action dependency-version: 0.23.1 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: ci - dependency-name: sigstore/cosign-installer dependency-version: 4.1.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: ci ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): Bump tempfile in /functional-tests in the rust group Bumps the rust group in /functional-tests with 1 update: [tempfile](https://github.com/Stebalien/tempfile). Updates `tempfile` from 3.26.0 to 3.27.0 - [Changelog](https://github.com/Stebalien/tempfile/blob/master/CHANGELOG.md) - [Commits](Stebalien/tempfile@v3.26.0...v3.27.0) --- updated-dependencies: - dependency-name: tempfile dependency-version: 3.27.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: rust ... Signed-off-by: dependabot[bot] <support@github.com> * Revert "Merge pull request getsops#1697 from onjen/fix-1142" This reverts commit 37fe172, reversing changes made to bf5e7ae. Signed-off-by: Felix Fontein <felix@fontein.de> * Add 3.12.2 changelog entry. Signed-off-by: Felix Fontein <felix@fontein.de> * Set version to 3.12.2. Signed-off-by: Felix Fontein <felix@fontein.de> * build(deps): Bump google.golang.org/grpc from 1.79.1 to 1.79.3 Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.79.1 to 1.79.3. - [Release notes](https://github.com/grpc/grpc-go/releases) - [Commits](grpc/grpc-go@v1.79.1...v1.79.3) --- updated-dependencies: - dependency-name: google.golang.org/grpc dependency-version: 1.79.3 dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): Bump the ci group with 3 updates Bumps the ci group with 3 updates: [actions/cache](https://github.com/actions/cache), [github/codeql-action](https://github.com/github/codeql-action) and [anchore/sbom-action](https://github.com/anchore/sbom-action). Updates `actions/cache` from 5.0.3 to 5.0.4 - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](actions/cache@cdf6c1f...6682284) Updates `github/codeql-action` from 4.33.0 to 4.34.1 - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](github/codeql-action@b1bff81...3869755) Updates `anchore/sbom-action` from 0.23.1 to 0.24.0 - [Release notes](https://github.com/anchore/sbom-action/releases) - [Changelog](https://github.com/anchore/sbom-action/blob/main/RELEASE.md) - [Commits](anchore/sbom-action@57aae52...e22c389) --- updated-dependencies: - dependency-name: actions/cache dependency-version: 5.0.4 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: ci - dependency-name: github/codeql-action dependency-version: 4.34.1 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: ci - dependency-name: anchore/sbom-action dependency-version: 0.24.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: ci ... Signed-off-by: dependabot[bot] <support@github.com> --------- Signed-off-by: Felix Fontein <felix@fontein.de> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This MR contains the following updates: | Package | Update | Change | |---|---|---| | [getsops/sops](https://github.com/getsops/sops) | patch | `v3.12.1` → `v3.12.2` | MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot). **Proposed changes to behavior should be submitted there as MRs.** --- ### Release Notes <details> <summary>getsops/sops (getsops/sops)</summary> ### [`v3.12.2`](https://github.com/getsops/sops/releases/tag/v3.12.2) [Compare Source](getsops/sops@v3.12.1...v3.12.2) #### Installation To install `sops`, download one of the pre-built binaries provided for your platform from the artifacts attached to this release. For instance, if you are using Linux on an AMD64 architecture: ```shell # Download the binary curl -LO https://github.com/getsops/sops/releases/download/v3.12.2/sops-v3.12.2.linux.amd64 # Move the binary in to your PATH mv sops-v3.12.2.linux.amd64 /usr/local/bin/sops # Make the binary executable chmod +x /usr/local/bin/sops ``` ##### Verify checksums file signature The checksums file provided within the artifacts attached to this release is signed using [Cosign](https://docs.sigstore.dev/cosign/overview/) with GitHub OIDC. To validate the signature of this file, run the following commands: ```shell # Download the checksums file, certificate and signature curl -LO https://github.com/getsops/sops/releases/download/v3.12.2/sops-v3.12.2.checksums.txt curl -LO https://github.com/getsops/sops/releases/download/v3.12.2/sops-v3.12.2.checksums.pem curl -LO https://github.com/getsops/sops/releases/download/v3.12.2/sops-v3.12.2.checksums.sig # Verify the checksums file cosign verify-blob sops-v3.12.2.checksums.txt \ --certificate sops-v3.12.2.checksums.pem \ --signature sops-v3.12.2.checksums.sig \ --certificate-identity-regexp=https://github.com/getsops \ --certificate-oidc-issuer=https://token.actions.githubusercontent.com ``` ##### Verify binary integrity To verify the integrity of the downloaded binary, you can utilize the checksums file after having validated its signature: ```shell # Verify the binary using the checksums file sha256sum -c sops-v3.12.2.checksums.txt --ignore-missing ``` ##### Verify artifact provenance The [SLSA provenance](https://slsa.dev/provenance/v0.2) of the binaries, packages, and SBOMs can be found within the artifacts associated with this release. It is presented through an [in-toto](https://in-toto.io/) link metadata file named `sops-v3.12.2.intoto.jsonl`. To verify the provenance of an artifact, you can utilize the [`slsa-verifier`](https://github.com/slsa-framework/slsa-verifier#artifacts) tool: ```shell # Download the metadata file curl -LO https://github.com/getsops/sops/releases/download/v3.12.2/sops-v3.12.2.intoto.jsonl # Verify the provenance of the artifact slsa-verifier verify-artifact <artifact> \ --provenance-path sops-v3.12.2.intoto.jsonl \ --source-uri github.com/getsops/sops \ --source-tag v3.12.2 ``` #### Container Images The `sops` binaries are also available as container images, based on Debian (slim) and Alpine Linux. The Debian-based container images include any dependencies which may be required to make use of certain key services, such as GnuPG, AWS KMS, Azure Key Vault, and Google Cloud KMS. The Alpine-based container images are smaller in size, but do not include these dependencies. These container images are available for the following architectures: `linux/amd64` and `linux/arm64`. ##### GitHub Container Registry - `ghcr.io/getsops/sops:v3.12.2` - `ghcr.io/getsops/sops:v3.12.2-alpine` ##### Quay.io - `quay.io/getsops/sops:v3.12.2` - `quay.io/getsops/sops:v3.12.2-alpine` ##### Verify container image signature The container images are signed using [Cosign](https://docs.sigstore.dev/cosign/overview/) with GitHub OIDC. To validate the signature of an image, run the following command: ```shell cosign verify ghcr.io/getsops/sops:v3.12.2 \ --certificate-identity-regexp=https://github.com/getsops \ --certificate-oidc-issuer=https://token.actions.githubusercontent.com \ -o text ``` ##### Verify container image provenance The container images include [SLSA provenance](https://slsa.dev/provenance/v0.2) attestations. For more information around the verification of this, please refer to the [`slsa-verifier` documentation](https://github.com/slsa-framework/slsa-verifier#containers). #### Software Bill of Materials The Software Bill of Materials (SBOM) for each binary is accessible within the artifacts enclosed with this release. It is presented as an [SPDX](https://spdx.dev/) JSON file, formatted as `<binary>.spdx.sbom.json`. #### What's Changed - CI: Rearrange steps; disable setup-go's caching by [@​felixfontein](https://github.com/felixfontein) in [#​2081](getsops/sops#2081) - build(deps): Bump the go group with 6 updates by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2085](getsops/sops#2085) - build(deps): Bump the ci group with 2 updates by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2084](getsops/sops#2084) - build(deps): Bump github.com/cloudflare/circl from 1.6.1 to 1.6.3 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2087](getsops/sops#2087) - build(deps): Bump go.opentelemetry.io/otel/sdk from 1.39.0 to 1.40.0 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2089](getsops/sops#2089) - build(deps): Bump the ci group with 4 updates by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2091](getsops/sops#2091) - build(deps): Bump tempfile from 3.25.0 to 3.26.0 in /functional-tests in the rust group by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2090](getsops/sops#2090) - build(deps): Bump github.com/docker/cli from 28.0.4+incompatible to 29.2.0+incompatible by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2095](getsops/sops#2095) - build(deps): Bump the ci group with 4 updates by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2101](getsops/sops#2101) - Check for metadata key(s) before re-encrypting file by [@​felixfontein](https://github.com/felixfontein) in [#​2098](getsops/sops#2098) - fix: handle mac only encrypted flag in global by [@​CzBiX](https://github.com/CzBiX) in [#​2100](getsops/sops#2100) - sops edit: delete temporary file on termination by [@​felixfontein](https://github.com/felixfontein) in [#​2104](getsops/sops#2104) - build(deps): Bump the ci group with 4 updates by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2106](getsops/sops#2106) - build(deps): Bump tempfile from 3.26.0 to 3.27.0 in /functional-tests in the rust group by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2105](getsops/sops#2105) - Revert "Merge pull request [#​1697](getsops/sops#1697) from onjen/fix-1142" by [@​felixfontein](https://github.com/felixfontein) in [#​2099](getsops/sops#2099) - Release 3.12.2 by [@​felixfontein](https://github.com/felixfontein) in [#​2109](getsops/sops#2109) #### New Contributors - [@​CzBiX](https://github.com/CzBiX) made their first contribution in [#​2100](getsops/sops#2100) **Full Changelog**: <getsops/sops@v3.12.1...v3.12.2> </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever MR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this MR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My44Ny4xIiwidXBkYXRlZEluVmVyIjoiNDMuODcuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90IiwiYXV0b21hdGlvbjpib3QtYXV0aG9yZWQiLCJkZXBlbmRlbmN5LXR5cGU6OnBhdGNoIl19-->
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
Fixes #2020