1
0
mirror of https://github.com/getsops/sops.git synced 2026-02-05 12:45:21 +01:00
Commit Graph

23 Commits

Author SHA1 Message Date
Hidde Beydals
02a866f27d age: improve identity loading, add tests, tidy
This adds improvements to identity loading, extensive test coverage
and a general tidying of bits of code. The improvements are based on a
fork of the age key source in the Flux project's kustomize-controller,
which was built due to SOPS' limitations around identity management
without relying on runtime environment variables.

- It introduces a `ParsedIdentity` type which contains a slice of age
  identities, and can be applied to the `MasterKey`. When applied,
  further loading of identities from the runtime environment is skipped
  for `Decrypt` operations. This is most useful when working with SOPS
  as an SDK, in combination with e.g. a local key service server
  implementation.
- The `Identity` field has been deprecated in the `MasterKey` struct.
  Presence of the field was misleading, as it is not actually used.
- Any detected identity reference is now loaded, instead of it assuming
  a priority order. This makes more sense, as age is able to work with
  a set of loaded identities. If no environment variables are defined,
  the existence of the keys.txt in the user's config directory is
  required.
- Decrypt logs have been added to match other key sources.
- Extensive test coverage.

Signed-off-by: Hidde Beydals <hello@hidde.co>
2022-06-03 00:43:05 +02:00
Cedric Kienzler
1dc90ad1ab Add tests for single key
Adding tests to verify we do not break the usage of a single AGE key

Signed-off-by: Cedric Kienzler <github@cedric-kienzler.de>
2022-03-22 21:26:33 +01:00
Cedric Kienzler
b5f5f28c3c Make masterKeyFromRecipient private
In [this](https://github.com/mozilla/sops/pull/966#discussion_r830294838) comment
it was proposed to make `masterKeyFromRecipient` private to avoid
reintroducing this bug in the future.
Since I agree with the Idea, this change will make the mehtod private
and update all unit-tests to use the `MasterKeysFromRecipients` method
instead.

Signed-off-by: Cedric Kienzler <github@cedric-kienzler.de>
2022-03-20 23:04:12 +01:00
Cedric Kienzler
7ebee3dc7b This fixes a bug with age encryption when specifying multiple age recipients
I encountered an issue when I tried so specify multiple age recipients
in the .sops.yaml config file of my repository.

I tried running `sops --age 'agePubKey1,agePubKey2' -e -i values.secret.yaml`
which produced an appropriate file with two entries in the `/sops/age/-`
part of the encrypted yaml file.

However, I then continued to set multiple recipients in my .sops.yaml
file to simplify handling:

```yaml
creation_rules:
  - encrypted_regex: '^(data|stringData|spec)$'
    age: 'agePubKey1,agePubKey2'
```

However, this resulted in encryption only being done for the first
specified agePubKey, not the second or third one.

After digging a bit trough the code, I think this should fix it.

I verified the fix locally on my machine and got it working. Also adding
some unit tests and extending the repository examples so they can be
decrypted using the age keys provided in `age/keys.txt`

Signed-off-by: Cedric Kienzler <github@cedric-kienzler.de>
2022-03-20 22:49:11 +01:00
AJ Bahnken
dff9c31411 Merge branch 'develop' into sops-age-key-env 2022-03-01 10:22:01 -08:00
Christian Hoffmeister
b7c58e4e56 Move age environment variable names to constants 2022-02-25 18:09:37 +01:00
AJ Bahnken
624c7d02b8 Merge pull request #842 from hiddeco/remove-unused-age-code
Remove unused age keysource code
2022-02-24 15:04:22 -08:00
Christian Hoffmeister
086c11d09b Support SOPS_AGE_KEY environment variable 2022-02-14 22:18:05 +01:00
Johan Fleury
fdf4517ce8 Trim space from age keys 2021-04-03 22:17:45 -04:00
Hidde Beydals
e98451e975 Remove unused age code
This removes two pieces of code in the age keysource that are not
actually used.

The `parsedIdentity` is technically a candidate to stay, but should
then be changed to a `[]*age.X25519Identity` type and be lazy-loaded
by `Decrypt` (with the result of `age.ParseIdentities`).

Signed-off-by: Hidde Beydals <hello@hidde.co>
2021-03-30 17:44:33 +02:00
Andreas
5d1376d56d Use age/armor for encrypted data key (#819)
* Use age/armor for encrypted data key

Currently the encrypted data key is stored as a binary value, and this
results in SOPS encrypted DOTENV files having weird binary characters.

This changes the encrypt/decrypt methods to use the armor reader writer
provided by: filippo.io/age/armor

Signed-off-by: Andreas Amstutz <tullo@users.noreply.github.com>

* upgrade filippo.io/age to v1.0.0-beta7

Signed-off-by: Andreas Amstutz <tullo@users.noreply.github.com>

* add unit test

Signed-off-by: Andreas Amstutz <tullo@users.noreply.github.com>

Co-authored-by: Andreas Amstutz <tullo@users.noreply.github.com>
2021-02-21 09:06:40 +01:00
Mikhail Katychev
0f2ebcf7ff added wrap verb to outputs (#817) 2021-02-17 22:21:20 +01:00
Jimmy Cuadra
e9acafced7 Update to age 1.0.0-beta5. 2020-09-21 13:00:36 -07:00
Cole Mickens
8f6271f5c8 age: MasterKeysFromRecipients: gracefully handle empty string 2020-09-21 12:48:16 -07:00
Cole Mickens
50a89c8293 age: .sops.yaml support 2020-09-21 12:48:16 -07:00
Jimmy Cuadra
6a6a9363da Use more concise style for constructing map. 2020-09-21 12:47:15 -07:00
Jimmy Cuadra
7f7ecbc18e Try decrypting with all possible keys in the keyfile. 2020-09-21 12:47:15 -07:00
Jimmy Cuadra
617db437de Use a single keys.txt file for age private keys. 2020-09-21 12:47:15 -07:00
Jimmy Cuadra
5c171c800c Don't swallow potential errors from os.Stat. 2020-09-21 12:47:15 -07:00
Jimmy Cuadra
d9b196c87c Determine age package path using current file rather than pwd. 2020-09-21 12:47:15 -07:00
Jimmy Cuadra
2741ab530a Use user config dir instead of home dir as the root for age keys. 2020-09-21 12:47:15 -07:00
Jimmy Cuadra
9e4cbc93cf Allow age key dir to be set with SOPS_AGE_KEY_DIR and add tests. 2020-09-21 12:47:15 -07:00
Jimmy Cuadra
e8d00046e1 Add support for age. 2020-09-21 12:47:13 -07:00