pyinfra-dev / pyinfra

pyinfra turns Python code into shell commands and runs them on your servers. Execute ad-hoc commands and write declarative operations. Target SSH servers, local machine and Docker containers. Fast and scales from one server to thousands.
https://pyinfra.com
MIT License
3.82k stars 372 forks source link

Add encrypted password for server.user #804

Open oz123 opened 2 years ago

oz123 commented 2 years ago

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."
)
themanifold commented 2 years ago

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"""],
)
disser commented 9 months ago

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