是否有一种方法来重置所有(或只是禁用安全设置)从命令行没有用户/密码,因为我已经设法完全锁定自己的詹金斯?


当前回答

为了删除Windows操作系统中jenkins的默认安全性,

您可以遍历在/users/{UserName}/.jenkins中创建的Config.xml文件。

在这个文件中,您可以更改代码

<useSecurity>true</useSecurity>

To,

<useSecurity>false</useSecurity>

其他回答

编辑$JENKINS_HOME/config.xml文件,修改去安全配置如下:

<authorizationStrategy class="hudson.security.AuthorizationStrategy$Unsecured"/>

之后詹金斯重启。

很多时候你没有权限编辑config.xml文件。

最简单的方法是返回config.xml,然后使用sudo命令删除。

使用命令sudo /etc/init.重启jenkinsd / jenkins重启

这将禁用Jenkins中的所有安全性,登录选项将消失

使用bcrypt可以解决这个问题。为试图使用bash和python自动化该过程的人扩展@Reem答案。

#!/bin/bash

pip install bcrypt
yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum -y install xmlstarlet

cat > /tmp/jenkinsHash.py <<EOF
import bcrypt
import sys

if not sys.argv[1]:
  sys.exit(10)

plaintext_pwd=sys.argv[1]
encrypted_pwd=bcrypt.hashpw(sys.argv[1], bcrypt.gensalt(rounds=10, prefix=b"2a"))
isCorrect=bcrypt.checkpw(plaintext_pwd, encrypted_pwd)

if not isCorrect:
   sys.exit(20);

print "{}".format(encrypted_pwd)
EOF

chmod +x /tmp/jenkinsHash.py
cd /var/lib/jenkins/users/admin*
pwd
while (( 1 )); do
    echo "Waiting for Jenkins to generate admin user's config file ..."

    if [[ -f "./config.xml" ]]; then
        break
    fi

    sleep 10
done

echo "Admin config file created"

admin_password=$(python /tmp/jenkinsHash.py password 2>&1)

# Repalcing the new passowrd
xmlstarlet -q ed --inplace -u "/user/properties/hudson.security.HudsonPrivateSecurityRealm_-Details/passwordHash" -v '#jbcrypt:'"$admin_password" config.xml

# Restart
systemctl restart jenkins
sleep 10

我把密码硬编码在这里,但它可以是一个用户输入取决于要求。还要确保添加sleep,否则围绕Jenkins的任何其他命令都将失败。

另一种方法是手动编辑用户的配置文件(例如/var/lib/jenkins/users/username/config.xml),并更新passwordHash的内容:

<passwordHash>#jbcrypt:$2a$10$razd3L1aXndFfBNHO95aj.IVrFydsxkcQCcLmujmFQzll3hcUrY7S</passwordHash>

一旦你完成了这些,只要重新启动Jenkins并使用以下密码登录:

test

我发现有问题的文件位于/var/lib/jenkins中,名为config.xml,修改后解决了这个问题。