修改harbor账号密码

时间:2020-04-21
本文章向大家介绍修改harbor账号密码,主要包括修改harbor账号密码使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

    某一次harbor服务重启后无法登陆,密码肯定是正确的,但就是无法登陆,由于是内网部署,也无法使用邮箱找回之类的措施,所以就直接在harbor数据库中修改密码。 以下为笔记内容 。 

     毫无疑问我们只能进harbor的后台mysql进行修改,但是查资料发现,这个harbor中的mysql的密码是采用pbkdf2算法,调用的Hash函数为Sha1,迭代4096次,密钥长度为int型16位得出的,所以你常规的用明文密码去update是不行的,必须要通过算法将密钥算出来,然后update可以成功。

下面是密钥计算算法,计算明文为123QWEqwe, 盐值为gktqer4zml32472wmht9xeuixvg5pvjd, 迭代次数为4096, 密钥长度int型16位

运行环境为python2 版本,    注: python 3的模块名称已经修改,运行的时候会报错。

import hmac
import hashlib
from struct import Struct
from operator import xor
from itertools import izip, starmap
 
 
_pack_int = Struct('>I').pack
def pbkdf2_hex(data, salt, iterations=4096, keylen=16, hashfunc=None):
    return pbkdf2_bin(data, salt, iterations, keylen, hashfunc).encode('hex')
def pbkdf2_bin(data, salt, iterations=4096, keylen=16, hashfunc=None):
    hashfunc = hashfunc or hashlib.sha1
    mac = hmac.new(data, None, hashfunc)
    def _pseudorandom(x, mac=mac):
        h = mac.copy()
        h.update(x)
        return map(ord, h.digest())
    buf = []
    for block in xrange(1, -(-keylen // mac.digest_size) + 1):
        rv = u = _pseudorandom(salt + _pack_int(block))
        for i in xrange(iterations - 1):
            u = _pseudorandom(''.join(map(chr, u)))
            rv = starmap(xor, izip(rv, u))
        buf.extend(rv)
    return ''.join(map(chr, buf))[:keylen]
rv = pbkdf2_hex('123QWEqwe', 'gktqer4zml32472wmht9xeuixvg5pvjd', 4096, 16)
print(rv)

修改好明文密码和salt值后直接运行python文件

# python xx.py 
500026b9f02e84d1f41e7546b9b2d524

现在开始修改harbor密码

docker exec -it  b07b3206fea5  /bin/bash

psql (9.6.14)
Type "help" for help.

postgres=# help
You are using psql, the command-line interface to PostgreSQL.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit

postgres=# psql -U postgres -d postgres -h 127.0.0.1 -p 5432   # 进入psttsql客户端

postgres=# \c registry    #进入registry 数据库
You are now connected to database "registry" as user "postgres".

postgres=# select * from harbor_user;    #查询所有用户 

#更新用户密码 password会加密后的密码,salt为盐值,按select查询结果中显示的为准

postgres=# update harbor_user set password='500026b9f02e84d1f41e7546b9b2d524', salt='oafrcwi1rh83bem3cnfldltaw4cf9pqm'  where username='admin';

postgres=# \q #退出postsql数据库

原文地址:https://www.cnblogs.com/xiaoshancun/p/12743733.html