-
I am needing to run a command that takes a password either from stdin or a file specified as an argument. What is the best way to do this without exposing the password unnecessarily? Here are the options I have come up with:
Am I missing a better idea? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
It's possible that the last bullet is the best choice. The first one is definitely problematic from (at least) an idempotency standpoint. You might be able to set requisites such that the password file won't be written under certain circumstances, but it's a little hacky. The environment variable route could work, but it has a pretty big leak exposure since anyone who can render the state could see the actual password substituted in the state block. mycommand:
cmd.run:
- name: "echo $THEPASSWORD | thecommand --password-file /dev/stdin"
- env:
- THEPASSWORD: "{{ pillar.get("thepassword") }}" In lieu of creating a new option for mycommand:
cmd.run:
- name: "echo $THEPASSWORD | thecommand --password-file /dev/stdin"
- env:
- THEPASSWORD: __slot__:salt:pillar.get(thepassword) ...which would get around the problematic rendering issue and force the "getting" of Pillar data to runtime. Although, this really feels similar to Kubernetes separates Environment Variables and Secrets... handling each in a different way to mitigate this issue. I personally wouldn't be opposed to that route, but slots probably get you the best solution without trying to get a feature merged. |
Beta Was this translation helpful? Give feedback.
Thanks, I hadn't seen the slots feature before. I also just discovered that the
cmd.run
state accepts more options than are documented, including astdin
option, which is perfect to use in conjunction with the slots feature. So we end up with this proof-of-concept:resulting in