Kerberos簡介
環(huán)境信息
使用CentOS7操作系統(tǒng)。Ubuntu下的kerberos操作命令可能不同喧锦,以下均以CentOS7環(huán)境的為準(zhǔn)。
Kerberos的幾個概念
Realm
類似于namespace的概念扯夭,一個realm包含多個principal遵倦。一個principal屬于一個特定的realm。
Principal
認(rèn)證的主體额嘿,可以認(rèn)為等效于用戶名瘸恼。
Principal的名稱格式為
name/role@realm
Keytab
二進(jìn)制文件。包含了principal和加密了的principal密鑰信息册养,可以用來認(rèn)證principal东帅。
Kadmin
Kadmin即Kerberos administration server,運行在主kerberos節(jié)點球拦。負(fù)責(zé)存儲KDC數(shù)據(jù)庫靠闭,管理principal信息帐我。
Kerberos安裝和配置
安裝kerberos
Kerberos主節(jié)點(Kadmin,KDC)執(zhí)行如下命令:
yum install -y krb5-server krb5-libs krb5-workstation
Kerberos從節(jié)點(只使用Kerberos認(rèn)證)執(zhí)行如下命令:
yum install -y krb5-devel krb5-workstation
配置krb5.conf
krb5.conf
位于/etc/krb5.conf
愧膀。
[logging]
default = FILE:/var/log/krb5libs.log
kdc = FILE:/var/log/krb5kdc.log
admin_server = FILE:/var/log/kadmind.log
[libdefaults]
dns_lookup_realm = false
ticket_lifetime = 24h
renew_lifetime = 7d
forwardable = true
rdns = false
pkinit_anchors = FILE:/etc/pki/tls/certs/ca-bundle.crt
# default_realm = EXAMPLE.COM
default_ccache_name = KEYRING:persistent:%{uid}
[realms]
# EXAMPLE.COM = {
# kdc = kerberos.example.com
# admin_server = kerberos.example.com
# }
[domain_realm]
# .example.com = EXAMPLE.COM
# example.com = EXAMPLE.COM
logging模塊:
配置默認(rèn)拦键,KDC和kadmin服務(wù)的log文件路徑。
libdefaults模塊:
- dns_lookup_realm:使用主機(jī)域名到kerberos domain的映射定位KDC檩淋。
- ticket_lifetime:ticket過期時間芬为,超過這個時間ticket需要重新申請或renew。
- renew_lifetime:ticket可進(jìn)行renew的時間限制蟀悦。
- forwardable:如果配置為true媚朦,在KDC允許的情況下,初始ticket可以被轉(zhuǎn)發(fā)熬芜。
- rdns:是否可使用逆向DNS莲镣。
- pkinit_anchors:簽署KDC證書的根證書。
- default_realm:默認(rèn)的realm涎拉。
- default_ccache_name:默認(rèn)憑據(jù)緩存的命名規(guī)則瑞侮。
realms模塊:
使用如下的模版配置:
EXAMPLE.COM = {
kdc = kerberos.example.com
admin_server = kerberos.example.com
}
- admin_server:kadmin服務(wù)(即Kerberos administration server)所在節(jié)點。
- kdc:KDC服務(wù)所在節(jié)點鼓拧。
domain_realm模塊:
此模塊配置了domain name或者h(yuǎn)ostname同kerberos realm之間的映射關(guān)系半火。
官網(wǎng)配置項詳細(xì)解釋參見:http://web.mit.edu/kerberos/krb5-latest/doc/admin/conf_files/krb5_conf.html
配置kdc.conf
kdc.conf
位于/var/kerberos/krb5kdc/kdc.conf
。默認(rèn)kdc.conf
文件如下所示:
[kdcdefaults]
kdc_ports = 88
kdc_tcp_ports = 88
[realms]
EXAMPLE.COM = {
#master_key_type = aes256-cts
acl_file = /var/kerberos/krb5kdc/kadm5.acl
dict_file = /usr/share/dict/words
admin_keytab = /var/kerberos/krb5kdc/kadm5.keytab
supported_enctypes = aes256-cts:normal aes128-cts:normal des3-hmac-sha1:normal arcfour-hmac:normal camellia256-cts:normal camellia128-cts:normal des-hmac-sha1:normal des-cbc-md5:normal des-cbc-crc:normal
}
- kdc_ports:KDC服務(wù)監(jiān)聽的端口季俩。
- acl_file:ACL文件的路徑钮糖。Kerberos使用這個ACL文件來確定哪些principal具有哪些權(quán)限。
- dict_file:存放一個由多行字符串構(gòu)成的文本文件酌住,該文件中的字符串禁止作為密碼使用店归。
- admin_keytab:KDC 進(jìn)行校驗的 keytab。
- supported_enctypes:支持的加密算法類型酪我。
- default_principal_flags:默認(rèn)的principal標(biāo)識消痛,即創(chuàng)建principal時候無需特殊指定默認(rèn)自帶的標(biāo)識。
官網(wǎng)配置項詳細(xì)解釋參見:http://web.mit.edu/kerberos/krb5-latest/doc/admin/conf_files/kdc_conf.html
配置kadm5.acl
ACL文件用于控制kadmin數(shù)據(jù)庫的訪問權(quán)限都哭,以及哪些principal可以操作其他的principal秩伞。位于/var/kerberos/krb5kdc/kadm5.acl
。配置文件格式為:
principal permissions [target_principal [restrictions] ]
permissions官網(wǎng)有詳細(xì)的列表欺矫,平時最為常用的是”*“纱新,表示允許所有權(quán)限,并將該權(quán)限賦予管理員類型的principal穆趴。
例如我們配置:
*/admin@PAUL.COM *
表示所有后綴為/admin@PAUL.COM
的principal具有所有權(quán)限脸爱,充當(dāng)管理員角色。
官網(wǎng)配置項詳細(xì)解釋參見:http://web.mit.edu/kerberos/krb5-latest/doc/admin/conf_files/kadm5_acl.html
初始化Kadmin數(shù)據(jù)庫
命令格式為:
kdb5_util create -s -r [realm]
例如我們使用的realm為PAUL.COM
未妹,初始化數(shù)據(jù)庫的命令為:
kdb5_util create -s -r PAUL.COM
根據(jù)提示輸入database密碼:
Loading random data
Initializing database '/var/kerberos/krb5kdc/principal' for realm 'PAUL.COM',
master key name 'K/M@PAUL.COM'
You will be prompted for the database Master Password.
It is important that you NOT FORGET this password.
Enter KDC database master key:
Re-enter KDC database master key to verify:
啟動Kerberos服務(wù)
systemctl start kadmin krb5kdc
Kerberos操作
Kadmin數(shù)據(jù)庫操作
在運行kadmin的節(jié)點上執(zhí)行如下命令阅羹,進(jìn)入kadmin操作模式:
kadmin.local
如果有訪問 KDC 服務(wù)器的 root 權(quán)限勺疼,但沒有 kerberos admin 賬戶教寂,使用
kadmin.local
捏鱼。如果沒有訪問 KDC服務(wù)器的 root 權(quán)限,但用 kerberos admin 賬戶酪耕,使用
kadmin
导梆。還可以使用
kadmin.local -q "命令"
的方式直接從shell操作kadmin數(shù)據(jù)庫。
輸入"?"可以獲取到所有命令和解釋:
kadmin.local: ?
Available kadmin.local requests:
add_principal, addprinc, ank
Add principal
delete_principal, delprinc
Delete principal
modify_principal, modprinc
Modify principal
rename_principal, renprinc
Rename principal
change_password, cpw Change password
get_principal, getprinc Get principal
list_principals, listprincs, get_principals, getprincs
List principals
add_policy, addpol Add policy
modify_policy, modpol Modify policy
delete_policy, delpol Delete policy
get_policy, getpol Get policy
list_policies, listpols, get_policies, getpols
List policies
get_privs, getprivs Get privileges
ktadd, xst Add entry(s) to a keytab
ktremove, ktrem Remove entry(s) from a keytab
lock Lock database exclusively (use with extreme caution!)
unlock Release exclusive database lock
purgekeys Purge previously retained old keys from a principal
get_strings, getstrs Show string attributes on a principal
set_string, setstr Set a string attribute on a principal
del_string, delstr Delete a string attribute on a principal
list_requests, lr, ? List available requests.
quit, exit, q Exit program.
listprincs
列出所有的principal迂烁。
kadmin.local: listprincs
K/M@PAUL.COM
kadmin/admin@PAUL.COM
kadmin/changepw@PAUL.COM
kadmin/d7b07e9f1287@PAUL.COM
kiprop/d7b07e9f1287@PAUL.COM
krbtgt/PAUL.COM@PAUL.COM
addprinc
添加一個principal看尼。如果沒有指定-randkey
或-nokey
參數(shù),需要指定一個密碼盟步。
kadmin.local: addprinc demo/localhost
WARNING: no policy specified for demo/localhost@PAUL.COM; defaulting to no policy
Enter password for principal "demo/localhost@PAUL.COM":
Re-enter password for principal "demo/localhost@PAUL.COM":
Principal "demo/localhost@PAUL.COM" created.
此時可以使用kinit命令藏斩,登陸這個principal。
sh-4.2# kinit demo/localhost@PAUL.COM
Password for demo/localhost@PAUL.COM:
sh-4.2# klist
Ticket cache: KEYRING:persistent:0:0
Default principal: demo/localhost@PAUL.COM
Valid starting Expires Service principal
03/23/21 01:26:55 03/24/21 01:26:55 krbtgt/PAUL.COM@PAUL.COM
modprinc
修改principal却盘。為principal增加或去掉部分屬性狰域。包含的屬性和參數(shù)參見命令幫助。
kadmin.local: modprinc
usage: modify_principal [options] principal
options are:
[-x db_princ_args]* [-expire expdate] [-pwexpire pwexpdate] [-maxlife maxtixlife]
[-kvno kvno] [-policy policy] [-clearpolicy]
[-maxrenewlife maxrenewlife] [-unlock] [{+|-}attribute]
attributes are:
allow_postdated allow_forwardable allow_tgs_req allow_renewable
allow_proxiable allow_dup_skey allow_tix requires_preauth
requires_hwauth needchange allow_svr password_changing_service
ok_as_delegate ok_to_auth_as_delegate no_auth_data_required
lockdown_keys
where,
[-x db_princ_args]* - any number of database specific arguments.
Look at each database documentation for supported arguments
delprinc
刪除principal黄橘。
kadmin.local: delprinc test/localhost
Are you sure you want to delete the principal "test/localhost@PAUL.COM"? (yes/no): yes
Principal "test/localhost@PAUL.COM" deleted.
Make sure that you have removed this principal from all ACLs before reusing.
change_password
修改principal的密碼兆览。之后使用kinit
命令認(rèn)證,需要使用新的密碼塞关。
kadmin.local: change_password demo/localhost@PAUL.COM
Enter password for principal "demo/localhost@PAUL.COM":
Re-enter password for principal "demo/localhost@PAUL.COM":
Password for "demo/localhost@PAUL.COM" changed.
ktadd
生成一個keytab抬探,或者是將一個principal加入到keytab。
kadmin.local: ktadd -norandkey -k /root/demo.keytab demo/localhost@PAUL.COM
Entry for principal demo/localhost@PAUL.COM with kvno 4, encryption type aes256-cts-hmac-sha1-96 added to keytab WRFILE:/root/demo.keytab.
Entry for principal demo/localhost@PAUL.COM with kvno 4, encryption type aes128-cts-hmac-sha1-96 added to keytab WRFILE:/root/demo.keytab.
Entry for principal demo/localhost@PAUL.COM with kvno 4, encryption type des3-cbc-sha1 added to keytab WRFILE:/root/demo.keytab.
Entry for principal demo/localhost@PAUL.COM with kvno 4, encryption type arcfour-hmac added to keytab WRFILE:/root/demo.keytab.
Entry for principal demo/localhost@PAUL.COM with kvno 4, encryption type camellia256-cts-cmac added to keytab WRFILE:/root/demo.keytab.
Entry for principal demo/localhost@PAUL.COM with kvno 4, encryption type camellia128-cts-cmac added to keytab WRFILE:/root/demo.keytab.
Entry for principal demo/localhost@PAUL.COM with kvno 4, encryption type des-hmac-sha1 added to keytab WRFILE:/root/demo.keytab.
Entry for principal demo/localhost@PAUL.COM with kvno 4, encryption type des-cbc-md5 added to keytab WRFILE:/root/demo.keytab.
對于上面這條命令帆赢,如果執(zhí)行的時候/root/demo.keytab
不存在小压,會生成一個新的keytab文件。然后將demo/localhost@PAUL.COM
這個principal添加到該keytab椰于。-norandkey
參數(shù)的含義是不更改密碼怠益。也就是說現(xiàn)在這個principal既可以使用原來的密碼認(rèn)證,也可以使用新生成的keytab認(rèn)證廉羔。
我們在
kdc.conf
的supported_enctypes
配置項指定了8種加密算法溉痢,因此這里會打印出8個entry。
使用keytab方式認(rèn)證的命令如下:
kinit -kt demo.keytab demo/localhost@PAUL.COM
我們可以使用ktadd
命令憋他,將多個principal加入同一個keytab文件孩饼,這樣該keytab文件可用于認(rèn)證多個用戶。例如:
kadmin.local: addprinc test/localhost@PAUL.COM
WARNING: no policy specified for test/localhost@PAUL.COM; defaulting to no policy
Enter password for principal "test/localhost@PAUL.COM":
Re-enter password for principal "test/localhost@PAUL.COM":
Principal "test/localhost@PAUL.COM" created.
kadmin.local: ktadd -kt /root/demo.keytab test/localhost@PAUL.COM
Entry for principal test/localhost@PAUL.COM with kvno 4, encryption type aes256-cts-hmac-sha1-96 added to keytab WRFILE:/root/demo.keytab.
Entry for principal test/localhost@PAUL.COM with kvno 4, encryption type aes128-cts-hmac-sha1-96 added to keytab WRFILE:/root/demo.keytab.
Entry for principal test/localhost@PAUL.COM with kvno 4, encryption type des3-cbc-sha1 added to keytab WRFILE:/root/demo.keytab.
Entry for principal test/localhost@PAUL.COM with kvno 4, encryption type arcfour-hmac added to keytab WRFILE:/root/demo.keytab.
Entry for principal test/localhost@PAUL.COM with kvno 4, encryption type camellia256-cts-cmac added to keytab WRFILE:/root/demo.keytab.
Entry for principal test/localhost@PAUL.COM with kvno 4, encryption type camellia128-cts-cmac added to keytab WRFILE:/root/demo.keytab.
Entry for principal test/localhost@PAUL.COM with kvno 4, encryption type des-hmac-sha1 added to keytab WRFILE:/root/demo.keytab.
Entry for principal test/localhost@PAUL.COM with kvno 4, encryption type des-cbc-md5 added to keytab WRFILE:/root/demo.keytab.
此時我們使用klist
命令查看下關(guān)聯(lián)了/root/demo.keytab
文件的principal:
sh-4.2# klist -kt demo.keytab
Keytab name: FILE:demo.keytab
KVNO Timestamp Principal
---- ----------------- --------------------------------------------------------
4 03/23/21 05:38:02 demo/localhost@PAUL.COM
4 03/23/21 05:38:02 demo/localhost@PAUL.COM
4 03/23/21 05:38:02 demo/localhost@PAUL.COM
4 03/23/21 05:38:02 demo/localhost@PAUL.COM
4 03/23/21 05:38:02 demo/localhost@PAUL.COM
4 03/23/21 05:38:02 demo/localhost@PAUL.COM
4 03/23/21 05:38:02 demo/localhost@PAUL.COM
4 03/23/21 05:38:02 demo/localhost@PAUL.COM
4 03/23/21 05:57:39 test/localhost@PAUL.COM
4 03/23/21 05:57:39 test/localhost@PAUL.COM
4 03/23/21 05:57:39 test/localhost@PAUL.COM
4 03/23/21 05:57:39 test/localhost@PAUL.COM
4 03/23/21 05:57:39 test/localhost@PAUL.COM
4 03/23/21 05:57:39 test/localhost@PAUL.COM
4 03/23/21 05:57:39 test/localhost@PAUL.COM
4 03/23/21 05:57:39 test/localhost@PAUL.COM
看到這個輸出說明demo.keytab
已經(jīng)關(guān)聯(lián)這兩個principal竹挡。
ktremove
從keytab中刪除關(guān)聯(lián)的principal镀娶。
接著上面的例子,如果需要刪除test/localhost@PAUL.COM
和/root/demo.keytab
的關(guān)聯(lián)揪罕,執(zhí)行如下命令:
kadmin.local: ktremove -k /root/demo.keytab test/localhost@PAUL.COM
Entry for principal test/localhost@PAUL.COM with kvno 4 removed from keytab WRFILE:/root/demo.keytab.
Entry for principal test/localhost@PAUL.COM with kvno 4 removed from keytab WRFILE:/root/demo.keytab.
Entry for principal test/localhost@PAUL.COM with kvno 4 removed from keytab WRFILE:/root/demo.keytab.
Entry for principal test/localhost@PAUL.COM with kvno 4 removed from keytab WRFILE:/root/demo.keytab.
Entry for principal test/localhost@PAUL.COM with kvno 4 removed from keytab WRFILE:/root/demo.keytab.
Entry for principal test/localhost@PAUL.COM with kvno 4 removed from keytab WRFILE:/root/demo.keytab.
Entry for principal test/localhost@PAUL.COM with kvno 4 removed from keytab WRFILE:/root/demo.keytab.
Entry for principal test/localhost@PAUL.COM with kvno 4 removed from keytab WRFILE:/root/demo.keytab.
然后我們使用klist
查看/root/demo.keytab
關(guān)聯(lián)的principal:
sh-4.2# klist -kt demo.keytab
Keytab name: FILE:demo.keytab
KVNO Timestamp Principal
---- ----------------- --------------------------------------------------------
4 03/23/21 05:38:02 demo/localhost@PAUL.COM
4 03/23/21 05:38:02 demo/localhost@PAUL.COM
4 03/23/21 05:38:02 demo/localhost@PAUL.COM
4 03/23/21 05:38:02 demo/localhost@PAUL.COM
4 03/23/21 05:38:02 demo/localhost@PAUL.COM
4 03/23/21 05:38:02 demo/localhost@PAUL.COM
4 03/23/21 05:38:02 demo/localhost@PAUL.COM
4 03/23/21 05:38:02 demo/localhost@PAUL.COM
發(fā)現(xiàn)test/localhost@PAUL.COM
的8個entry已經(jīng)被移除梯码。我們無法再使用/root/demo.keytab
認(rèn)證test/localhost@PAUL.COM
宝泵。
Kerberos命令
kinit
獲取principal授予的票據(jù),并緩存(認(rèn)證principal)轩娶。
可以使用-h
參數(shù)獲取該命令的幫助信息:
kinit -h
使用password進(jìn)行認(rèn)證
直接輸入kinit principal
儿奶,然后命令行會提示輸入密碼。
sh-4.2# kinit demo/localhost@PAUL.COM
Password for demo/localhost@PAUL.COM:
sh-4.2# klist
Ticket cache: KEYRING:persistent:0:0
Default principal: demo/localhost@PAUL.COM
Valid starting Expires Service principal
03/23/21 01:26:55 03/24/21 01:26:55 krbtgt/PAUL.COM@PAUL.COM
使用keytab進(jìn)行認(rèn)證
和password不同的是鳄抒,我們使用-kt
參數(shù)指定keytab文件的路徑闯捎,例如:
kinit demo/localhost@PAUL.COM -kt /root/demo.keytab
Ticket續(xù)約
如果沒有配置KDC允許續(xù)約,會出現(xiàn)類似如下問題:
執(zhí)行klist
许溅,沒有續(xù)約提示瓤鼻。
sh-4.2# klist
Ticket cache: KEYRING:persistent:0:0
Default principal: demo/localhost@PAUL.COM
Valid starting Expires Service principal
03/23/21 02:46:06 03/24/21 02:46:06 krbtgt/PAUL.COM@PAUL.COM
執(zhí)行kinit -R
,報如下錯誤:
sh-4.2# kinit -R
kinit: KDC can't fulfill requested option while renewing credentials
解決方法:
編輯/var/kerberos/krb5kdc/kdc.conf
文件贤重,按照如下注釋修改配置:
[realms]
PAUL.COM = {
#master_key_type = aes256-cts
acl_file = /var/kerberos/krb5kdc/kadm5.acl
dict_file = /usr/share/dict/words
admin_keytab = /var/kerberos/krb5kdc/kadm5.keytab
# 增加最大允許續(xù)約時間
max_renewable_life = 7d 0h 0m 0s
# 增加principal默認(rèn)的flag:允許續(xù)約
default_principal_flags = +renewable
supported_enctypes = aes256-cts:normal aes128-cts:normal des3-hmac-sha1:normal arcfour-hmac:normal camellia256-cts:normal camellia128-cts:normal des-hmac-sha1:normal des-cbc-md5:normal des-cbc-crc:normal
}
然后重啟Kerberos相關(guān)服務(wù)茬祷,重新創(chuàng)建kadmin
數(shù)據(jù)庫:
systemctl restart kadmin krb5kdc
如果kadmin
數(shù)據(jù)庫已存在,使用下方命令刪除:
sh-4.2# kdb5_util destroy -r PAUL.COM
Deleting KDC database stored in '/var/kerberos/krb5kdc/principal', are you sure?
(type 'yes' to confirm)? yes
OK, deleting database '/var/kerberos/krb5kdc/principal'...
** Database '/var/kerberos/krb5kdc/principal' destroyed.
再創(chuàng)建數(shù)據(jù)庫:
kdb5_util create -s -r PAUL.COM
然后使用addprinc
等命令創(chuàng)建principal和keytab并蝗。
kadmin.local: addprinc demo
WARNING: no policy specified for demo@PAUL.COM; defaulting to no policy
Enter password for principal "demo@PAUL.COM":
Re-enter password for principal "demo@PAUL.COM":
Principal "demo@PAUL.COM" created.
kadmin.local: ktadd -kt /root/demo.keytab demo
Entry for principal demo with kvno 2, encryption type aes256-cts-hmac-sha1-96 added to keytab WRFILE:/root/demo.keytab.
Entry for principal demo with kvno 2, encryption type aes128-cts-hmac-sha1-96 added to keytab WRFILE:/root/demo.keytab.
Entry for principal demo with kvno 2, encryption type des3-cbc-sha1 added to keytab WRFILE:/root/demo.keytab.
Entry for principal demo with kvno 2, encryption type arcfour-hmac added to keytab WRFILE:/root/demo.keytab.
Entry for principal demo with kvno 2, encryption type camellia256-cts-cmac added to keytab WRFILE:/root/demo.keytab.
Entry for principal demo with kvno 2, encryption type camellia128-cts-cmac added to keytab WRFILE:/root/demo.keytab.
Entry for principal demo with kvno 2, encryption type des-hmac-sha1 added to keytab WRFILE:/root/demo.keytab.
Entry for principal demo with kvno 2, encryption type des-cbc-md5 added to keytab WRFILE:/root/demo.keytab.
然后我們使用kinit
命令認(rèn)證祭犯,并使用klist
命令查看:
sh-4.2# kinit -kt demo.keytab demo
sh-4.2# klist
Ticket cache: KEYRING:persistent:0:krb_ccache_vhzDpIA
Default principal: demo@PAUL.COM
Valid starting Expires Service principal
03/23/21 08:31:43 03/24/21 08:31:43 krbtgt/PAUL.COM@PAUL.COM
renew until 03/30/21 08:31:43
我們發(fā)現(xiàn)klist
輸出多了rennew until
字樣,表示在這個日期前可以續(xù)約借卧。執(zhí)行kinit -R
命令續(xù)約:
sh-4.2# kinit -R
sh-4.2# klist
Ticket cache: KEYRING:persistent:0:krb_ccache_vhzDpIA
Default principal: demo@PAUL.COM
Valid starting Expires Service principal
03/23/21 08:33:56 03/24/21 08:33:56 krbtgt/PAUL.COM@PAUL.COM
renew until 03/30/21 08:31:43
此時kinit -R
命令不再報錯盹憎,且Valid starting
和Expires
時間已經(jīng)更新。
注意:
如果我們已經(jīng)創(chuàng)建出的principal不允許續(xù)約或者是更改最大允許續(xù)約時間铐刘,可執(zhí)行如下命令:
modprinc -maxrenewlife 1week +allow_renewable demo/localhost@PAUL.COM
kdestroy
銷毀當(dāng)前認(rèn)證票據(jù)陪每,刪除憑據(jù)緩存。該命令不需要任何參數(shù)镰吵¢莺蹋可使用kdestroy -A
清除所有憑據(jù)緩存。
klist
查看當(dāng)前憑據(jù)緩存內(nèi)的票據(jù)疤祭。
sh-4.2# klist
Ticket cache: KEYRING:persistent:0:0
Default principal: demo/localhost@PAUL.COM
Valid starting Expires Service principal
03/23/21 01:26:55 03/24/21 01:26:55 krbtgt/PAUL.COM@PAUL.COM
如果處于未認(rèn)證狀態(tài)盼产,返回的結(jié)果如下所示:
sh-4.2# klist
klist: Credentials cache keyring 'persistent:0:0' not found
除此之外klist命令還可以列出某個keytab文件關(guān)聯(lián)的principal。
sh-4.2# klist -kt demo.keytab
Keytab name: FILE:demo.keytab
KVNO Timestamp Principal
---- ----------------- --------------------------------------------------------
4 03/23/21 05:38:02 demo/localhost@PAUL.COM
4 03/23/21 05:38:02 demo/localhost@PAUL.COM
4 03/23/21 05:38:02 demo/localhost@PAUL.COM
4 03/23/21 05:38:02 demo/localhost@PAUL.COM
4 03/23/21 05:38:02 demo/localhost@PAUL.COM
4 03/23/21 05:38:02 demo/localhost@PAUL.COM
4 03/23/21 05:38:02 demo/localhost@PAUL.COM
4 03/23/21 05:38:02 demo/localhost@PAUL.COM
ktutil命令
ktutil
是方便用戶操作keytab文件的工具集勺馆。我們可以使用ktutil
命令進(jìn)入ktutil
模式戏售。
鍵入"?"獲取ktutil
的幫助信息。
ktutil: ?
Available ktutil requests:
clear_list, clear Clear the current keylist.
read_kt, rkt Read a krb5 keytab into the current keylist.
read_st, rst Read a krb4 srvtab into the current keylist.
write_kt, wkt Write the current keylist to a krb5 keytab.
write_st, wst Write the current keylist to a krb4 srvtab.
add_entry, addent Add an entry to the current keylist.
delete_entry, delent Delete an entry from the current keylist.
list, l List the current keylist.
list_requests, lr, ? List available requests.
quit, exit, q Exit program.
ktutil
命令常用于合并keytab文件草穆,比如我們有:
-
/root/demo.keytab
對應(yīng)demo/localhost@PAUL.COM
-
/root/test.keytab
對應(yīng)test/localhost@PAUL.COM
我們可以用如下命令將這兩個keytab合并為/root/merged.keytab
:
ktutil: rkt demo.keytab
ktutil: rkt test.keytab
ktutil: l
slot KVNO Principal
---- ---- ---------------------------------------------------------------------
1 4 demo/localhost@PAUL.COM
2 4 demo/localhost@PAUL.COM
3 4 demo/localhost@PAUL.COM
4 4 demo/localhost@PAUL.COM
5 4 demo/localhost@PAUL.COM
6 4 demo/localhost@PAUL.COM
7 4 demo/localhost@PAUL.COM
8 4 demo/localhost@PAUL.COM
9 5 test/localhost@PAUL.COM
10 5 test/localhost@PAUL.COM
11 5 test/localhost@PAUL.COM
12 5 test/localhost@PAUL.COM
13 5 test/localhost@PAUL.COM
14 5 test/localhost@PAUL.COM
15 5 test/localhost@PAUL.COM
16 5 test/localhost@PAUL.COM
ktutil: wkt /root/merged.keytab
到此為止/root/merged.keytab
文件可用于認(rèn)證這兩個principal灌灾。我們可以用klist
命令查看下:
sh-4.2# klist -kt merged.keytab
Keytab name: FILE:merged.keytab
KVNO Timestamp Principal
---- ----------------- --------------------------------------------------------
4 03/23/21 06:55:13 demo/localhost@PAUL.COM
4 03/23/21 06:55:13 demo/localhost@PAUL.COM
4 03/23/21 06:55:13 demo/localhost@PAUL.COM
4 03/23/21 06:55:13 demo/localhost@PAUL.COM
4 03/23/21 06:55:13 demo/localhost@PAUL.COM
4 03/23/21 06:55:13 demo/localhost@PAUL.COM
4 03/23/21 06:55:13 demo/localhost@PAUL.COM
4 03/23/21 06:55:13 demo/localhost@PAUL.COM
5 03/23/21 06:55:13 test/localhost@PAUL.COM
5 03/23/21 06:55:13 test/localhost@PAUL.COM
5 03/23/21 06:55:13 test/localhost@PAUL.COM
5 03/23/21 06:55:13 test/localhost@PAUL.COM
5 03/23/21 06:55:13 test/localhost@PAUL.COM
5 03/23/21 06:55:13 test/localhost@PAUL.COM
5 03/23/21 06:55:13 test/localhost@PAUL.COM
5 03/23/21 06:55:13 test/localhost@PAUL.COM
Docker搭建Kerberos開發(fā)環(huán)境
我們基于CentOS7,創(chuàng)建Kerberos鏡像悲柱。編寫Dockerfile
如下:
FROM centos:centos7
RUN yum install -y krb5-server krb5-libs krb5-workstation
CMD ["/usr/sbin/init"]
然后執(zhí)行如下命令锋喜,構(gòu)建鏡像:
docker build -t kerberos:0.1 .
啟動該Kerberos容器的命令:
docker run --privileged -p 88:88 -p 749:749 -p 750:750 -d --name=kerberos kerberos:0.1
注意,必須添加
--privileged
參數(shù),且程序入口為/usr/sbin/init
嘿般。只有這樣才能夠在容器內(nèi)運行systemctl
命令段标,否則會出錯。
進(jìn)入容器的方法:
docker exec -it kerberos sh
然后我們可以像真機(jī)環(huán)境一樣操作Kerberos了炉奴。
本博客為作者原創(chuàng)逼庞,歡迎大家參與討論和批評指正。如需轉(zhuǎn)載請注明出處盆佣。