前言
之前的博文中涉及到了Kerberos的内容,这里对Kerberos ticket lifetime相关的内容做一个补充。
ticket lifetime
Kerberos ticket具有lifetime,超过此时间则ticket就会过期,需要重新申请或renew。ticket lifetime取决于以下5项设置中的最小值:
- Kerberos server上/var/kerberos/krb5kdc/kdc.conf中max_life
- 内置principal krbtgt的maximum ticket life,可在kadmin命令行下用getprinc命令查看
- 你的principal的maximum ticket life,可在kadmin命令行下用getprinc命令查看
- Kerberos client上/etc/krb5.conf的ticket_lifetime
- kinit -l 参数后面指定的时间
ticket renew lifetime
ticket过期后,如果想延长,一种方法是重新申请(需要输入密码),另一种是renew(不需要输入密码),每renew一次,就延长一个lifetime。不过renew操作本身也有lifetime,即在ticket renew lifetime,在此lifetime之内,才能进行renew操作。与上面的很相似,ticket renew lifetime取决于以下5项设置中的最小值:
- Kerberos server上/var/kerberos/krb5kdc/kdc.conf中max_renewable_life
- 内置principal krbtgt的maximum renewable life,可在kadmin命令行下用getprinc命令查看
- 你的principal的maximum renewable life,可在kadmin命令行下用getprinc命令查看
- Kerberos client上/etc/krb5.conf的renew_lifetime
- kinit -r 参数后面指定的时间
HBase与ticket lifetime
HBase需要长时间运行,它对ticket过期问题的处理见org.apache.hadoop.hbase.ipc.RpcClient,方法handleSaslConnectionFailure(),方法注释中提到HBase是尝试自动relogin,从代码上看应该是直接获取一个新的ticket,而不是进行renew。
The other problem is to do with ticket expiry. To handle that, a relogin is attempted.
The retry logic is governed by the shouldAuthenticateOverKrb method. In case when the user doesn't have valid credentials, we don't need to retry (from cache or ticket). In such cases, it is prudent to throw a runtime exception when we receive a SaslException from the underlying authentication implementation, so there is no retry from other high level (for eg, HCM or HBaseAdmin).
另外:
[org.apache.hadoop.security.UserGroupInformation] Not attempting to re-login since the last re-login was attempted less than 600 seconds before.
这个错误实际是由于UserGroupInformation中的一个hard code值引起的,MIN_TIME_BEFORE_RELOGIN=10*60*1000L,是hadoop自己做出的限制,即不允许过于频繁地relogin,需要将ticket_lifetime设置为大于10分钟即可。
keytab与ticket lifetime
keytab文件实际只是一个密码文件,显然,修改lifetime相关设置跟密码是没有关系的,不需要去重新生成现有的keytab文件。
一些命令
- kadmin: modprinc -maxrenewlife 11days +allow_renewable {principal}
- kadmin: modprinc -maxlife 6minutes {principal}
- kadmin: getprinc {principal} //retrieve the detail info of principal
- kinit -R //renew current ticket
- kinit {principal} -kt {keytab file} //init a principal via keytab file