pyinfra icon indicating copy to clipboard operation
pyinfra copied to clipboard

Add encrypted password for server.user

Open oz123 opened this issue 3 years ago • 2 comments

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."
)

oz123 avatar May 02 '22 21:05 oz123

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"""],
)

themanifold avatar May 03 '22 09:05 themanifold

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

disser avatar Nov 22 '23 00:11 disser