Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error reporting for missing gpg binary #1286

Merged
merged 2 commits into from
Oct 9, 2023

Conversation

makkes
Copy link
Contributor

@makkes makkes commented Sep 15, 2023

The error returned by gpgExec has just been swallowed. Now it is stringified and returned together with any output to stderr.

@makkes
Copy link
Contributor Author

makkes commented Sep 15, 2023

@hiddeco I can't directly add you as a reviewer but would you mind reviewing this so we can close out fluxcd/kustomize-controller#966, pls?

pgp/keysource_test.go Outdated Show resolved Hide resolved
@makkes makkes force-pushed the better-import-error branch from e241bdc to 1f60e10 Compare September 15, 2023 14:36
pgp/keysource.go Outdated Show resolved Hide resolved
hiddeco
hiddeco previously approved these changes Sep 19, 2023
Copy link
Member

@hiddeco hiddeco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @makkes 🥇

@hiddeco hiddeco dismissed their stale review September 19, 2023 21:57

Second thoughts

assert.Error(t, gnuPGHome.Import([]byte("invalid armored data")))
err = gnuPGHome.Import([]byte("invalid armored data"))
assert.Error(t, err)
assert.ErrorContains(t, err, "gpg: no valid OpenPGP data found.\ngpg: Total number processed: 0\n: exit status 2")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gpg: no valid OpenPGP data found.
gpg: Total number processed: 0
: exit status 2

Does still look far from optimal 😬

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I mean, we can just strip all newlines but I didn't want to change too much.

@hiddeco hiddeco force-pushed the better-import-error branch 2 times, most recently from e1862de to 454ee8b Compare October 9, 2023 22:16
Max Jonas Werner and others added 2 commits October 10, 2023 00:46
The error returned by `gpgExec` has just been swallowed. Now it is
stringified and returned together with any output to stderr.

Signed-off-by: Max Jonas Werner <mail@makk.es>
Looking more at this, it would actually be great if we would detect
multi-line errors from GnuPG in `Import()`, `Decrypt()` and `Encrypt()`
so that we can slightly improve the formatting of the errors with a
newline seperator before the `gpg: ...\ngpg: ...` output. As this would
likely increase readability.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
@hiddeco hiddeco force-pushed the better-import-error branch from 454ee8b to d021b6b Compare October 9, 2023 22:46
Copy link
Member

@hiddeco hiddeco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slightly tuned the message formatting a bit, and think this is the least unpleasant way to deal with this for now.

Thanks a lot for taking care of this @makkes 🙇

@hiddeco hiddeco merged commit 8c89d14 into getsops:main Oct 9, 2023
9 checks passed
mergify bot referenced this pull request in dbsystel/cdk-sops-secrets Oct 11, 2023
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [github.com/getsops/sops/v3](https://github.com/getsops/sops) | require | patch | `v3.8.0` -> `v3.8.1` |

---

### Release Notes

<details>
<summary>getsops/sops (github.com/getsops/sops/v3)</summary>

### [`v3.8.1`](https://github.com/getsops/sops/releases/tag/v3.8.1)

[Compare Source](https://github.com/getsops/sops/compare/v3.8.0...v3.8.1)

#### Note from the Maintainers

In this release of SOPS, we have focused on landing a variety of bug fixes to improve the overall user experience.

For a comprehensive list of changes, please refer to [`CHANGELOG.rst`](https://github.com/getsops/sops/blob/v3.8.1/CHANGELOG.rst).

##### Important Information for SOPS SDK Users

With the project transitioning from the Mozilla Foundation to the CNCF, the Go module path has been updated to reflect this change in ownership. If you use `go.mozilla.org/sops/v3` as a library, going forward, import the Go Module using `github.com/getsops/sops/v3`. Apart from this small adjustment, the SDK's API remains fully backward compatible.

For a one-liner to quickly implement this change throughout your codebase, please refer to: [https://github.com/getsops/sops/issues/1246#issuecomment-1625526429](https://github.com/getsops/sops/issues/1246#issuecomment-1625526429)

#### 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.8.1/sops-v3.8.1.linux.amd64

### Move the binary in to your PATH
mv sops-v3.8.1.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.8.1/sops-v3.8.1.checksums.txt
curl -LO https://github.com/getsops/sops/releases/download/v3.8.1/sops-v3.8.1.checksums.pem
curl -LO https://github.com/getsops/sops/releases/download/v3.8.1/sops-v3.8.1.checksums.sig

### Verify the checksums file
cosign verify-blob sops-v3.8.1.checksums.txt \
  --certificate sops-v3.8.1.checksums.pem \
  --signature sops-v3.8.1.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.8.1.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.8.1.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.8.1/sops-v3.8.1.intoto.jsonl

### Verify the provenance of the artifact
slsa-verifier verify-artifact <artifact> \
  --provenance-path sops-v3.8.1.intoto.jsonl \
  --source-uri github.com/getsops/sops \
  --source-tag v3.8.1
```

#### 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.8.1`
-   `ghcr.io/getsops/sops:v3.8.1-alpine`

##### Quay.io

-   `quay.io/getsops/sops:v3.8.1`
-   `quay.io/getsops/sops:v3.8.1-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.8.1 \
  --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

-   build(deps): Bump the ci group with 3 updates by [@&#8203;dependabot](https://github.com/dependabot) in [https://github.com/getsops/sops/pull/1295](https://github.com/getsops/sops/pull/1295)
-   pgp: improve handling of GnuPG home dir by [@&#8203;hiddeco](https://github.com/hiddeco) in [https://github.com/getsops/sops/pull/1298](https://github.com/getsops/sops/pull/1298)
-   Delete sops encrypted file we don't have keys for by [@&#8203;felixfontein](https://github.com/felixfontein) in [https://github.com/getsops/sops/pull/1288](https://github.com/getsops/sops/pull/1288)
-   Improve handling of errors when binary store handles bad data by [@&#8203;felixfontein](https://github.com/felixfontein) in [https://github.com/getsops/sops/pull/1289](https://github.com/getsops/sops/pull/1289)
-   On macOS, prefer XDG_CONFIG_HOME over os.UserConfigDir() by [@&#8203;felixfontein](https://github.com/felixfontein) in [https://github.com/getsops/sops/pull/1291](https://github.com/getsops/sops/pull/1291)
-   Do not crash if an empty YAML file is encrypted by [@&#8203;felixfontein](https://github.com/felixfontein) in [https://github.com/getsops/sops/pull/1290](https://github.com/getsops/sops/pull/1290)
-   Fix descriptions of unencrypted-regex and encrypted-regex flags, and ensure unencrypted_regex is considered in config validation by [@&#8203;mitar](https://github.com/mitar) in [https://github.com/getsops/sops/pull/1300](https://github.com/getsops/sops/pull/1300)
-   build(deps): Bump the go group with 4 updates by [@&#8203;dependabot](https://github.com/dependabot) in [https://github.com/getsops/sops/pull/1306](https://github.com/getsops/sops/pull/1306)
-   build(deps): Bump the ci group with 1 update by [@&#8203;dependabot](https://github.com/dependabot) in [https://github.com/getsops/sops/pull/1301](https://github.com/getsops/sops/pull/1301)
-   Handle return values of dec.Token() to improve error messages by [@&#8203;felixfontein](https://github.com/felixfontein) in [https://github.com/getsops/sops/pull/1307](https://github.com/getsops/sops/pull/1307)
-   pgp: make error the last return value by [@&#8203;felixfontein](https://github.com/felixfontein) in [https://github.com/getsops/sops/pull/1310](https://github.com/getsops/sops/pull/1310)
-   pgp: do not require abs path for SopsGpgExecEnv  by [@&#8203;holiman](https://github.com/holiman) in [https://github.com/getsops/sops/pull/1309](https://github.com/getsops/sops/pull/1309)
-   decrypt: fix dropped error by [@&#8203;alrs](https://github.com/alrs) in [https://github.com/getsops/sops/pull/1304](https://github.com/getsops/sops/pull/1304)
-   Handle errors by [@&#8203;felixfontein](https://github.com/felixfontein) in [https://github.com/getsops/sops/pull/1311](https://github.com/getsops/sops/pull/1311)
-   Report key rotation errors by [@&#8203;felixfontein](https://github.com/felixfontein) in [https://github.com/getsops/sops/pull/1317](https://github.com/getsops/sops/pull/1317)
-   cmd/sops/main.go: make sure to wrap raw errors with toExitError() by [@&#8203;felixfontein](https://github.com/felixfontein) in [https://github.com/getsops/sops/pull/1318](https://github.com/getsops/sops/pull/1318)
-   build(deps): Bump the go group with 7 updates by [@&#8203;dependabot](https://github.com/dependabot) in [https://github.com/getsops/sops/pull/1319](https://github.com/getsops/sops/pull/1319)
-   Enrich AWS authentication documentation by [@&#8203;nsantiago2719](https://github.com/nsantiago2719) in [https://github.com/getsops/sops/pull/1272](https://github.com/getsops/sops/pull/1272)
-   Better error reporting for missing gpg binary by [@&#8203;makkes](https://github.com/makkes) in [https://github.com/getsops/sops/pull/1286](https://github.com/getsops/sops/pull/1286)
-   Improve RST and MD files by [@&#8203;felixfontein](https://github.com/felixfontein) in [https://github.com/getsops/sops/pull/1320](https://github.com/getsops/sops/pull/1320)
-   Add linting for RST and MD files by [@&#8203;felixfontein](https://github.com/felixfontein) in [https://github.com/getsops/sops/pull/1287](https://github.com/getsops/sops/pull/1287)
-   Update dependencies by [@&#8203;hiddeco](https://github.com/hiddeco) in [https://github.com/getsops/sops/pull/1325](https://github.com/getsops/sops/pull/1325)
-   Prepare v3.8.1 by [@&#8203;hiddeco](https://github.com/hiddeco) in [https://github.com/getsops/sops/pull/1324](https://github.com/getsops/sops/pull/1324)

#### New Contributors

-   [@&#8203;mitar](https://github.com/mitar) made their first contribution in [https://github.com/getsops/sops/pull/1300](https://github.com/getsops/sops/pull/1300)
-   [@&#8203;holiman](https://github.com/holiman) made their first contribution in [https://github.com/getsops/sops/pull/1309](https://github.com/getsops/sops/pull/1309)
-   [@&#8203;alrs](https://github.com/alrs) made their first contribution in [https://github.com/getsops/sops/pull/1304](https://github.com/getsops/sops/pull/1304)
-   [@&#8203;nsantiago2719](https://github.com/nsantiago2719) made their first contribution in [https://github.com/getsops/sops/pull/1272](https://github.com/getsops/sops/pull/1272)
-   [@&#8203;makkes](https://github.com/makkes) made their first contribution in [https://github.com/getsops/sops/pull/1286](https://github.com/getsops/sops/pull/1286)

**Full Changelog**: getsops/sops@v3.8.0...v3.8.1

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/markussiebert/cdk-sops-secrets).
@makkes makkes deleted the better-import-error branch April 8, 2024 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants