【问题标题】:Password is expired just after user is added to FreeIPA?将用户添加到 FreeIPA 后密码已过期?
【发布时间】:2019-12-17 12:23:14
【问题描述】:

我已经设置了一个 FreeIPA 服务器。我面临一个问题,即首次创建用户时密码已过期。因此,新用户在第一次登录时应始终设置他的密码,该密码在here 中定义。但我不想要这个功能。

我正在使用this library 在 FreeIPA 中创建或添加用户。

所以,我像这样连接 FreeIPA-

private function getIPA()
{
    $host = env('FREEIPA_HOST', 'cloud-host-ipa.com');
    $certificate = database_path(env('FREEIPA_CERTIFICATE', 'ca.crt'));
    try {
        return new \FreeIPA\APIAccess\Main($host, $certificate);
    } catch (Exception $e) {
        throw new \ErrorException("Error {$e->getCode()}: {$e->getMessage()}");
        return false;
    }
}

private function getIPAConnection() //Ged authinticated admin IPA connection
{
    $ipa = $this->getIPA();

    try {
        $auth = $ipa->connection()->authenticate(env('FREEIPA_ADMIN_NAME', 'oc-ipa-connector'), env('FREEIPA_ADMIN_PASS', 'ADMIN_PASS'));
        if ($auth) {
            return $ipa;
        } else {
            $auth_info = $ipa->connection()->getAuthenticationInfo();
            $auth_info = implode(' ', $auth_info);
            throw new \ErrorException("\nLogin Failed : {$auth_info}");
            //return false;
        }
    } catch (Exception $e) {
        throw new \ErrorException("\nError {$e->getCode()}: {$e->getMessage()}");
        //return false;
    }
}

然后像这样添加一个用户-

$ipa = $this->getIPAConnection();
try {
    $new_user_data = array(
        'givenname' =>  $givenname,
        'sn'        =>  $sn,
        'uid'       =>  $uid,
        //'userpassword' => $_POST["userpassword"],
        'mail'      =>  $mail,
        'mobile'    =>  $phone
    );

    $add_user = $ipa->user()->add($new_user_data);
    if ($add_user) {
        return true;
    }
} catch (Exception $e) {
    throw new \ErrorException("Error {$e->getCode()}: {$e->getMessage()}");
    return false;
}

此代码运行良好,并添加了用户。

然后我用这个代码设置密码-

$ipa = $this->getIPAConnection();

try {
    $user_info = $ipa->user()->get($uid);

    if($user_info != false)
    {
        try {
            $new_user_data = array(
                'userpassword' => $password,
            );

            $mod_user = $ipa->user()->modify($uid, $new_user_data);

            if ($mod_user) {
                return true;
            }
            else
            {
                return false;
            }
        } catch (Exception $e) {
            throw new \ErrorException("Error {$e->getCode()}: {$e->getMessage()}");
        }
    }
} catch (Exception $e) {
    throw new \ErrorException("Error {$e->getCode()}: {$e->getMessage()}");
}

密码也设置得很完美。但是设置的密码刚设置完就自动过期了。

我希望我的用户拥有此密码至少 1 周。所以,我想禁用this 功能。有什么实用的方法吗?

重新-

我在 FreeIPA 中创建了this issue 来为我们提供解决方法,但问题已关闭并标记为 - Closed: wontfix 。那么,我想知道是否存在解决方法?

【问题讨论】:

    标签: linux laravel authentication redhat freeipa


    【解决方案1】:

    答案在链接https://www.redhat.com/archives/freeipa-users/2012-June/msg00360.html中提供。

    您可以从以下命令中看到密码的全局策略:

    [server]$ ipa pwpolicy-show Group: global_policy Max lifetime (days): 90 Min lifetime (hours): 1 History size: 0 Character classes: 0 Min length: 8 Max failures: 6 Failure reset interval: 60 Lockout duration: 600

    您可以通过运行以下命令为要添加用户的组创建新的策略覆盖:

    [server]$ ipa pwpolicy-add sysadmin --minlife=0 Priority: 50 Group: sysadmin Min lifetime (hours): 0 Priority: 50

    现在此策略会覆盖全局密码策略并仅为组创建一个策略。

    如果你想修改全局策略,你可以用命令做同样的事情: [server]$ ipa pwpolicy-mod global_policy --minlife=0 Group: global_policy Max lifetime (days): 90 Min lifetime (hours): 0 History size: 0 Character classes: 0 Min length: 8 Max failures: 6 Failure reset interval: 60 Lockout duration: 600

    请注意将最小生命周期(小时)更改为 0,这会导致密码永不过期。

    创建用户后,您需要从服务器中的脚本运行此代码:

    echo -e $PASSWORD\n$PASSWORD\n$PASSWORD | kinit $username kdestroy

    请注意,您需要将PASSWORDusername 作为参数发送到脚本并远程执行此脚本。

    【讨论】:

    • 非常感谢您的帮助。我已经这样做了,但没有任何帮助,因为它不起作用:(你能给我提供一种不同的方法吗?
    • 我更新并添加了一个脚本,它将密码改回永不过期的旧密码。我意识到你的要求没有得到满足。所以我更新并测试了一个可以解决这个问题的新脚本。请注意,任何其他更改密码的尝试都不起作用,这是我看到的唯一可行的方法。推理已发布在链接中 - freeipa.org/page/New_Passwords_Expired
    猜你喜欢
    • 2013-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-17
    • 1970-01-01
    • 1970-01-01
    • 2020-12-31
    • 2017-03-09
    相关资源
    最近更新 更多