Skip to content

Commit 511bebb

Browse files
authored
Merge branch 'main' into SOPS_AGE_KEY_CMD
2 parents 6c88a9d + fd95030 commit 511bebb

17 files changed

Lines changed: 113 additions & 69 deletions

File tree

.github/workflows/cli.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
VAULT_ADDR: "http://127.0.0.1:8200"
3030
steps:
3131
- name: Set up Go ${{ matrix.go-version }}
32-
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
32+
uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5.4.0
3333
with:
3434
go-version: ${{ matrix.go-version }}
3535
id: go
@@ -39,7 +39,7 @@ jobs:
3939
with:
4040
persist-credentials: false
4141

42-
- uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4.2.2
42+
- uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
4343
with:
4444
path: ~/go/pkg/mod
4545
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
@@ -71,14 +71,14 @@ jobs:
7171

7272
- name: Upload artifact for ${{ matrix.os }}
7373
if: matrix.os != 'windows'
74-
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1
74+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
7575
with:
7676
name: sops-${{ matrix.go-version }}-${{ matrix.os }}-${{ matrix.arch }}-${{ github.sha }}
7777
path: sops-${{ matrix.go-version }}-${{ matrix.os }}-${{ matrix.arch }}-${{ github.sha }}
7878

7979
- name: Upload artifact for ${{ matrix.os }}
8080
if: matrix.os == 'windows'
81-
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1
81+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
8282
with:
8383
name: sops-${{ matrix.go-version }}-${{ matrix.os }}-${{ github.sha }}
8484
path: sops-${{ matrix.go-version }}-${{ matrix.os }}-${{ github.sha }}
@@ -108,7 +108,7 @@ jobs:
108108
- name: Show Rust version
109109
run: cargo --version
110110

111-
- uses: actions/download-artifact@cc203385981b70ca67e1cc392babf9cc229d5806 # v4.1.9
111+
- uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
112112
with:
113113
name: sops-${{ matrix.go-version }}-linux-amd64-${{ github.sha }}
114114

.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@6bb031afdd8eb862ea3fc1848194185e076637e5 # v3.28.11
38+
uses: github/codeql-action/init@5f8171a638ada777af81d42b55959a643bb29017 # v3.28.12
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@6bb031afdd8eb862ea3fc1848194185e076637e5 # v3.28.11
55+
uses: github/codeql-action/analyze@5f8171a638ada777af81d42b55959a643bb29017 # v3.28.12
5656
with:
5757
category: "/language:go"

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
persist-credentials: false
3232

3333
- name: Setup Go
34-
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v4.0.1
34+
uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v4.0.1
3535
with:
3636
go-version-file: go.mod
3737
cache: false

age/keysource_test.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,9 @@ func TestMasterKey_Identities_Passphrase(t *testing.T) {
548548
t.Setenv(SopsAgeKeyEnv, mockEncryptedIdentity)
549549
//blocks calling gpg-agent
550550
os.Unsetenv("XDG_RUNTIME_DIR")
551-
t.Setenv(SopsAgePasswordEnv, mockIdentityPassphrase)
551+
testOnlyAgePassword = mockIdentityPassphrase
552552
got, err := key.Decrypt()
553+
testOnlyAgePassword = ""
553554

554555
assert.NoError(t, err)
555556
assert.EqualValues(t, mockEncryptedKeyPlain, got)
@@ -567,9 +568,11 @@ func TestMasterKey_Identities_Passphrase(t *testing.T) {
567568
t.Setenv(SopsAgeKeyFileEnv, keyPath)
568569
//blocks calling gpg-agent
569570
os.Unsetenv("XDG_RUNTIME_DIR")
570-
t.Setenv(SopsAgePasswordEnv, mockIdentityPassphrase)
571+
testOnlyAgePassword = mockIdentityPassphrase
571572

572573
got, err := key.Decrypt()
574+
testOnlyAgePassword = ""
575+
573576
assert.NoError(t, err)
574577
assert.EqualValues(t, mockEncryptedKeyPlain, got)
575578
})
@@ -579,9 +582,11 @@ func TestMasterKey_Identities_Passphrase(t *testing.T) {
579582
t.Setenv(SopsAgeKeyEnv, mockEncryptedIdentity)
580583
//blocks calling gpg-agent
581584
os.Unsetenv("XDG_RUNTIME_DIR")
582-
t.Setenv(SopsAgePasswordEnv, mockIdentityPassphrase)
585+
testOnlyAgePassword = mockIdentityPassphrase
583586

584587
got, err := key.Decrypt()
588+
testOnlyAgePassword = ""
589+
585590
assert.Error(t, err)
586591
assert.ErrorContains(t, err, "failed to create reader for decrypting sops data key with age")
587592
assert.Nil(t, got)

age/tui.go

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ import (
2222
"golang.org/x/term"
2323
)
2424

25-
const (
26-
SopsAgePasswordEnv = "SOPS_AGE_PASSWORD"
27-
)
25+
var testOnlyAgePassword string
2826

2927
func printf(format string, v ...interface{}) {
3028
log.Printf("age: "+format, v...)
@@ -34,20 +32,6 @@ func warningf(format string, v ...interface{}) {
3432
log.Printf("age: warning: "+format, v...)
3533
}
3634

37-
// If testOnlyPanicInsteadOfExit is true, exit will set testOnlyDidExit and
38-
// panic instead of calling os.Exit. This way, the wrapper in TestMain can
39-
// recover the panic and return the exit code only if it was originated in exit.
40-
var testOnlyPanicInsteadOfExit bool
41-
var testOnlyDidExit bool
42-
43-
func exit(code int) {
44-
if testOnlyPanicInsteadOfExit {
45-
testOnlyDidExit = true
46-
panic(code)
47-
}
48-
os.Exit(code)
49-
}
50-
5135
// clearLine clears the current line on the terminal, or opens a new line if
5236
// terminal escape codes don't work.
5337
func clearLine(out io.Writer) {
@@ -96,9 +80,8 @@ func withTerminal(f func(in, out *os.File) error) error {
9680
// readSecret reads a value from the terminal with no echo. The prompt is ephemeral.
9781
func readSecret(prompt string) (s []byte, err error) {
9882
if testing.Testing() {
99-
password := os.Getenv(SopsAgePasswordEnv)
100-
if password != "" {
101-
return []byte(password), nil
83+
if testOnlyAgePassword != "" {
84+
return []byte(testOnlyAgePassword), nil
10285
}
10386
}
10487

azkv/keysource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func NewMasterKeyFromURL(url string) (*MasterKey, error) {
7979
url = strings.TrimSpace(url)
8080
re := regexp.MustCompile("^(https://[^/]+)/keys/([^/]+)/([^/]+)$")
8181
parts := re.FindStringSubmatch(url)
82-
if parts == nil || len(parts) < 3 {
82+
if len(parts) < 3 {
8383
return nil, fmt.Errorf("could not parse %q into a valid Azure Key Vault MasterKey", url)
8484
}
8585
return NewMasterKey(parts[1], parts[2], parts[3]), nil

cmd/sops/common/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func GetKMSKeyWithEncryptionCtx(tree *sops.Tree) (keyGroupIndex int, keyIndex in
222222
for n, k := range kg {
223223
kmsKey, ok := k.(*kms.MasterKey)
224224
if ok {
225-
if kmsKey.EncryptionContext != nil && len(kmsKey.EncryptionContext) >= 2 {
225+
if len(kmsKey.EncryptionContext) >= 2 {
226226
duplicateValues := map[string]int{}
227227
for _, v := range kmsKey.EncryptionContext {
228228
duplicateValues[*v] = duplicateValues[*v] + 1

cmd/sops/main.go

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,15 @@ func main() {
359359
if c.Bool("verbose") || c.GlobalBool("verbose") {
360360
logging.SetLevel(logrus.DebugLevel)
361361
}
362-
configPath, err := config.FindConfigFile(".")
363-
if err != nil {
364-
return common.NewExitError(err, codes.ErrorGeneric)
362+
var configPath string
363+
var err error
364+
if c.GlobalString("config") != "" {
365+
configPath = c.GlobalString("config")
366+
} else {
367+
configPath, err = config.FindConfigFile(".")
368+
if err != nil {
369+
return common.NewExitError(err, codes.ErrorGeneric)
370+
}
365371
}
366372
if c.NArg() < 1 {
367373
return common.NewExitError("Error: no file specified", codes.NoFileSpecified)
@@ -690,12 +696,12 @@ func main() {
690696
failedCounter := 0
691697
for _, path := range c.Args() {
692698
err := updatekeys.UpdateKeys(updatekeys.Opts{
693-
InputPath: path,
694-
GroupQuorum: c.Int("shamir-secret-sharing-threshold"),
695-
KeyServices: keyservices(c),
696-
Interactive: !c.Bool("yes"),
697-
ConfigPath: configPath,
698-
InputType: c.String("input-type"),
699+
InputPath: path,
700+
ShamirThreshold: c.Int("shamir-secret-sharing-threshold"),
701+
KeyServices: keyservices(c),
702+
Interactive: !c.Bool("yes"),
703+
ConfigPath: configPath,
704+
InputType: c.String("input-type"),
699705
})
700706

701707
if c.NArg() == 1 {
@@ -785,6 +791,11 @@ func main() {
785791
fileNameOverride := c.String("filename-override")
786792
if fileNameOverride == "" {
787793
fileNameOverride = fileName
794+
} else {
795+
fileNameOverride, err = filepath.Abs(fileNameOverride)
796+
if err != nil {
797+
return toExitError(err)
798+
}
788799
}
789800

790801
inputStore, err := inputStore(c, fileNameOverride)
@@ -966,6 +977,11 @@ func main() {
966977
fileNameOverride := c.String("filename-override")
967978
if fileNameOverride == "" {
968979
fileNameOverride = fileName
980+
} else {
981+
fileNameOverride, err = filepath.Abs(fileNameOverride)
982+
if err != nil {
983+
return toExitError(err)
984+
}
969985
}
970986

971987
inputStore, err := inputStore(c, fileNameOverride)
@@ -1132,6 +1148,11 @@ func main() {
11321148
fileNameOverride := c.String("filename-override")
11331149
if fileNameOverride == "" {
11341150
fileNameOverride = fileName
1151+
} else {
1152+
fileNameOverride, err = filepath.Abs(fileNameOverride)
1153+
if err != nil {
1154+
return toExitError(err)
1155+
}
11351156
}
11361157

11371158
inputStore, err := inputStore(c, fileNameOverride)
@@ -1769,6 +1790,11 @@ func main() {
17691790
fileNameOverride := c.String("filename-override")
17701791
if fileNameOverride == "" {
17711792
fileNameOverride = fileName
1793+
} else {
1794+
fileNameOverride, err = filepath.Abs(fileNameOverride)
1795+
if err != nil {
1796+
return toExitError(err)
1797+
}
17721798
}
17731799

17741800
commandCount := 0
@@ -2144,7 +2170,7 @@ func keyservices(c *cli.Context) (svcs []keyservice.KeyServiceClient) {
21442170
"address",
21452171
fmt.Sprintf("%s://%s", url.Scheme, addr),
21462172
).Infof("Connecting to key service")
2147-
conn, err := grpc.Dial(addr, opts...)
2173+
conn, err := grpc.NewClient(addr, opts...)
21482174
if err != nil {
21492175
log.Fatalf("failed to listen: %v", err)
21502176
}
@@ -2277,7 +2303,7 @@ func keyGroups(c *cli.Context, file string) ([]sops.KeyGroup, error) {
22772303
if err != nil {
22782304
errMsg = fmt.Sprintf("%s: %s", errMsg, err)
22792305
}
2280-
return nil, fmt.Errorf(errMsg)
2306+
return nil, fmt.Errorf("%s", errMsg)
22812307
}
22822308
return conf.KeyGroups, err
22832309
}

cmd/sops/subcommand/updatekeys/updatekeys.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
// Opts represents key operation options and config
1616
type Opts struct {
1717
InputPath string
18-
GroupQuorum int
18+
ShamirThreshold int
1919
KeyServices []keyservice.KeyServiceClient
2020
DecryptionOrder []string
2121
Interactive bool
@@ -70,8 +70,8 @@ func updateFile(opts Opts) error {
7070
// TODO: use conf.ShamirThreshold instead of tree.Metadata.ShamirThreshold in the next line?
7171
// Or make this configurable?
7272
var shamirThreshold = tree.Metadata.ShamirThreshold
73-
if opts.GroupQuorum != 0 {
74-
shamirThreshold = opts.GroupQuorum
73+
if opts.ShamirThreshold != 0 {
74+
shamirThreshold = opts.ShamirThreshold
7575
}
7676
shamirThreshold = min(shamirThreshold, len(conf.KeyGroups))
7777
var shamirThresholdWillChange = tree.Metadata.ShamirThreshold != shamirThreshold

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.

0 commit comments

Comments
 (0)