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

83 Commits

Author SHA1 Message Date
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
6ad2a82d22 Refactor duplicated code
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
Bastien Wermeille
303fdd8f37 Add cli indent option for yaml store
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
Mitar
051ce028c9 Support computing MAC only over values which end up encrypted
Signed-off-by: Mitar <mitar.git@tnode.com>
2023-11-07 11:59:08 +01:00
Felix Fontein
38ec3f7a52 Handle unhandled errors.
Signed-off-by: Felix Fontein <felix@fontein.de>
2023-10-03 09:41:49 +02:00
Felix Fontein
a27e1bddf2 Ignore irrelevant return value (it is always nil).
Signed-off-by: Felix Fontein <felix@fontein.de>
2023-10-03 09:41:49 +02: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
eeaf9f76d5 *: address various simple staticcheck warnings
Deprecation of `io/ioutil`, removal of unused functions, possible nil
pointer dereference, and other tiny nits.

There are (many) more, but these would require their own (commit)
context.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-08-17 00:16:40 +02:00
Hidde Beydals
ca0e15eda3 *: solve go vet errors
```
stores/dotenv/store.go:74:12: github.com/getsops/sops/v3.Comment struct literal uses unkeyed fields
stores/dotenv/store_test.go:29:10: github.com/getsops/sops/v3.Comment struct literal uses unkeyed fields
keyservice/server.go:149:9: assignment copies lock value to key: github.com/getsops/sops/v3/keyservice.Key contains google.golang.org/protobuf/internal/impl.MessageState contains sync.Mutex
keyservice/server.go:206:20: call of ks.prompt copies lock value: github.com/getsops/sops/v3/keyservice.Key contains google.golang.org/protobuf/internal/impl.MessageState contains sync.Mutex
keyservice/server.go:214:22: keyToString passes lock by value: github.com/getsops/sops/v3/keyservice.Key contains google.golang.org/protobuf/internal/impl.MessageState contains sync.Mutex
keyservice/server.go:231:29: prompt passes lock by value: github.com/getsops/sops/v3/keyservice.Key contains google.golang.org/protobuf/internal/impl.MessageState contains sync.Mutex
keyservice/server.go:232:27: call of keyToString copies lock value: github.com/getsops/sops/v3/keyservice.Key contains google.golang.org/protobuf/internal/impl.MessageState contains sync.Mutex
keyservice/server.go:251:9: assignment copies lock value to key: github.com/getsops/sops/v3/keyservice.Key contains google.golang.org/protobuf/internal/impl.MessageState contains sync.Mutex
keyservice/server.go:308:20: call of ks.prompt copies lock value: github.com/getsops/sops/v3/keyservice.Key contains google.golang.org/protobuf/internal/impl.MessageState contains sync.Mutex
stores/yaml/store_test.go:27:11: github.com/getsops/sops/v3.Comment struct literal uses unkeyed fields
stores/yaml/store_test.go:39:11: github.com/getsops/sops/v3.Comment struct literal uses unkeyed fields
stores/yaml/store_test.go:107:5: github.com/getsops/sops/v3.Comment struct literal uses unkeyed fields
stores/yaml/store_test.go:139:13: github.com/getsops/sops/v3.Comment struct literal uses unkeyed fields
decrypt/example_test.go:34:1: ExampleDecryptFile refers to unknown identifier: DecryptFile
```

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-08-17 00:14:20 +02:00
Andraz Bajt
700eea7119 Add a test for dotenv output ordering
Signed-off-by: Andraz Bajt <andraz@bajt.me>
2023-08-16 11:21:13 +02:00
Jason Banich
e25c1d9c2d Sort sops parameters in dotenv file 2023-08-16 11:19:55 +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
Felix Fontein
b2d5f08258 Fix comment jumping. 2022-05-31 21:26:49 +02:00
ikedam
108b211cfb Allow empty maps for yaml (#907) 2021-07-24 15:37:49 +09:00
ikedam
75cd389509 Add a test to reproduce #907 2021-07-24 15:29:15 +09:00
Felix Fontein
5af8e63ad5 Prevent comment duplication. (#866) 2021-05-08 19:43:55 +02:00
Felix Fontein
e2d6d0fdc3 Use yaml.v3 instead of modified yaml.v2 for handling YAML files (#791)
* Add another test (that currently fails).

* First shot at using yaml.v3 for reading YAML files with comments.

* Allow parsing multi-document YAML files.

* Use Decoder to parse multi-part documents.

* Use yaml.v3 for config and audit.

* First step of serializing YAML using yaml.v3.

* Always serialize with yaml.v3.

* Remove debug prints.

* Remove traces of github.com/mozilla-services/yaml.

* Improve serialization of documents consisting only of comments.

* Improve handling of some empty documents.

* Adjust to latest changes in go-yaml/yaml#684.

* Bump yaml.v3 version, temporarily disable failing tests.

* Run go mod tidy.

* Fix CI.
2021-02-21 18:48:23 +01:00
Felix Fontein
47cf265067 Forgot to remove no longer used import. 2021-01-06 22:57:34 +01:00
Felix Fontein
88b05654b2 Remove dead code that fails compiling (#774). 2021-01-06 22:57:34 +01:00
Felix Fontein
b1d253e7b9 Do not discard comments at beginning of YAML documents (#757)
* Allow to preserve comments at beginning of YAML document.

* Extend functional tests.

* Update changelog.
2020-10-07 18:10:51 +02:00
Felix Fontein
13d64c94eb Bump YAML library version, and add test for YAML library. (#754) 2020-10-07 11:58:28 +02:00
Jimmy Cuadra
e8d00046e1 Add support for age. 2020-09-21 12:47:13 -07:00
Rene Hernandez
8aca3cb790 Add support for --unencrypted-regex (#715)
* Add support for --unencrypted-regex

* Fix grammar mistake

* Add gofmt'd files
2020-09-02 19:15:50 +02:00
Adrian Utrilla
5d32d9a3ee Revert "Add standard newline/quoting behavior to dotenv store (#622)" (#706)
This reverts commit 4507019a33.
2020-07-27 22:20:37 +02:00
Vaibhav Kaushik
e4abd871c7 Add HashiCorp Vault support (#655)
* feat: initial adding of vualt transit backend to sops
initial work on integration
feat(vault): added cli coomands working for vualt"

fix(vault): fixed config with correct tests

fix(vault): added vault to keygroup and to keyservice server

fixed metadata load

* feat(docs): added docs in README.md and in command help

fix(doc): fix rst formatting"

fix(doc): fix rst formatting

* fix(vault): addressed typos and fixes from autrilla

feat(cli): moved vault to hc-vault naming

* fix(test): typo while rebasing

* fix typos and imporve error messages for vault kms

* rename package from vault to hcvault

* refactor vault keysource url validation

* add negative test cases  for vault keysource

* add hc vault transit config option via objects
additional to URIs

* remove vault_example.yml

* streamline key name to snake case

* rename `BackendPath` to `EnginePath` for hc vault

* correction in hc-vault-transit commands

Signed-off-by: vnzongzna <github@vaibhavk.in>

* resolving conflict

Signed-off-by: vnzongzna <github@vaibhavk.in>

* Apply suggestions from code review

Co-Authored-By: Adrian Utrilla <adrianutrilla@gmail.com>

* allowing only hc_vault_transit_uri as input

Co-Authored-By: gitirabassi
Co-Authored-By: ldue
Signed-off-by: vnzongzna <github@vaibhavk.in>

Co-authored-by: gitirabassi <giacomo@tirabassi.eu>
Co-authored-by: ldue <larsduennwald@gmail.com>
Co-authored-by: Vaibhav Kaushik <vaibhavkaushik@vaibhavka-ltm1.internal.salesforce.com>
Co-authored-by: Adrian Utrilla <adrianutrilla@gmail.com>
2020-05-04 21:27:51 +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
Spencer Judd
4507019a33 Add standard newline/quoting behavior to dotenv store (#622)
Rationale
=========

The dotenv store as it exists right now performs splitting on newlines
to determine where a new key-value pair or comment begins. This works
remarkably well, up until you need to handle values that contain
newlines.

While I couldn't find an offical dotenv file format spec, I sampled a
number of open-source dotenv parsers and it seems that they typically
apply the following rules:

Comments:

* Comments may be written by starting a line with the `#` character.

Newline handling:

* If a value is unquoted or single-quoted and contains the character
  sequence `\n` (`0x5c6e`), it IS NOT decoded to a line feed (`0x0a`).

* If a value is double-quoted and contains the character sequence `\n`
  (`0x5c6e`), it IS decoded to a line feed (`0x0a`).

Whitespace trimming:

* For comments, the whitespace immediately after the `#` character and any
  trailing whitespace is trimmed.

* If a value is unquoted and contains any leading or trailing whitespace, it
  is trimmed.

* If a value is either single- or double-quoted and contains any leading or
  trailing whitespace, it is left untrimmed.

Quotation handling:

* If a value is surrounded by single- or double-quotes, the quotation marks
  are interpreted and not included in the value.

* Any number of single-quote characters may appear in a double-quoted
  value, or within a single-quoted value if they are escaped (i.e.,
  `'foo\'bar'`).

* Any number of double-quote characters may appear in a single-quoted
  value, or within a double-quoted value if they are escaped (i.e.,
  `"foo\"bar"`).

Because single- and double-quoted values may contain actual newlines,
we cannot split our input data on newlines as this may be in the middle
of a quoted value. This, along with the other rules around handling
quoted values, prompted me to try and implement a more robust parsing
solution. This commit is my first stab at that.

Special Considerations
======================

This is _not_ a backwards-compatible change:

* The `dotenv` files produced by this version of SOPS _cannot_ be read
  by an earlier version.

* The `dotenv` files produced by an earlier version of SOPS _can_ be
  read by this version, with the understanding that the semantics around
  quotations and newlines have changed.

Examples
========

The below examples show how double-quoted values are passed to the
running environment:

```console
$ echo 'FOO="foo\\nbar\\nbaz"' > plaintext.env
$ sops -e --output ciphertext.env plaintext.env
$ sops exec-env ciphertext.env 'env | grep FOO | xxd'
00000000: 464f 4f3d 666f 6f5c 6e62 6172 5c6e 6261  FOO=foo\nbar\nba
00000010: 7a0a                                     z.
```

```console
$ echo 'FOO="foo\nbar\nbaz"' > plaintext.env
$ sops -e --output ciphertext.env plaintext.env
$ sops exec-env ciphertext.env 'env | grep -A2 FOO | xxd'
00000000: 464f 4f3d 666f 6f0a 6261 720a 6261 7a0a  FOO=foo.bar.baz.
```
2020-03-20 22:47:14 +01:00
Spencer Judd
16343503c2 Fix newline encoding for dotenv store (#612)
When reading and writing dotenv files, we need to make sure to
encode/decode newline characters. SOPS does not currently do this, as
can be seen from the below:

```console
$ echo '{"foo": "foo\nbar\nbaz"}' > plaintext.json
$ sops -e --output ciphertext.json plaintext.json
$ sops -d --output-type dotenv ciphertext.json
foo=foo
bar
baz
```

This output, is invalid and cannot even be fed back into SOPS:

```console
$ sops -d --output-type dotenv --output plaintext.env ciphertext.json
$ sops -e plaintext.env
Error unmarshalling file: invalid dotenv input line: bar
```

This commit fixes the issue, such that the final `sops -d ...` command
above produces the correct output:

```console
$ sops -d --output-type dotenv ciphertext.json
foo=foo\nbar\nbaz
```
2020-01-24 18:03:34 +01:00
AJ Bahnken
8e21de8dbc Upgrade sops to go 1.13 (#566) 2019-11-18 10:06:58 -08:00
Jason Priebe
45076418c7 added encrypted-regex option 2019-08-14 15:39:21 -04:00
Adrian Utrilla
9998e16c3e Merge pull request #491 from adrianosela/golint
Address Go Lint messages
2019-07-16 11:36:51 +02:00
Adriano
4d4891588d address comments 2019-07-11 10:47:43 -07:00
Adriano
4b99fa18b3 go lint 2019-07-11 10:30:32 -07:00
Adriano
87adc130eb code cleanup [1/5] - go fmt 2019-07-08 09:46:36 -07:00
Adrian Utrilla
2712e3770f Merge branch 'master' into consolidate-example-trees 2019-02-27 22:03:21 +01:00
Adrian Utrilla
d77ae5b1be Add comment support to dotenv store 2019-01-23 11:07:05 +01:00
Adrian Utrilla
bbf17b3d84 Consolidate example trees 2019-01-23 10:54:27 +01:00
mark kelly
eb7b22a4a0 Merge branch 'master' into master 2019-01-14 10:44:55 +00:00
Mark Kelly
7605dd76b1 Added aws_profile
* Decrypt
* Command Line
* Master Key
* Encrypt
* .sops.yaml
2019-01-11 17:11:43 +00:00
Patrick Armstrong
9b364dccef Added ini file example.
Note that this adds both a example file to the top level of the
repository, as well as special case handling of the Example file when
doing a sops -i newfile.ini, since the ini store doesn't support the
tree structure of the existing example.
2019-01-10 21:36:16 -08:00
Patrick Armstrong
d3375f8753 Ran gofmt/goimports on ini store files. 2019-01-10 21:36:16 -08:00
Patrick Armstrong
dc4a697500 Switched ini to same flattening scheme as .env implementation 2019-01-10 21:36:16 -08:00
Patrick Armstrong
c70c52be58 Added support for ini files 2019-01-10 21:36:16 -08:00