python - Writing a runit script for a program that requires a passphrase -


i wrote python program requires passphrase run, , securely read passphrase @ startup. supervise program runit.

so far, program reads passphrase environment variable "passphrase". planning start in such way runit set variable @ startup:

# !/bin/bash # file /etc/sv/mypgrm/run read -s -p "passphrase :" passphrase exec 2>&1 exec chpst env passphrase=$passphrase myprgm 

however, approach not work , line program started never reached. when remove first line of script, program starts empty passphrase.

could suggest alternate (secure) way of proceeding? thank you!

ok, after sharing problem fellow security aware engineers, turns out question 2-fold:

  1. how configure app without putting secret in code?
  2. how store secret?

the first question has easy answer: putting secrets in environment considered best practice (cf http://12factor.net/config).

the answer second question question: threat model? own reasoning: take passphrase? root. can prevent if person root? no, root can fetch in memory. root can steal data processed python program before gets processed. next threat model gets access , non root user. can prevent these users read passphrase if store in file proper access right.

so replace:

read -s -p "passphrase :" passphrase 

with:

passphrase=$(cat /etc/mypassphrase) 

and set file belong root , non readable otherwise. update answer if not work.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -