Skip to content

Commit 827a02a

Browse files
authored
Merge branch 'main' into fix-1846
2 parents bab8e61 + 225546e commit 827a02a

File tree

20 files changed

+454
-189
lines changed

20 files changed

+454
-189
lines changed

.github/workflows/cli.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ 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@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
32+
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
3333
with:
3434
go-version: ${{ matrix.go-version }}
3535
id: go
3636

3737
- name: Check out code into the Go module directory
38-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
38+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
3939
with:
4040
persist-credentials: false
4141

42-
- uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
42+
- uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
4343
with:
4444
path: ~/go/pkg/mod
4545
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
@@ -92,7 +92,7 @@ jobs:
9292
VAULT_ADDR: "http://127.0.0.1:8200"
9393
steps:
9494
- name: Check out code
95-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
95+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
9696
with:
9797
persist-credentials: false
9898

@@ -105,7 +105,7 @@ jobs:
105105
- name: Show Rust version
106106
run: cargo --version
107107

108-
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
108+
- uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
109109
with:
110110
name: sops-${{ matrix.go-version }}-linux-amd64-${{ github.sha }}
111111

.github/workflows/codeql.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ jobs:
2929

3030
steps:
3131
- name: Checkout code
32-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
32+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
3333
with:
3434
persist-credentials: false
3535

3636
# Initializes the CodeQL tools for scanning.
3737
- name: Initialize CodeQL
38-
uses: github/codeql-action/init@51f77329afa6477de8c49fc9c7046c15b9a4e79d # v3.29.5
38+
uses: github/codeql-action/init@f1f6e5f6af878fb37288ce1c627459e94dbf7d01 # v3.29.5
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@51f77329afa6477de8c49fc9c7046c15b9a4e79d # v3.29.5
55+
uses: github/codeql-action/analyze@f1f6e5f6af878fb37288ce1c627459e94dbf7d01 # v3.29.5
5656
with:
5757
category: "/language:go"

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323

2424
steps:
2525
- name: Checkout code
26-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
26+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
2727
with:
2828
persist-credentials: false
2929

.github/workflows/linters.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
runs-on: ubuntu-latest
2222
steps:
2323
- name: Check out code
24-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
24+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
2525
with:
2626
persist-credentials: false
2727

.github/workflows/release.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ jobs:
2525

2626
steps:
2727
- name: Checkout
28-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
28+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
2929
with:
3030
fetch-depth: 0
3131
persist-credentials: false
3232

3333
- name: Setup Go
34-
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v4.0.1
34+
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v4.0.1
3535
with:
3636
go-version: 1.24
3737
cache: false
3838

3939
- name: Setup Syft
40-
uses: anchore/sbom-action/download-syft@7b36ad622f042cab6f59a75c2ac24ccb256e9b45 # v0.20.4
40+
uses: anchore/sbom-action/download-syft@da167eac915b4e86f08b264dbdbc867b61be6f0c # v0.20.5
4141

4242
- name: Setup Cosign
4343
uses: sigstore/cosign-installer@d58896d6a1865668819e1d91763c7751a165e159 # v3.9.2
@@ -49,22 +49,22 @@ jobs:
4949
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
5050

5151
- name: Login to GitHub Container Registry
52-
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
52+
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0
5353
with:
5454
registry: ghcr.io
5555
username: ${{ github.actor }}
5656
password: ${{ secrets.GITHUB_TOKEN }}
5757

5858
- name: Login to Quay.io
59-
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
59+
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0
6060
with:
6161
registry: quay.io
6262
username: ${{ secrets.QUAY_BOT_USERNAME }}
6363
password: ${{ secrets.QUAY_BOT_TOKEN }}
6464

6565
- name: Run GoReleaser
6666
id: goreleaser
67-
uses: goreleaser/goreleaser-action@9c156ee8a17a598857849441385a2041ef570552 # v6.3.0
67+
uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0
6868
with:
6969
# Note that the following is the version of goreleaser, and NOT a Go version!
7070
# When bumping it, make sure to check out goreleaser's changelog first!

README.rst

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,11 @@ a key. This has the following form::
378378
379379
https://${VAULT_URL}/keys/${KEY_NAME}/${KEY_VERSION}
380380
381+
You can omit the version, and have just a trailing slash, and this will use
382+
whatever the latest version of the key is::
383+
384+
https://${VAULT_URL}/keys/${KEY_NAME}/
385+
381386
To create a Key Vault and assign your service principal permissions on it
382387
from the commandline:
383388
@@ -401,6 +406,10 @@ Now you can encrypt a file using::
401406
402407
$ sops encrypt --azure-kv https://sops.vault.azure.net/keys/sops-key/some-string test.yaml > test.enc.yaml
403408
409+
or, without the version::
410+
411+
$ sops encrypt --azure-kv https://sops.vault.azure.net/keys/sops-key/ test.yaml > test.enc.yaml
412+
404413
And decrypt it using::
405414
406415
$ sops decrypt test.enc.yaml
@@ -846,14 +855,6 @@ Example: place the following in your ``~/.bashrc``
846855
SOPS_GPG_EXEC = 'your_gpg_client_wrapper'
847856
848857
849-
Specify a different GPG key server
850-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
851-
852-
By default, SOPS uses the key server ``keys.openpgp.org`` to retrieve the GPG
853-
keys that are not present in the local keyring.
854-
This is no longer configurable. You can learn more about why from this write-up: `SKS Keyserver Network Under Attack <https://gist.github.com/rjhansen/67ab921ffb4084c865b3618d6955275f>`_.
855-
856-
857858
Key groups
858859
~~~~~~~~~~
859860

audit/audit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414

1515
"github.com/getsops/sops/v3/logging"
1616
"github.com/sirupsen/logrus"
17-
"gopkg.in/yaml.v3"
17+
"go.yaml.in/yaml/v3"
1818
)
1919

2020
var log *logrus.Logger

azkv/keysource.go

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,21 @@ func NewMasterKey(vaultURL string, keyName string, keyVersion string) *MasterKey
7979
// MasterKey. The URL format is {vaultUrl}/keys/{keyName}/{keyVersion}.
8080
func NewMasterKeyFromURL(url string) (*MasterKey, error) {
8181
url = strings.TrimSpace(url)
82-
re := regexp.MustCompile("^(https://[^/]+)/keys/([^/]+)/([^/]+)$")
82+
re := regexp.MustCompile("^(https://[^/]+)/keys/([^/]+)(/[^/]*)?$")
8383
parts := re.FindStringSubmatch(url)
8484
if len(parts) < 3 {
85-
return nil, fmt.Errorf("could not parse %q into a valid Azure Key Vault MasterKey", url)
85+
return nil, fmt.Errorf("could not parse %q into a valid Azure Key Vault MasterKey %v", url, parts)
8686
}
87-
return NewMasterKey(parts[1], parts[2], parts[3]), nil
87+
// Blank key versions are supported in Azure Key Vault, as they default to the latest
88+
// version of the key. We need to put the actual version in the sops metadata block though
89+
var key *MasterKey
90+
if len(parts[3]) > 1 {
91+
key = NewMasterKey(parts[1], parts[2], parts[3][1:])
92+
} else {
93+
key = NewMasterKey(parts[1], parts[2], "")
94+
}
95+
err := key.ensureKeyHasVersion(context.Background())
96+
return key, err
8897
}
8998

9099
// MasterKeysFromURLs takes a comma separated list of Azure Key Vault URLs,
@@ -145,6 +154,36 @@ func (key *MasterKey) Encrypt(dataKey []byte) error {
145154
return key.EncryptContext(context.Background(), dataKey)
146155
}
147156

157+
func (key *MasterKey) ensureKeyHasVersion(ctx context.Context) error {
158+
if (key.Version != "") {
159+
// Nothing to do
160+
return nil
161+
}
162+
163+
token, err := key.getTokenCredential()
164+
165+
if err != nil {
166+
log.WithFields(logrus.Fields{"key": key.Name, "version": key.Version}).Info("Encryption failed")
167+
return fmt.Errorf("failed to get Azure token credential to retrieve key version: %w", err)
168+
}
169+
170+
c, err := azkeys.NewClient(key.VaultURL, token, key.clientOptions)
171+
if err != nil {
172+
log.WithFields(logrus.Fields{"key": key.Name, "version": key.Version}).Info("Encryption failed")
173+
return fmt.Errorf("failed to construct Azure Key Vault client to retrieve key version: %w", err)
174+
}
175+
176+
kdetail, err := c.GetKey(ctx, key.Name, key.Version, nil)
177+
if err != nil {
178+
log.WithFields(logrus.Fields{"key": key.Name, "version": key.Version}).Info("Encryption failed")
179+
return fmt.Errorf("failed to fetch Azure Key to retrieve key version: %w", err)
180+
}
181+
key.Version = kdetail.Key.KID.Version()
182+
183+
log.WithFields(logrus.Fields{"key": key.Name, "version": key.Version}).Info("Version fetch succeeded")
184+
return nil
185+
}
186+
148187
// EncryptContext takes a SOPS data key, encrypts it with Azure Key Vault, and stores
149188
// the result in the EncryptedKey field.
150189
func (key *MasterKey) EncryptContext(ctx context.Context, dataKey []byte) error {

cmd/sops/main.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,14 @@ func main() {
7878

7979
keyserviceFlags := []cli.Flag{
8080
cli.BoolTFlag{
81-
Name: "enable-local-keyservice",
82-
Usage: "use local key service",
81+
Name: "enable-local-keyservice",
82+
Usage: "use local key service",
83+
EnvVar: "SOPS_ENABLE_LOCAL_KEYSERVICE",
8384
},
8485
cli.StringSliceFlag{
85-
Name: "keyservice",
86-
Usage: "Specify the key services to use in addition to the local one. Can be specified more than once. Syntax: protocol://address. Example: tcp://myserver.com:5000",
86+
Name: "keyservice",
87+
Usage: "Specify the key services to use in addition to the local one. Can be specified more than once. Syntax: protocol://address. Example: tcp://myserver.com:5000",
88+
EnvVar: "SOPS_KEYSERVICE",
8789
},
8890
}
8991
app.Name = "sops"

config/config.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"github.com/getsops/sops/v3/kms"
2020
"github.com/getsops/sops/v3/pgp"
2121
"github.com/getsops/sops/v3/publish"
22-
"gopkg.in/yaml.v3"
22+
"go.yaml.in/yaml/v3"
2323
)
2424

2525
type fileSystem interface {
@@ -508,7 +508,18 @@ func parseDestinationRuleForFile(conf *configFile, filePath string, kmsEncryptio
508508
}
509509

510510
var dest publish.Destination
511-
if dRule.S3Bucket != "" && dRule.GCSBucket != "" && dRule.VaultPath != "" {
511+
destinationCount := 0
512+
if dRule.S3Bucket != "" {
513+
destinationCount++
514+
}
515+
if dRule.GCSBucket != "" {
516+
destinationCount++
517+
}
518+
if dRule.VaultPath != "" {
519+
destinationCount++
520+
}
521+
522+
if destinationCount > 1 {
512523
return nil, fmt.Errorf("error loading config: more than one destinations were found in a single destination rule, you can only use one per rule")
513524
}
514525
if dRule.S3Bucket != "" {

0 commit comments

Comments
 (0)