Граф коммитов

15 Коммитов

Автор SHA1 Сообщение Дата
Vasily Marnopolsky cdfc7d6a20 fix(azkv): handle whitespace in Azure Key Vault URLs
### Problem:

The Azure Key Vault key parser would fail when URLs contained leading or trailing whitespace, which commonly occurs when using YAML Block Scalar syntax.

```yaml
creation_rules:
  - azure_keyvault: >-
      https://test.vault.azure.net/keys/test-key/a2a690a4fcc04166b739da342a912c90,
      https://test2.vault.azure.net/keys/another-test-key/cf0021e8b743453bae758e7fbf71b60e
```

This resulted in the error:

```bash
"could not parse " https://test2.vault.azure.net/keys/another-test-key/cf0021e8b743453bae758e7fbf71b60e" into a valid Azure Key Vault MasterKey"
```

### Fix:

- Added `strings.TrimSpace()` to clean the URL before parsing in `NewMasterKeyFromURL()`
- Added test case to verify handling of URLs with leading/trailing spaces

Signed-off-by: Vasily Marnopolsky <sept0r.com@gmail.com>
2024-10-22 18:40:53 +02:00
Boris Kreitchman c822b55290 Sort masterkeys according to decryption-order
Co-authored-by: Gabriel Martinez <19713226+GMartinez-Sisti@users.noreply.github.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: Bastien Wermeille <bastien.wermeille@gmail.com>
Co-authored-by: Hidde Beydals <hiddeco@users.noreply.github.com>
Signed-off-by: Boris Kreitchman <bkreitch@gmail.com>
2023-12-18 08:38:43 +01:00
Hidde Beydals 6ec0312ffe
keyservices: address logging regression
Replace the logging of failed encryption and decryption attempts from
error to info level.

This to address a regression in which an encryption or decryption
attempt with a series of keys would result in a list of failed attempts
logged to stderr even when the operation itself eventually succeeded.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-09-13 07:44:08 +02:00
Hidde Beydals 0953fe0d7e
azkv: update dependencies
- github.com/Azure/azure-sdk-for-go/sdk/azcore to v1.7.0
- github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azkeys to v1.0.0

This includes dealing with some breaking changes, which should be the
last ones for the foreseeable future as they tagged it as the first
MAJOR.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-08-12 12:16:32 +02:00
Hidde Beydals f2a1d4c782
Rename Go module to `github.com/getsops/sops/v3`
This commit renames the Go module from `go.mozilla.org/sops/v3` to
`github.com/getsops/sops/v3` without a major version bump, to align
with new stewardship.

For more information around this change, refer to
https://github.com/getsops/sops/issues/1246.

For a one-liner to change the `go.mod` and any import paths in your
Go project making use of this module, run:

```
find /path/to/repo -type f \( -name "*.go" -o -name "go.mod" \) -exec sed -i 's|go.mozilla.org/sops/v3|github.com/getsops/sops/v3|g' {} \;
find /path/to/repo -type f \( -name "*.go" -o -name "go.mod" \) -exec sed -i '' 's|go.mozilla.org/sops/v3|github.com/getsops/sops/v3|g' {} \;
```

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-07-31 22:51:36 +02:00
Hidde Beydals 4f858e5ed2 azkv: update Azure SDK to v0.9.0
Besides some signature changes, really nothing special.

```
$ go test --tags integration ./... -v
=== RUN   TestMasterKey_Encrypt
--- PASS: TestMasterKey_Encrypt (1.34s)
=== RUN   TestMasterKey_Decrypt
--- PASS: TestMasterKey_Decrypt (0.68s)
=== RUN   TestMasterKey_EncryptDecrypt_RoundTrip
--- PASS: TestMasterKey_EncryptDecrypt_RoundTrip (0.40s)
=== RUN   TestNewMasterKeyFromURL
=== RUN   TestNewMasterKeyFromURL/URL
=== RUN   TestNewMasterKeyFromURL/malformed_URL
--- PASS: TestNewMasterKeyFromURL (0.00s)
    --- PASS: TestNewMasterKeyFromURL/URL (0.00s)
    --- PASS: TestNewMasterKeyFromURL/malformed_URL (0.00s)
=== RUN   TestMasterKeysFromURLs
=== RUN   TestMasterKeysFromURLs/single_URL
=== RUN   TestMasterKeysFromURLs/multiple_URLs
=== RUN   TestMasterKeysFromURLs/multiple_URLs,_one_malformed
=== RUN   TestMasterKeysFromURLs/empty
--- PASS: TestMasterKeysFromURLs (0.00s)
    --- PASS: TestMasterKeysFromURLs/single_URL (0.00s)
    --- PASS: TestMasterKeysFromURLs/multiple_URLs (0.00s)
    --- PASS: TestMasterKeysFromURLs/multiple_URLs,_one_malformed (0.00s)
    --- PASS: TestMasterKeysFromURLs/empty (0.00s)
=== RUN   TestTokenCredential_ApplyToMasterKey
--- PASS: TestTokenCredential_ApplyToMasterKey (0.00s)
=== RUN   TestMasterKey_EncryptedDataKey
--- PASS: TestMasterKey_EncryptedDataKey (0.00s)
=== RUN   TestMasterKey_SetEncryptedDataKey
--- PASS: TestMasterKey_SetEncryptedDataKey (0.00s)
=== RUN   TestMasterKey_EncryptIfNeeded
=== RUN   TestMasterKey_EncryptIfNeeded/not_encrypted
[AZKV]   time="2022-11-21T20:41:58Z" level=error msg="Encryption failed" key=test-key version=a2a690a4fcc04166b739da342a912c90
=== RUN   TestMasterKey_EncryptIfNeeded/already_encrypted
--- PASS: TestMasterKey_EncryptIfNeeded (2.12s)
    --- PASS: TestMasterKey_EncryptIfNeeded/not_encrypted (2.12s)
    --- PASS: TestMasterKey_EncryptIfNeeded/already_encrypted (0.00s)
=== RUN   TestMasterKey_NeedsRotation
--- PASS: TestMasterKey_NeedsRotation (0.00s)
=== RUN   TestMasterKey_ToString
--- PASS: TestMasterKey_ToString (0.00s)
=== RUN   TestMasterKey_ToMap
--- PASS: TestMasterKey_ToMap (0.00s)
=== RUN   TestMasterKey_getTokenCredential
=== RUN   TestMasterKey_getTokenCredential/with_TokenCredential
=== RUN   TestMasterKey_getTokenCredential/default
--- PASS: TestMasterKey_getTokenCredential (0.00s)
    --- PASS: TestMasterKey_getTokenCredential/with_TokenCredential (0.00s)
    --- PASS: TestMasterKey_getTokenCredential/default (0.00s)
PASS
ok      go.mozilla.org/sops/v3/azkv     4.551s
```

Signed-off-by: Hidde Beydals <hello@hidde.co>
2023-07-03 21:34:58 +02:00
Hidde Beydals ce5177651b azkv: update Azure SDK to v0.6.0
This should be the last major change in their SDK with regard to
changing method signatures and/or the way the client is constructed.

I manually ran the integration test suite which passes without any
issues.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2023-07-03 21:34:58 +02:00
Hidde Beydals b80c0d1eba azkv: update SDK to latest, add tests, tidy
This updates the Azure SDK to latest[1], while dropping the custom
authentication flow in favor of the SDK default[2]. It includes
integration tests, which require the `integration` Go build tag and
a set of environmental variables to be configured to be run:

```
PASS
coverage: 81.2% of statements
ok  	go.mozilla.org/sops/v3/azkv	5.376s	coverage: 81.2% of statements
```

The improvements are based on a fork of the key source in the Flux
project's kustomize-controller, built due to SOPS' limitation around
credential managment without relying on runtime environment variables.

- Azure SDK has been updated to latest, including integration test
  coverage.
- Custom authentication flow has been dropped in favor of the SDK
  default[2]. This should work well on almost any system and is
  generally the go-to way of setting this up, including on cloud
  environments, etc.
- It introduces a `TokenCredential` type which holds an
  `azcore.TokenCredential`, and can be applied to a `MasterKey`.
  When applied, the token is used instead of the SDK default. This is
  most useful when working with SOPS as an SDK, in combination with
  e.g. a local key service server implementation.
- Extensive test coverage.

The forked version of this has compatibility tests to ensure it works
with current SOPS:

- 327a3560b3/internal/sops/azkv/keysource_integration_test.go (L89)
- 327a3560b3/internal/sops/azkv/keysource_integration_test.go (L117)

[1]: https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/keyvault/azkeys
[2]: https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity#DefaultAzureCredential

Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-06-02 22:26:07 +02:00
Mikhail Katychev 0f2ebcf7ff
added wrap verb to outputs (#817) 2021-02-17 22:21:20 +01:00
AJ Bahnken 8e21de8dbc
Upgrade sops to go 1.13 (#566) 2019-11-18 10:06:58 -08:00
Aaron Wislang 862a9dc372 Add MSI_ENDPOINT variable. Handle "devicecode" case. 2019-07-17 12:43:42 +02:00
Aaron Wislang c181d95ed8 Adds new Azure authentication methods via newAuthorizer() 2019-07-17 12:43:42 +02:00
Adriano 4b99fa18b3
go lint 2019-07-11 10:30:32 -07:00
Calle Pettersson 19e964ebdd Make Azure key parsing failable 2018-06-18 16:03:24 +02:00
Calle Pettersson 9fa4f0e90e Add support for Azure Key Vault 2018-06-17 22:50:30 +02:00