Skip to content

Commit c3abac2

Browse files
committed
Add and use rotate, edit, and set subcommands.
Signed-off-by: Felix Fontein <[email protected]>
1 parent 2ae16f5 commit c3abac2

File tree

3 files changed

+449
-44
lines changed

3 files changed

+449
-44
lines changed

README.rst

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ separated, in the **SOPS_PGP_FP** env variable.
9696
9797
Note: you can use both PGP and KMS simultaneously.
9898

99-
Then simply call ``sops`` with a file path as argument. It will handle the
99+
Then simply call ``sops edit`` with a file path as argument. It will handle the
100100
encryption/decryption transparently and open the cleartext file in an editor
101101

102102
.. code:: sh
103103
104-
$ sops mynewtestfile.yaml
104+
$ sops edit mynewtestfile.yaml
105105
mynewtestfile.yaml doesn't exist, creating it.
106106
please wait while an encryption key is being generated and stored in a secure fashion
107107
file written to mynewtestfile.yaml
@@ -164,7 +164,7 @@ Given that, the only command a SOPS user needs is:
164164

165165
.. code:: sh
166166
167-
$ sops <file>
167+
$ sops edit <file>
168168
169169
`<file>` will be opened, decrypted, passed to a text editor (vim by default),
170170
encrypted if modified, and saved back to its original location. All of these
@@ -184,7 +184,7 @@ the example files and pgp key provided with the repository::
184184
$ git clone https://github.com/getsops/sops.git
185185
$ cd sops
186186
$ gpg --import pgp/sops_functional_tests_key.asc
187-
$ sops example.yaml
187+
$ sops edit example.yaml
188188

189189
This last step will decrypt ``example.yaml`` using the test private key.
190190

@@ -480,35 +480,33 @@ separated list.
480480
SOPS will prompt you with the changes to be made. This interactivity can be
481481
disabled by supplying the ``-y`` flag.
482482
483-
Command Line
484-
************
483+
``rotate`` command
484+
******************
485485
486-
Command line flag ``--add-kms``, ``--add-pgp``, ``--add-gcp-kms``, ``--add-azure-kv``,
487-
``--rm-kms``, ``--rm-pgp``, ``--rm-gcp-kms`` and ``--rm-azure-kv`` can be used to add
488-
and remove keys from a file.
489-
These flags use the comma separated syntax as the ``--kms``, ``--pgp``, ``--gcp-kms``
490-
and ``--azure-kv`` arguments when creating new files.
486+
The ``rotate`` command generates a new data encryption key and reencrypt all values
487+
with the new key. At te same time, the command line flag ``--add-kms``, ``--add-pgp``,
488+
``--add-gcp-kms``, ``--add-azure-kv``, ``--rm-kms``, ``--rm-pgp``, ``--rm-gcp-kms``
489+
and ``--rm-azure-kv`` can be used to add and remove keys from a file. These flags use
490+
the comma separated syntax as the ``--kms``, ``--pgp``, ``--gcp-kms`` and ``--azure-kv``
491+
arguments when creating new files.
491492
492-
Note that ``-r`` or ``--rotate`` is mandatory in this mode. Not specifying
493-
rotate will ignore the ``--add-*`` options. Use ``updatekeys`` if you want to
494-
add a key without rotating the data key.
493+
Use ``updatekeys`` if you want to add a key without rotating the data key.
495494
496495
.. code:: sh
497496
498497
# add a new pgp key to the file and rotate the data key
499-
$ sops -r -i --add-pgp 85D77543B3D624B63CEA9E6DBC17301B491B3F21 example.yaml
498+
$ sops rotate -i --add-pgp 85D77543B3D624B63CEA9E6DBC17301B491B3F21 example.yaml
500499
501500
# remove a pgp key from the file and rotate the data key
502-
$ sops -r -i --rm-pgp 85D77543B3D624B63CEA9E6DBC17301B491B3F21 example.yaml
501+
$ sops rotate -i --rm-pgp 85D77543B3D624B63CEA9E6DBC17301B491B3F21 example.yaml
503502
504503
505504
Direct Editing
506505
**************
507506
508-
Alternatively, invoking ``sops`` with the flag **-s** will display the master keys
507+
Alternatively, invoking ``sops edit`` with the flag **-s** will display the master keys
509508
while editing. This method can be used to add or remove ``kms`` or ``pgp`` keys under the
510-
``sops`` section. Invoking ``sops`` with the **-i** flag will perform an in-place edit
511-
instead of redirecting output to ``stdout``.
509+
``sops`` section.
512510
513511
For example, to add a KMS master key to a file, add the following entry while
514512
editing:
@@ -620,7 +618,7 @@ When creating a new file, you can specify the encryption context in the
620618
621619
.. code:: sh
622620
623-
$ sops --encryption-context Environment:production,Role:web-server test.dev.yaml
621+
$ sops edit --encryption-context Environment:production,Role:web-server test.dev.yaml
624622
625623
The format of the Encrypt Context string is ``<EncryptionContext Key>:<EncryptionContext Value>,<EncryptionContext Key>:<EncryptionContext Value>,...``
626624
@@ -651,13 +649,16 @@ Key Rotation
651649
~~~~~~~~~~~~
652650
653651
It is recommended to renew the data key on a regular basis. ``sops`` supports key
654-
rotation via the ``-r`` flag. Invoking it on an existing file causes ``sops`` to
655-
reencrypt the file with a new data key, which is then encrypted with the various
652+
rotation via the ``rotate`` command. Invoking it on an existing file causes ``sops``
653+
to reencrypt the file with a new data key, which is then encrypted with the various
656654
KMS and PGP master keys defined in the file.
657655
656+
Add the ``-i`` option to write the rotated file back, instead of printing it to
657+
stdout.
658+
658659
.. code:: sh
659660
660-
$ sops -r example.yaml
661+
$ sops rotate example.yaml
661662
662663
Using .sops.yaml conf to select KMS, PGP and age for new files
663664
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -741,7 +742,7 @@ Creating a new file with the right keys is now as simple as
741742
742743
.. code:: sh
743744
744-
$ sops <newfile>.prod.yaml
745+
$ sops edit <newfile>.prod.yaml
745746
746747
Note that the configuration file is ignored when KMS or PGP parameters are
747748
passed on the SOPS command line or in environment variables.
@@ -847,7 +848,7 @@ For example:
847848
848849
.. code:: sh
849850
850-
$ sops --shamir-secret-sharing-threshold 2 example.json
851+
$ sops edit --shamir-secret-sharing-threshold 2 example.json
851852
852853
Alternatively, you can configure the Shamir threshold for each creation rule in the ``.sops.yaml`` config
853854
with ``shamir_threshold``:
@@ -880,7 +881,7 @@ with ``shamir_threshold``:
880881
- pgp:
881882
- fingerprint5
882883
883-
And then run ``sops example.json``.
884+
And then run ``sops edit example.json``.
884885
885886
The threshold (``shamir_threshold``) is set to 2, so this configuration will require
886887
master keys from two of the three different key groups in order to decrypt the file.
@@ -1348,7 +1349,7 @@ The command below creates a new file with a data key encrypted by KMS and PGP.
13481349
13491350
.. code:: sh
13501351
1351-
$ sops --kms "arn:aws:kms:us-west-2:927034868273:key/fe86dd69-4132-404c-ab86-4269956b4500" --pgp C9CAB0AF1165060DB58D6D6B2653B624D620786D /path/to/new/file.yaml
1352+
$ sops edit --kms "arn:aws:kms:us-west-2:927034868273:key/fe86dd69-4132-404c-ab86-4269956b4500" --pgp C9CAB0AF1165060DB58D6D6B2653B624D620786D /path/to/new/file.yaml
13521353
13531354
Encrypting an existing file
13541355
~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -1448,26 +1449,26 @@ Set a sub-part in a document tree
14481449
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
14491450
14501451
SOPS can set a specific part of a YAML or JSON document, by providing
1451-
the path and value in the ``--set`` command line flag. This is useful to
1452-
set specific values, like keys, without needing an editor.
1452+
the path and value in the ``set`` command. This is useful to set specific
1453+
values, like keys, without needing an editor.
14531454
14541455
.. code:: sh
14551456
1456-
$ sops --set '["app2"]["key"] "app2keystringvalue"' ~/git/svc/sops/example.yaml
1457+
$ sops set ~/git/svc/sops/example.yaml '["app2"]["key"]' '"app2keystringvalue"'
14571458
14581459
The tree path syntax uses regular python dictionary syntax, without the
14591460
variable name. Set to keys by naming them, and array elements by
14601461
numbering them.
14611462
14621463
.. code:: sh
14631464
1464-
$ sops --set '["an_array"][1] "secretuser2"' ~/git/svc/sops/example.yaml
1465+
$ sops set ~/git/svc/sops/example.yaml '["an_array"][1]' '"secretuser2"'
14651466
14661467
The value must be formatted as json.
14671468
14681469
.. code:: sh
14691470
1470-
$ sops --set '["an_array"][1] {"uid1":null,"uid2":1000,"uid3":["bob"]}' ~/git/svc/sops/example.yaml
1471+
$ sops set ~/git/svc/sops/example.yaml '["an_array"][1]' '{"uid1":null,"uid2":1000,"uid3":["bob"]}'
14711472
14721473
Showing diffs in cleartext in git
14731474
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -1742,7 +1743,7 @@ when creating a new file:
17421743
17431744
.. code:: sh
17441745
1745-
$ sops --pgp "E60892BB9BD89A69F759A1A0A3D652173B763E8F,84050F1D61AF7C230A12217687DF65059EF093D3,85D77543B3D624B63CEA9E6DBC17301B491B3F21" mynewfile.yaml
1746+
$ sops edit --pgp "E60892BB9BD89A69F759A1A0A3D652173B763E8F,84050F1D61AF7C230A12217687DF65059EF093D3,85D77543B3D624B63CEA9E6DBC17301B491B3F21" mynewfile.yaml
17461747
17471748
Threat Model
17481749
------------

0 commit comments

Comments
 (0)