I install files using standard POSIX utilities cp
, install
, sed
, sh
.
It is possible to fix any permission with chmod
/ chown
/ chgrp
but it is dangerous to temporarily expose sensitive data and fix it later.
"Standard" way to deal with the problem is to use install -m MODE -u USER -g GRP
.
What if I need to process file with a "dumb" utility (like grep
/ sed
/ awk
/ sh
)? How can I prevent data leak from such tools? By using umask 777
?
I consider following dangerous:
base64 -d secret.txt >/etc/app.key
sed -e '/^#.*/d' </etc/default/app.cfg >/etc/app.cfg
because file content might be accessible to other users if umask
is too open. Also I have to "fix" user/group after redirections...
PS Seems install
is not in POSIX... https://pubs.opengroup.org/onlinepubs/9699919799/utilities/contents.html
Also GNU install
doesn't read from pipe, so following trick is impossible:
sed ... < $SRC | install -m MODE -u USER -g GRP - $DEST
Some shell allow process substitution (<(cmd)
syntax) or one might create named pipe as workaround...