Skip to content

Commit aed3d9c

Browse files
MarvinImmickfelixfonteindependabot[bot]
authored
sync (#2)
* 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>
1 parent 9a2c576 commit aed3d9c

11 files changed

Lines changed: 102 additions & 23 deletions

File tree

.github/workflows/cli.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
cache: false
4141
id: go
4242

43-
- uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
43+
- uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
4444
with:
4545
path: ~/go/pkg/mod
4646
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
@@ -106,7 +106,7 @@ jobs:
106106
- name: Show Rust version
107107
run: cargo --version
108108

109-
- uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0
109+
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
110110
with:
111111
name: sops-${{ matrix.go-version }}-linux-amd64-${{ github.sha }}
112112

.github/workflows/codeql.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535

3636
# Initializes the CodeQL tools for scanning.
3737
- name: Initialize CodeQL
38-
uses: github/codeql-action/init@0d579ffd059c29b07949a3cce3983f0780820c98 # v4.32.6
38+
uses: github/codeql-action/init@38697555549f1db7851b81482ff19f1fa5c4fedc # v4.34.1
3939
with:
4040
languages: go
4141
# xref: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
@@ -52,6 +52,6 @@ jobs:
5252
make install
5353
5454
- name: Perform CodeQL Analysis
55-
uses: github/codeql-action/analyze@0d579ffd059c29b07949a3cce3983f0780820c98 # v4.32.6
55+
uses: github/codeql-action/analyze@38697555549f1db7851b81482ff19f1fa5c4fedc # v4.34.1
5656
with:
5757
category: "/language:go"

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ jobs:
3737
cache: false
3838

3939
- name: Setup Syft
40-
uses: anchore/sbom-action/download-syft@17ae1740179002c89186b61233e0f892c3118b11 # v0.23.0
40+
uses: anchore/sbom-action/download-syft@e22c389904149dbc22b58101806040fa8d37a610 # v0.24.0
4141

4242
- name: Setup Cosign
43-
uses: sigstore/cosign-installer@faadad0cce49287aee09b3a48701e75088a2c6ad # v4.0.0
43+
uses: sigstore/cosign-installer@ba7bc0a3fef59531c69a25acd34668d6d3fe6f22 # v4.1.0
4444
with:
4545
# TODO: update cosign and go-releaser, and adjust go-releaser config
4646
cosign-release: 'v2.6.2'

CHANGELOG.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,36 @@
11
# Changelog
22

3+
## 3.12.2
4+
5+
Improvements:
6+
7+
* Dependency updates ([#2085](https://github.com/getsops/sops/pull/2085),
8+
[#2087](https://github.com/getsops/sops/pull/2087), [#2089](https://github.com/getsops/sops/pull/2089),
9+
[#2095](https://github.com/getsops/sops/pull/2095)).
10+
11+
Bugfixes:
12+
13+
* GCP: Revert the fix introduced in 3.12.0 that sets quota project to API
14+
project in GCP KMS. This change unintentionally resulted in requiring
15+
more permissions for GCP users. The original issue will be addressed in
16+
another way in a future release ([#2099](https://github.com/getsops/sops/pull/2099)).
17+
* Ensure to delete temporary file and directory when editing in more
18+
situations, like when user presses Ctrl+C or SOPS receives a SIGTERM
19+
([#2104](https://github.com/getsops/sops/pull/2104)).
20+
* Fix message that you need to enter (and not any key) after SOPS rejects
21+
an edited file ([#2098](https://github.com/getsops/sops/pull/2098)).
22+
* Reject files with ``sops`` keys when editing files ([#2098](https://github.com/getsops/sops/pull/2098)).
23+
* Fix handling of ``--mac-only-encrypted`` option in subcommands ([#2100](https://github.com/getsops/sops/pull/2100)).
24+
25+
Project changes:
26+
27+
* CI dependency updates ([#2084](https://github.com/getsops/sops/pull/2084),
28+
[#2091](https://github.com/getsops/sops/pull/2091), [#2101](https://github.com/getsops/sops/pull/2101),
29+
[#2106](https://github.com/getsops/sops/pull/2106)).
30+
* Rust dependency updates for functional tests ([#2090](https://github.com/getsops/sops/pull/2090),
31+
[#2105](https://github.com/getsops/sops/pull/2105)).
32+
* Improve CI workflows ([#2081](https://github.com/getsops/sops/pull/2081)).
33+
334
## 3.12.1
435

536
This is a re-release of 3.12.0 with no code changes.

cmd/sops/edit.go

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ package main
33
import (
44
"bufio"
55
"bytes"
6+
"context"
67
"crypto/sha256"
78
"fmt"
89
"io"
910
"os"
11+
"os/signal"
1012
"path/filepath"
1113
"strings"
14+
"syscall"
1215

1316
"github.com/getsops/sops/v3"
1417
"github.com/getsops/sops/v3/cmd/sops/codes"
@@ -96,6 +99,24 @@ func edit(opts editOpts) ([]byte, error) {
9699
return editTree(opts, tree, dataKey)
97100
}
98101

102+
type cancelError struct{}
103+
104+
func (err *cancelError) Error() string {
105+
return "User canceled operation"
106+
}
107+
108+
type editTreeResult struct {
109+
value []byte
110+
err error
111+
}
112+
113+
func createError(err error) editTreeResult {
114+
return editTreeResult{
115+
value: nil,
116+
err: err,
117+
}
118+
}
119+
99120
func editTree(opts editOpts, tree *sops.Tree, dataKey []byte) ([]byte, error) {
100121
// Create temporary file for editing
101122
tmpdir, err := os.MkdirTemp("", "")
@@ -117,33 +138,58 @@ func editTree(opts editOpts, tree *sops.Tree, dataKey []byte) ([]byte, error) {
117138

118139
tmpfileName := tmpfile.Name()
119140

141+
// Catch when the user presses Ctrl+C, or kills SOPS.
142+
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL)
143+
defer stop()
144+
145+
result := make(chan editTreeResult, 1)
146+
147+
// This goroutine handles signals that exit SOPS, that usually lead to termination
148+
// before editTree() can clean up the temporary directory and file.
149+
go func() {
150+
<-ctx.Done()
151+
result <- createError(&cancelError{})
152+
}()
153+
154+
// This goroutine handles regular execution of editing.
155+
go func() {
156+
result <- editTreeImpl(tmpfile, tmpfileName, opts, tree, dataKey)
157+
}()
158+
159+
// Wait until the first result shows up (either an exit is requested, or editTreeImpl returns).
160+
res := <-result
161+
return res.value, res.err
162+
}
163+
164+
func editTreeImpl(tmpfile *os.File, tmpfileName string, opts editOpts, tree *sops.Tree, dataKey []byte) editTreeResult {
120165
// Write to temporary file
121166
var out []byte
167+
var err error
122168
if opts.ShowMasterKeys {
123169
out, err = opts.OutputStore.EmitEncryptedFile(*tree)
124170
} else {
125171
out, err = opts.OutputStore.EmitPlainFile(tree.Branches)
126172
}
127173
if err != nil {
128-
return nil, common.NewExitError(fmt.Sprintf("Could not marshal tree: %s", err), codes.ErrorDumpingTree)
174+
return createError(common.NewExitError(fmt.Sprintf("Could not marshal tree: %s", err), codes.ErrorDumpingTree))
129175
}
130176
_, err = tmpfile.Write(out)
131177
if err != nil {
132-
return nil, common.NewExitError(fmt.Sprintf("Could not write output file: %s", err), codes.CouldNotWriteOutputFile)
178+
return createError(common.NewExitError(fmt.Sprintf("Could not write output file: %s", err), codes.CouldNotWriteOutputFile))
133179
}
134180

135181
// Compute file hash to detect if the file has been edited
136182
origHash, err := hashFile(tmpfileName)
137183
if err != nil {
138-
return nil, common.NewExitError(fmt.Sprintf("Could not hash file: %s", err), codes.CouldNotReadInputFile)
184+
return createError(common.NewExitError(fmt.Sprintf("Could not hash file: %s", err), codes.CouldNotReadInputFile))
139185
}
140186

141187
// Close the temporary file, so that an editor can open it.
142188
// We need to do this because some editors (e.g. VSCode) will refuse to
143189
// open a file on Windows due to the Go standard library not opening
144190
// files with shared delete access.
145191
if err := tmpfile.Close(); err != nil {
146-
return nil, err
192+
return createError(err)
147193
}
148194

149195
// Let the user edit the file
@@ -155,23 +201,26 @@ func editTree(opts editOpts, tree *sops.Tree, dataKey []byte) ([]byte, error) {
155201
ShowMasterKeys: opts.ShowMasterKeys,
156202
Tree: tree})
157203
if err != nil {
158-
return nil, err
204+
return createError(err)
159205
}
160206

161207
// Encrypt the file
162208
err = common.EncryptTree(common.EncryptTreeOpts{
163209
DataKey: dataKey, Tree: tree, Cipher: opts.Cipher,
164210
})
165211
if err != nil {
166-
return nil, err
212+
return createError(err)
167213
}
168214

169215
// Output the file
170216
encryptedFile, err := opts.OutputStore.EmitEncryptedFile(*tree)
171217
if err != nil {
172-
return nil, common.NewExitError(fmt.Sprintf("Could not marshal tree: %s", err), codes.ErrorDumpingTree)
218+
return createError(common.NewExitError(fmt.Sprintf("Could not marshal tree: %s", err), codes.ErrorDumpingTree))
219+
}
220+
return editTreeResult{
221+
value: encryptedFile,
222+
err: nil,
173223
}
174-
return encryptedFile, nil
175224
}
176225

177226
const pressKeyMsg = "Press enter to return to the editor, or Ctrl+C to exit."

functional-tests/Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

functional-tests/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55
authors = ["Adrian Utrilla <adrianutrilla@gmail.com>"]
66

77
[dependencies]
8-
tempfile = "3.26.0"
8+
tempfile = "3.27.0"
99
serde = "1.0"
1010
serde_json = "1.0.149"
1111
serde_yaml = "0.9.34"

gcpkms/keysource.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,14 +280,13 @@ 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/(?P<project>[^/]+)/locations/[^/]+/keyRings/[^/]+/cryptoKeys/[^/]+$`)
283+
re := regexp.MustCompile(`^projects/[^/]+/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]))
291290
switch {
292291
case key.tokenSource != nil:
293292
opts = append(opts, option.WithTokenSource(key.tokenSource))

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ require (
4343
golang.org/x/term v0.40.0
4444
google.golang.org/api v0.267.0
4545
google.golang.org/genproto/googleapis/rpc v0.0.0-20260203192932-546029d2fa20
46-
google.golang.org/grpc v1.79.1
46+
google.golang.org/grpc v1.79.3
4747
google.golang.org/protobuf v1.36.11
4848
gopkg.in/ini.v1 v1.67.1
4949
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,8 @@ google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZi
467467
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
468468
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
469469
google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
470-
google.golang.org/grpc v1.79.1 h1:zGhSi45ODB9/p3VAawt9a+O/MULLl9dpizzNNpq7flY=
471-
google.golang.org/grpc v1.79.1/go.mod h1:KmT0Kjez+0dde/v2j9vzwoAScgEPx/Bw1CYChhHLrHQ=
470+
google.golang.org/grpc v1.79.3 h1:sybAEdRIEtvcD68Gx7dmnwjZKlyfuc61Dyo9pGXXkKE=
471+
google.golang.org/grpc v1.79.3/go.mod h1:KmT0Kjez+0dde/v2j9vzwoAScgEPx/Bw1CYChhHLrHQ=
472472
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
473473
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
474474
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=

0 commit comments

Comments
 (0)