sops icon indicating copy to clipboard operation
sops copied to clipboard

Quotes in env formatted file are handled unexpectedly when using exec-env

Open adamhl8 opened this issue 2 years ago • 2 comments

When using exec-env on an env formatted file, quotes are included in the resulting environment variable.

secrets.env:

secret1='foo'
secret2="bar"
$ sops exec-env secrets.env 'echo $secret1'
'foo'
$ sops exec-env secrets.env 'echo $secret2'
"bar"

I would expect that environment variables would be set as if the file was sourceed or the variables were defined manually.

$ secret1='foo'; echo $secret1
foo
$ secret2="bar"; echo $secret2
bar

I realize this probably isn't actually a bug and it makes sense that the environment variable is set to the literal value in the context of other formats, but I think there should be special handling for quotes when the env format is used.

adamhl8 avatar Sep 21 '22 20:09 adamhl8

Is this expected? Is there a workaround besides defining dotenv files without quotes?

brettinternet avatar Dec 10 '23 22:12 brettinternet

This is expected.

The dotenv file format sops implements is very simple, files are split by \n, and every line can be one of the three forms:

  1. line is empty;
  2. starting with #: comment;
  3. contains a =: everything before = is the key, everything after the value; the literal string "\n" in the value is converted to a newline.

According to this file format quotes are part of the value.

felixfontein avatar Dec 11 '23 17:12 felixfontein