kinit 如何生成不同版本的 credential cache file
https://web.mit.edu/kerberos/krb5-1.21/doc/formats/ccache_file_format.html
版本
Kerberos 凭证缓存文件(credential cache file)有不同的格式版本,这些版本通常由 MIT Kerberos 项目维护和定义。目前,常见的版本号有 1
到 4
.
- 版本
1
和2
:使用本地字节序来表示整数. - 版本
3
和4
:始终使用大端字节序 (big-endian). - 版本
4
增加了一个头部 (header) 格式,用于存储额外的元数据.
控制 kinit
生成不同版本的凭证缓存文件
要控制 kinit
使用的版本,你可以在 krb5.conf
文件的 [libdefaults]
部分添加或修改 ccache_type
参数.
Link: libdefaults
ccache_type
This parameter determines the format of credential cache types created by kinit or other programs. The default value is 4, which represents the most current format. Smaller values can be used for compatibility with very old implementations of Kerberos which interact with credential caches on the same host.
翻译
此参数决定 kinit 或其他程序创建的凭证缓存类型的格式。
默认值为 4,代表最新格式。
较小的值可用于兼容与同一主机上的凭证缓存交互的非常旧的 Kerberos 实现。
示例配置
[libdefaults]
default_realm = EXAMPLE.COM
# 指定凭证缓存文件的版本号
ccache_type = 2
注意:
大多数情况下,你不需要手动指定这个参数。Kerberos 库会自动处理版本兼容性问题。
只有在特定的环境或应用(例如,一些旧的或非标准的 Kerberos 实现)需要特定的缓存文件格式时,才需要进行此项配置。
在我的 ubuntu 24 机器上,它的默认配置是这样的:
文件位置: /etc/krb5.conf
[libdefaults]
default_realm = TESTUBUNTU.LOCAL
# The following krb5.conf variables are only for MIT Kerberos.
kdc_timesync = 1
ccache_type = 4
forwardable = true
proxiable = true
rdns = false
导出凭证缓存文件
kinit -c {path_of_your_credential_cachefile} {principal}
实例
kinit -c cc2.cache test@TESTUBUNTU.LOCAL
这条指定会将用户 test@TESTUBUNTU.LOCAL
的凭证导出到当前目录下,文件名为 cc2.cache
.
检查导出凭证缓存文件的版本号
对于凭证缓存文件来说,这个文件的前两个字节用于表示此文件的版本号。 使用一个支持打开二进制文件的编辑器打开,确保它的前两个字节是05 0{V}
(hex)即可.
比如:05 02
开头的凭证缓存文件表示它是 v2
版本的凭证缓存文件.