@@ -803,104 +803,6 @@ By default ``sops`` just dumps all the output to the standard output. We can use
803803``--output`` flag followed by a filename to save the output to the file specified.
804804Beware using both ``--in-place`` and ``--output`` flags will result in an error.
805805
806- Passing Secrets to Other Processes
807- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
808- In addition to writing secrets to standard output and to files on disk, ``sops``
809- has two commands for passing decrypted secrets to a new process: ``exec-env``
810- and ``exec-file``. These commands will place all output into the environment of
811- a child process and into a temporary file, respectively. For example, if a
812- program looks for credentials in its environment, ``exec-env`` can be used to
813- ensure that the decrypted contents are available only to this process and never
814- written to disk.
815-
816- .. code:: bash
817-
818- # print secrets to stdout to confirm values
819- $ sops -d out.json
820- {
821- "database_password": "jf48t9wfw094gf4nhdf023r",
822- "AWS_ACCESS_KEY_ID": "AKIAIOSFODNN7EXAMPLE",
823- "AWS_SECRET_KEY": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
824- }
825-
826- # decrypt out.json and run a command
827- # the command prints the environment variable and runs a script that uses it
828- $ sops exec-env out.json ' echo secret: $database_password ; ./database-import'
829- secret: jf48t9wfw094gf4nhdf023r
830-
831- # launch a shell with the secrets available in its environment
832- $ sops exec-env out.json ' sh'
833- sh-3.2# echo $database_password
834- jf48t9wfw094gf4nhdf023r
835-
836- # the secret is not accessible anywhere else
837- sh-3.2$ exit
838- $ echo your password: $database_password
839- your password:
840-
841-
842- If the command you want to run only operates on files, you can use ``exec-file``
843- instead. By default ``sops`` will use a FIFO to pass the contents of the
844- decrypted file to the new program. Using a FIFO, secrets are only passed in
845- memory which has two benefits: the plaintext secrets never touch the disk, and
846- the child process can only read the secrets once. In contexts where this won' t
847- work, such as platforms where FIFOs are not available or secret files need to be
848- available to the child process longer term, the ` ` --no-fifo` ` flag can be used
849- to instruct ` ` sops` ` to use a traditional temporary file that will get cleaned
850- up once the process is finished executing. ` ` exec-file` ` behaves similar to
851- ` ` find(1)` ` in that ` ` {}` ` is used as a placeholder in the command which will be
852- substituted with the temporary file path (whether a FIFO or an actual file).
853-
854- .. code:: bash
855-
856- # operating on the same file as before, but as a file this time
857- $ sops exec-file out.json ' echo your temporary file: {}; cat {}'
858- your temporary file: /tmp/.sops894650499/tmp-file
859- {
860- " database_password" : " jf48t9wfw094gf4nhdf023r" ,
861- " AWS_ACCESS_KEY_ID" : " AKIAIOSFODNN7EXAMPLE" ,
862- " AWS_SECRET_KEY" : " wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
863- }
864-
865- # launch a shell with a variable TMPFILE pointing to the temporary file
866- $ sops exec-file --no-fifo out.json ' TMPFILE={} sh'
867- sh-3.2$ echo $TMPFILE
868- /tmp/.sops506055069/tmp-file291138648
869- sh-3.2$ cat $TMPFILE
870- {
871- " database_password" : " jf48t9wfw094gf4nhdf023r" ,
872- " AWS_ACCESS_KEY_ID" : " AKIAIOSFODNN7EXAMPLE" ,
873- " AWS_SECRET_KEY" : " wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
874- }
875- sh-3.2$ ./program --config $TMPFILE
876- sh-3.2$ exit
877-
878- # try to open the temporary file from earlier
879- $ cat /tmp/.sops506055069/tmp-file291138648
880- cat: /tmp/.sops506055069/tmp-file291138648: No such file or directory
881-
882- Additionally, both ` ` exec-env` ` and ` ` exec-file` ` support dropping privileges
883- before executing the new program via the ` ` --user < username> ` ` flag. This is
884- particularly useful in cases where the encrypted file is only readable by root,
885- but the target program does not need root privileges to function. This flag
886- should be used where possible for added security.
887-
888- .. code:: bash
889-
890- # the encrypted file can't be read by the current user
891- $ cat out.json
892- cat: out.json: Permission denied
893-
894- # execute sops as root, decrypt secrets, then drop privileges
895- $ sudo sops exec-env --user nobody out.json ' sh'
896- sh-3.2$ echo $database_password
897- jf48t9wfw094gf4nhdf023r
898-
899- # dropped privileges, still can't load the original file
900- sh-3.2$ id
901- uid=4294967294(nobody) gid=4294967294(nobody) groups=4294967294(nobody)
902- sh-3.2$ cat out.json
903- cat: out.json: Permission denied
904806
905807Using the publish command
906808~~~~~~~~~~~~~~~~~~~~~~~~~
0 commit comments