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

33 Commits

Author SHA1 Message Date
Felix Fontein
6bb6621897 Make SingleValueStore extend Store instead of the other way around.
Signed-off-by: Felix Fontein <felix@fontein.de>
2025-09-27 20:17:14 +02:00
Felix Fontein
ffc1e265bb Ignore encryption selection options for binary store (and warn when they are used).
Signed-off-by: Felix Fontein <felix@fontein.de>
2025-09-27 20:17:14 +02:00
Felix Fontein
54196f028b Adjust new test.
Signed-off-by: Felix Fontein <felix@fontein.de>
2025-02-15 14:25:29 +01:00
Felix Fontein
d9d35e999f Merge branch 'main' into eof-newline 2025-02-15 14:22:01 +01:00
Felix Fontein
233deecdd0 Merge branch 'main' into fixes 2025-02-15 14:06:42 +01:00
Felix Fontein
50b6afc9c2 Merge branch 'main' into eof-newline 2025-02-15 13:54:00 +01:00
Felix Fontein
2463a6f96f Correctly handle comments during JSON serialization.
Signed-off-by: Felix Fontein <felix@fontein.de>
2024-12-01 09:19:22 +01:00
Martin Holst Swende
adad27e2d4 stores: test for duplicate keys, reseve keyword (yaml only now)
stores/json: use assert
stores/yaml: fix failing test (empty data)
stores/yaml: use assert in tests
unfix error handling and ignore error

Signed-off-by: Martin Holst Swende <martin@swende.se>
2024-09-27 15:58:34 +02:00
Sebastien Duthil
fa545b142d outputs: add trailing \n at the end of json files
Signed-off-by: Sebastien Duthil <duthils@duthils.net>
2024-09-14 09:25:19 -04:00
Felix Fontein
618b60e99c Create a constant for the 'sops' metadata key.
Signed-off-by: Felix Fontein <felix@fontein.de>
2023-12-29 22:55:57 +01:00
Felix Fontein
1bda828b69 Make check whether file contains invalid keys for encryption dependent on output store.
Signed-off-by: Felix Fontein <felix@fontein.de>
2023-12-29 22:22:01 +01:00
Bastien
42018ef4a5 Add indentation settings for json_binary
Signed-off-by: Bastien <bastien.wermeille@gmail.com>
2023-11-24 07:41:14 +01:00
Bastien
8a63bb0d21 Add checks for indentation value
Signed-off-by: Bastien <bastien.wermeille@gmail.com>
2023-11-24 07:41:14 +01:00
Bastien Wermeille
755c16d49c Allow no indent at all for json store
Signed-off-by: Bastien Wermeille <bastien.wermeille@gmail.com>
2023-11-24 07:41:14 +01:00
Bastien Wermeille
c6dc5267e5 Indentation of json files
Signed-off-by: Bastien Wermeille <bastien.wermeille@gmail.com>
2023-11-24 07:41:14 +01:00
Bastien Wermeille
d2ee8df5de Implement feedback
Co-authored-by: Felix Fontein <felix@fontein.de>
Signed-off-by: Bastien Wermeille <bastien.wermeille@gmail.com>
2023-11-24 07:41:14 +01:00
James J. Goodhouse
e9e2346fdd Add configuration for stores
this will allow for setting of parameters specific to each store, such
as indentation level for YAML

Co-authored-by: Bastien Wermeille <bastien.wermeille@gmail.com>
Signed-off-by: James J. Goodhouse <jgoodhouse@newrelic.com>
2023-11-24 07:41:14 +01:00
Felix Fontein
72f11997d4 Handle return values of dec.Token() to improve error messages.
Signed-off-by: Felix Fontein <felix@fontein.de>
2023-09-28 22:16:45 +02:00
Felix Fontein
f258e6c1d1 Improve handling of errors when binary store handles bad data
Makes sure that the 'data' key refers to strings. Also
improves error messages, and on CLI hints at the --output-type
option.

Signed-off-by: Felix Fontein <felix@fontein.de>
2023-09-21 08:25:50 +02:00
Felix Fontein
8012cd6e9f Delete sops encrypted file we don't have keys for.
Signed-off-by: Felix Fontein <felix@fontein.de>
2023-09-20 21:09:29 +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
Noel Cower
84816c31be Add support for decoding JSON arrays of arrays (#642)
Add support for decoding JSON arrays of arrays by handling, during
slice decoding, when the next token is an array opening. This produces
nested []interface{} slices.

Closes #640.
2020-03-20 22:53:37 +01:00
AJ Bahnken
8e21de8dbc Upgrade sops to go 1.13 (#566) 2019-11-18 10:06:58 -08:00
Adriano
4b99fa18b3 go lint 2019-07-11 10:30:32 -07:00
Adrian Utrilla
bbf17b3d84 Consolidate example trees 2019-01-23 10:54:27 +01:00
James Robson
dfa150bf75 Add multidoc encrypt/decrypt for YAML sources 2018-11-21 09:00:49 -07:00
AJ Bahnken
3265a66cd3 Handle escaping in original json (#357)
* Handle escaping in original json

* Replace conditional magic with proper json encoding call for key

* swap TestDecodeJSONWithEscaping with new TestEncodeJSONWithEscaping

* fix copy/paste typo
2018-06-01 12:47:27 -07:00
Adrian Utrilla
1ffc93dfb6 Refactor Store interface to reflect operations SOPS performs (#335)
* Refactor Store interface to reflect operations SOPS performs

Previously the Store interface tried to mimic the Marshaler and Unmarshaler
interfaces. This was a mistake, as it meant Stores had no idea whether the files they
were loading were encrypted or not.

Partially fixes #334

* Add regression test for loading plain JSON file with binary store
2018-04-20 10:13:46 +02:00
Mohit Agarwal
591d5c4154 Don't consider io.EOF returned by Decoder.Token as error
[`Decoder.Token`](https://golang.org/pkg/encoding/json/#Decoder.Token)
returns nil, io.EOF at the input stream.

This caused the output json to have no "data" key for an input
containing a number:

```
{
        "sops": {
                "kms": null,
                "gcp_kms": null,
                "lastmodified": "2018-01-14T14:51:51Z",
                "mac": "ENC[AES256_GCM,data:miI91EH0VGqTY9DuJweV61++dq1LmdBwbU/tkaznCeVo2H7z0vws0FdDJiKUiyCwd+PYkpklinVyGWzxDjgR1yWch+9uU4zFkwSiNwLTdQRitYE9Kwxd37E7+AFmJtZIfIdUZsx/gFP4YZ4Pn2cgVK6n9sNRyaGhR4PyCp7TXT4=,iv:XnyghTNLba1edrVYk8sum38pe736T3L5yGJMmBocDyE=,tag:b3z730u8+hPiNxmg8REFHg==,type:str]",
                "pgp": [
                        {
                                "created_at": "2018-01-14T14:51:51Z",
                                "enc": "-----BEGIN PGP MESSAGE-----\n\nwcFMA90gOM45xlRNARAAj8AtDWZakRBpMmqRH3z6F+hIkyt2xpP911MAHpU1e4ma\nNZfUcKJybg2XFbAj40uDSEE1o1+hebU18nzYVwVUiDKBGN5f3rSgAIgtcK8u9JT2\nhRPndP7wkFK1t1+n3ne40ZotdqYefCLjHUalmS8Ka5wYDXGD9fOR3zBoaJ1VFWYu\nZyOltpqK76AFZ8dJkBBXcZCKfmZ2h2C9/tfSq5Hjibzddd/zit09zXsyHE6McFJU\n3YPGmGQ/kE+/1vkELIF3suGy7yB3Um0cRCEVnHoZJkE+lRZtxKKJ91oKLOfwJkoT\nOAHmeRJxDE45eae/wbWS4KHUFJ2IvfnUuaNCVrnYyzRP05wFxAuZI7XcV3ckVfaM\nBW2GkAUESfY9zYkTm/lOpUhAjEpqzjG+lSCt9VdHMMqOl8N4z6U5qzznm1ZL4Wf9\nbEV0zRc5XECmM6yjx7KHA8ivjdgxpKY9HgBI5ZkfjgoORfOaZaiVdteRmEOQM3yS\nWN+QTt4dkcfsqdpmYyHbCatgV9rsZdcIHS1kZ4EK7HMKzwR9+caRFA+o3NOm0hyx\nbNnMldVFr771KFoneau13A5HdZGdZRO7qMfpVZjdDQ8dFR1xtAimeoSGqIv5rcT3\n8UzrnNuSkHlPZHNgBloV5DoFLtWzd9VZCOl1KyLQLsSqQgbi1mbZlAQWfdWbwqHS\n4AHk3ef1I8MjQxVJFD4jSgC80OHzIeBK4C/heu/gfuKjuYWI4MLlPiuN6e+yoFT+\nR75GX1GgqTWP52gwxstEibTQ7n9zl6/gUeQ1/T+QOFDfajpawb8+xxyx4kjOzPnh\nU4MA\n=VSfw\n-----END PGP MESSAGE-----",
                                "fp": "C8F69F5F7059C32B3328DFE48BE9D15D0B0D06EB"
                        }
                ],
                "unencrypted_suffix": "_unencrypted",
                "version": "3.0.0"
        }
}
```

After the change:

```
{
        "data": "ENC[AES256_GCM,data:PVw=,iv:cCDbWu1jdYkCIUcF/BtZGBs6mSWtdTI5ZF/A/i7RxIY=,tag:sFtal0nSo2koPDxnaKxLgA==,type:str]",
        "sops": {
                "kms": null,
                "gcp_kms": null,
                "lastmodified": "2018-01-14T14:52:38Z",
                "mac": "ENC[AES256_GCM,data:BOyvRlaMKIGRcNOnmBGnN/Qz7i/l6Lhl5lx1OJ1VMb6nhuKkhCySktGVYOElUTgLc3CDKLfELNKiID2i6HKAkSAWQyYC1tIPAQTcBtnVd2Pt7Adzz8i8JFzWT+sc5rKLCOljnXwcXsxbmhrWwfQFj57wVWkvZTRNLfNZkcMnykw=,iv:JxCILR1qxAk391tTmLf/hXlr1L/JQWqhLbFHYR04HjI=,tag:0LSWWPWEBeK1Gm2mi4UBNA==,type:str]",
                "pgp": [
                        {
                                "created_at": "2018-01-14T14:52:38Z",
                                "enc": "-----BEGIN PGP MESSAGE-----\n\nwcFMA90gOM45xlRNARAAR+FmJBwY4gnpUUZSwWRrwJ+PLhBzVXoIfZ2zqhk+gkvl\nGZyi62mCM5ZVoVPf8Pw+a9cQi+IzJHgKEOT/6PIp1chw7DhnoGbFJExcE3inniou\nlLo2pFTRH5jTvCE3yIIR/l1b9VMrtnOcZuYx9SobLjIv4wKtY1gMkbmrG2IDLmMT\n9QYM/MT/aCcUA/u6bYz8+ZjAS7NUEifji/SkZkYlL1tdCEdiHU/Cl4gScOhqcIsK\nGWGa+1jnxnYOmYq3FDMb90RSPgU8xkzl9EQIInF2t4K3Zj7E+9J93Y7N2udpNGah\nebPwxS4VTCLl1p69q9+nhO8rn9ySjeTjIoJwPoNDzWVowQEmUPZCTz+A28RKi02l\nGsuYxCzD5aF8cRhZbLk882fCAo77U9TiYYa00cq8kTqnCpZmtp3BevrdWTswJwin\n/TID0DOflahzj7iUP8MAVI2nzGosmCWEFiVONWq2l2z7ND78Y65G/d5hM3zv71U/\n1z0B8zzxZSbFFTV2YjADwWdizpeXJFJuVdynCQdPxt8qfNZVXcQfIHmYwh4M3k3U\nv5yV491mwCPNAJAoBaNJoKLnXx3ae4Aic4s2sF3V+AKK6rNiWtuAWsyjuwzmTse2\ntQisNTez5m+6r5seC7YvC2i9Vb2DNzqYn4M/13tHjxpPrNxdCGNneM1FKG8a03nS\n4AHk5BBSjhL9oc/o7zf8AsoFdeE2A+BR4KnhNXbg2eJlJCnO4IvlzVv3wYVwmh5W\nfyHqIQAX3ICb43o6Vo2/AGANvM5BdA3gX+ToyYFHsSMttWLz4zAUJWe04pRx0/rh\n73EA\n=0ON2\n-----END PGP MESSAGE-----",
                                "fp": "C8F69F5F7059C32B3328DFE48BE9D15D0B0D06EB"
                        }
                ],
                "unencrypted_suffix": "_unencrypted",
                "version": "3.0.0"
        }
}
```

Fixes #235
2018-01-14 20:41:37 +05:30
Adrian Utrilla
14a55401d3 Fix metadata not found returning the wrong error 2017-10-03 14:51:59 -07:00
Adrian Utrilla
aeaa726b5f Show error message when decrypting SOPS1 JSON files 2017-09-18 09:18:36 -07:00
Adrian Utrilla
a9582158d2 Revert UnmarshalMetadata returning pointer 2017-08-29 12:16:00 -07:00
Adrian Utrilla
13b70024d0 Refactor metadata marshalling
**IMPORTANT** This breaks compatibility of the file format in 1.x for
json files, due to the version being encoded as a number in json files.
The fix for this is easy, however. One can either use a previous version
of sops in the range [2.0.0, 2.0.9] to edit the file, or one can manually edit
the encrypted file and change the version from a number to a string

Previously we basically hand-converted the metadata struct into a map
which we then passed to the stores. Now, we convert the metadata struct
to a "serialization" struct, which the stores serialize
2017-08-23 17:10:39 -07:00