Luzifer / vault2env

Small utility to transfer fields of a key in Vault into the environment
Apache License 2.0
9 stars 2 forks source link

Command with arguments #1

Closed kakoni closed 5 years ago

kakoni commented 5 years ago

Interesting and useful project, thanks.

When trying to run command with arguments, vault2env fails =>

vault2env --key=secret/mysql ls -la    
unknown shorthand flag: 'l' in -la

Escaping won't help

vault2env --key=secret/mysql "ls -la"    
FATA[0000] exec: "ls -la": executable file not found in $PATH
Luzifer commented 5 years ago

Just use a double-dash to separate commands:

vault2env --key=... -- ls -la

That's not a function of this tool but of your shell but it works.

Luzifer commented 5 years ago

Now this is part of the README. Thanks for bringing the lack of documentation about this to my attention! 🙂

kakoni commented 5 years ago

Aah, thanks. Forgot whole double-dash thing. Perhaps I use this same issue to ask about another thing;

Lets assume secret/mysq has username and password secrets

If I do something like

vault2env --key=secret/mysql -- curl -u$username:$password -v http://localhost:1234

It doesnt work. Curl reports that

* Server auth using Basic with user ''

so username and password are empty.

(vault2env --key=secret/mysql -- env displays them ok)

Any thoughts?

Luzifer commented 5 years ago

As those values are inserted into the env and your variables are evaluated by the surrounding shell this does not work as expected. You can wrap the command with another shell as a "workaround" to get it working:

$ vault write secret/example username=myuser password=mypass
Success! Data written to: secret/example

$ vault2env --key=secret/example -- echo "$username:$password"
:

$ vault2env --key=secret/example -- bash -ec 'echo "$username:$password"'
myuser:mypass
Luzifer commented 5 years ago

I've added this as an example to a new wiki page: https://github.com/Luzifer/vault2env/wiki/Usage-Examples (It will get linked in the README soon)

kakoni commented 5 years ago

Oh right, thanks. I testing shell wrapping with double quotes earlier vault2env --key=secret/example -- bash -c "echo $username" and this doesn't work. So perhaps that should be noted in that usage examples also.

Thanks for the help, now everything works as it should.