Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Predeployment setup password (salt+hash) #263

Closed
mc-hack opened this issue Apr 12, 2019 · 5 comments
Closed

Predeployment setup password (salt+hash) #263

mc-hack opened this issue Apr 12, 2019 · 5 comments

Comments

@mc-hack
Copy link

mc-hack commented Apr 12, 2019

Hi folks,

I have to automate postfixadmin rollout together with other stuff (postfix, dovecot etc), so teh result is a full featured, standalone mailserver with tools -- like postfixadmin.

I do this with puppet and it would be really nice, if I could manage the Setuppassword with Puppet too. But if I generate a config.local.php with an pregenerated Item (salt+hash), setup.php ignores this and force me to generate a new salt+hash Item. This I have to manually insert into config.local.php -- and this is the opposite of automation ;-)

I'm not that fit with PHP, so maybe someone can help me?

Thanks,

Martin

@DavidGoodwin
Copy link
Member

You should be able to pregenerate a setup_password, and put it in your config.local.php.

The setup_password is a sha1, generated like this https://github.com/postfixadmin/postfixadmin/blob/master/public/setup.php#L443

So, you could create one on the command line if you wish like :

php -r 'echo "somesalt:" . sha1("somesalt:" . "password");'

@DavidGoodwin
Copy link
Member

(You can type any old password into the first page of setup.php and submit the form - then it will prompt you to type in the setup password, and create a user account .... the wording on the form probably needs improving to make this more obvious).

@mc-hack
Copy link
Author

mc-hack commented Apr 13, 2019

Hmmm... thats exactly what I did.

Anyway: in the form, I typed in the generated password -- and tried to create the user account ... but pfa says something like "If you want to use the password you entered as setup password, edit config.inc.php or config.local.php and set". So ist sounds to me, that the pregenerated hash isnt accepted.

All stuff happens here, right?

--->

function check_setup_password($password, $lostpw_mode = 0) {
    global $CONF;
    $error = 1; # be pessimistic

    $setuppw = "";
    if (isset($CONF['setup_password'])) {
        $setuppw = $CONF['setup_password'];
    }

    list($confsalt, $confpass, $trash) = explode(':', $setuppw . '::');
    $pass = encrypt_setup_password($password, $confsalt);

    $validpass = validate_password($password);

    if ($password == "") { # no password specified?
        $result = "Setup password must be specified<br />If you didn't set up a setup password yet, enter the password you want to use.";
    } elseif (count($validpass) > 0) {
        $result = $validpass[0]; # TODO: honor all error messages, not only the first one
    } elseif ($pass == $setuppw && $lostpw_mode == 0) { # correct passsword (and not asking for a new password)
        $result = "pass_OK";
        $error = 0;
    } else {
        $pass = encrypt_setup_password($password, generate_setup_password_salt());
        $result = "";
        if ($lostpw_mode == 1) {
            $error = 0; # non-matching password is expected when the user asks for a new password
        } else {
            $result = '<p><b>Setup password not specified correctly</b></p>';
        }
        $result .= '<p>If you want to use the password you entered as setup password, edit config.inc.php or config.local.php and set</p>';
        $result .= "<pre>\$CONF['setup_password'] = '$pass';</pre>";
    }
    return array($error, $result);
}

And this is what my Puppemodule generates (config.local.php) :

<?php
$CONF['database_type'] = 'mysqli';
$CONF['database_user'] = 'vmail';
$CONF['database_password'] = 'password';
$CONF['database_name'] = 'vmail';
$CONF['setup_password'] = '52225b1c765a31ff80e174332d33704b:42b7d0db86925435011fba8f1f650604d9088838';
$CONF['configured'] = true;
?>

If I call setup.php once and put the generated hashes into config.local.php (via Puppet, of course) it works. Not with the initially generated ...

Spooky...

Something with the salt? The salt is generated on another machine. Because the targetsystem doesnt exist at this point.....

@DavidGoodwin
Copy link
Member

That looks fine to me.... I'll see if i can replicate/test it (but it's likely to be a week before i can do anything).

@mc-hack
Copy link
Author

mc-hack commented Apr 15, 2019

Okay, I tried it again.

I think, its a problem with the worklflow. If I type in my predefinded password and the adminuser+password, it works BUT I get an error message about the setup password. If I refresh the site, everthing ist fine and I can login with the given adminuser+password.

So: you've to ignore the errormessage. But it woud be better, if there is'nt one. Would be less confusing.

DavidGoodwin added a commit that referenced this issue Aug 13, 2019
…assword is configured; change verbs depending on context etc; see #263
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants