pyinfra
pyinfra copied to clipboard
Add encrypted password for server.user
Currently, pyinfra does now allow setting a user's password.
https://docs.pyinfra.com/en/1.x/operations/server.html#server-user
Sometimes it's required that users have a password. Adding in an ecrypted format would be great:
e.g:
server.user(
"foo", present=True,
unique=True,
encrypted_password="$6$zWs.EKU9NG2bZUIR$JipLm3jA0Cc0Z/6eZHrK2RSB66Pb.TXr4To9rHIC491LImbHxUa2o8Tqmpk.mVoaLsdIWmtRLcdCh1evWXE9e."
)
Here is a workaround:
import crypt
server.user(
"foo", present=True,
unique=True,
)
crypt_pw = crypt.crypt(PW_FROM_ENV_VAR, crypt.METHOD_SHA512)
server.shell(
name=f"Add password to foo user",
commands=[f"""echo 'foo:{crypt_pw}' | chpasswd -e"""],
)
I'm going to fix this... I have a working set of changes that pass the unit tests but holy smokes the e2e tests take a while to run.
https://github.com/pyinfra-dev/pyinfra/pull/1040