Skip to content

Commit 14a22d7

Browse files
authored
Merge pull request #526 from mozilla/revert-exec-command
Revert exec command for 3.4.0 release
2 parents 14b3816 + 5e02dac commit 14a22d7

File tree

4 files changed

+0
-358
lines changed

4 files changed

+0
-358
lines changed

CHANGELOG.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ Features:
77

88
* `sops publish`, a new command for publishing sops encrypted secrets to S3, GCS, or Hashicorp Vault
99
* Support for multiple Azure authentication mechanisms
10-
* `sops exec-env` and `sops exec-file`, two new commands for utilizing sops secrets within a temporary file or env vars
1110
* Azure Keyvault support to the sops config file
1211
* `encrypted_regex` option to the sops config file
1312

README.rst

Lines changed: 0 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
804804
Beware 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
905807
Using the publish command
906808
~~~~~~~~~~~~~~~~~~~~~~~~~

cmd/sops/main.go

Lines changed: 0 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"go.mozilla.org/sops/azkv"
2020
"go.mozilla.org/sops/cmd/sops/codes"
2121
"go.mozilla.org/sops/cmd/sops/common"
22-
"go.mozilla.org/sops/cmd/sops/subcommand/exec"
2322
"go.mozilla.org/sops/cmd/sops/subcommand/groups"
2423
keyservicecmd "go.mozilla.org/sops/cmd/sops/subcommand/keyservice"
2524
publishcmd "go.mozilla.org/sops/cmd/sops/subcommand/publish"
@@ -107,111 +106,6 @@ func main() {
107106
For more information, see the README at github.com/mozilla/sops`
108107
app.EnableBashCompletion = true
109108
app.Commands = []cli.Command{
110-
{
111-
Name: "exec-env",
112-
Usage: "execute a command with decrypted values inserted into the environment",
113-
ArgsUsage: "[file to decrypt] [command to run]",
114-
Flags: append([]cli.Flag{
115-
cli.BoolFlag{
116-
Name: "background",
117-
Usage: "background the process and don't wait for it to complete",
118-
},
119-
cli.StringFlag{
120-
Name: "user",
121-
Usage: "the user to run the command as",
122-
},
123-
}, keyserviceFlags...),
124-
Action: func(c *cli.Context) error {
125-
if len(c.Args()) != 2 {
126-
return common.NewExitError(fmt.Errorf("error: missing file to decrypt"), codes.ErrorGeneric)
127-
}
128-
129-
fileName := c.Args()[0]
130-
command := c.Args()[1]
131-
132-
inputStore := inputStore(c, fileName)
133-
134-
135-
svcs := keyservices(c)
136-
opts := decryptOpts{
137-
OutputStore: &dotenv.Store{},
138-
InputStore: inputStore,
139-
InputPath: fileName,
140-
Cipher: aes.NewCipher(),
141-
KeyServices: svcs,
142-
IgnoreMAC: c.Bool("ignore-mac"),
143-
}
144-
145-
output, err := decrypt(opts)
146-
if err != nil {
147-
return toExitError(err)
148-
}
149-
150-
exec.ExecWithEnv(exec.ExecOpts{
151-
Command: command,
152-
Plaintext: output,
153-
Background: c.Bool("background"),
154-
User: c.String("user"),
155-
})
156-
157-
return nil
158-
},
159-
},
160-
{
161-
Name: "exec-file",
162-
Usage: "execute a command with the decrypted contents as a temporary file",
163-
ArgsUsage: "[file to decrypt] [command to run]",
164-
Flags: append([]cli.Flag{
165-
cli.BoolFlag{
166-
Name: "background",
167-
Usage: "background the process and don't wait for it to complete",
168-
},
169-
cli.BoolFlag{
170-
Name: "no-fifo",
171-
Usage: "use a regular file instead of a fifo to temporarily hold the decrypted contents",
172-
},
173-
cli.StringFlag{
174-
Name: "user",
175-
Usage: "the user to run the command as",
176-
},
177-
}, keyserviceFlags...),
178-
Action: func(c *cli.Context) error {
179-
if len(c.Args()) != 2 {
180-
return common.NewExitError(fmt.Errorf("error: missing file to decrypt"), codes.ErrorGeneric)
181-
}
182-
183-
fileName := c.Args()[0]
184-
command := c.Args()[1]
185-
186-
inputStore := inputStore(c, fileName)
187-
outputStore := outputStore(c, fileName)
188-
189-
svcs := keyservices(c)
190-
opts := decryptOpts{
191-
OutputStore: outputStore,
192-
InputStore: inputStore,
193-
InputPath: fileName,
194-
Cipher: aes.NewCipher(),
195-
KeyServices: svcs,
196-
IgnoreMAC: c.Bool("ignore-mac"),
197-
}
198-
199-
output, err := decrypt(opts)
200-
if err != nil {
201-
return toExitError(err)
202-
}
203-
204-
exec.ExecWithFile(exec.ExecOpts{
205-
Command: command,
206-
Plaintext: output,
207-
Background: c.Bool("background"),
208-
Fifo: !c.Bool("no-fifo"),
209-
User: c.String("user"),
210-
})
211-
212-
return nil
213-
},
214-
},
215109
{
216110
Name: "publish",
217111
Usage: "Publish sops file to a configured destination",
@@ -812,7 +706,6 @@ func main() {
812706
}
813707

814708
outputFile := os.Stdout
815-
816709
if c.String("output") != "" {
817710
file, err := os.Create(c.String("output"))
818711
if err != nil {

cmd/sops/subcommand/exec/exec.go

Lines changed: 0 additions & 152 deletions
This file was deleted.

0 commit comments

Comments
 (0)