work
experiment
Initialize TGT.
βββ[user@example ~]$ kinit principal@EXAMPLE.COM
βββPassword for principal@EXAMPLE.COM:
βββ[user@example ~]$ klist
βββTicket cache: KCM:1000
βββDefault principal: principal@EXAMPLE.COM
ββ
βββValid starting Expires Service principal
βββ02/04/23 10:03:06 02/04/23 20:03:06 krbtgt/EXAMPLE.COM@EXAMPLE.COM
βββ renew until 02/11/23 10:03:02
This TGT:
Renew TGT
βββ[user@example ~]$ kinit -R principal@EXAMPLE.COM
βββ[user@example ~]$ klist
βββTicket cache: KCM:1000
βββDefault principal: principal@EXAMPLE.COM
βββValid starting Expires Service principal
βββ02/04/23 10:03:22 02/04/23 20:03:22 krbtgt/EXAMPLE.COM@EXAMPLE.COM
βββ renew until 02/11/23 10:03:02
After renewing:
Ans: No.
userName
and password
are provided in the JDBC connection string, what will happen if the TGT expires?Connection string:
jdbc:sqlserver://{SQL_SERVER_HOST}:1433;
database={DB_NAME};
encrypt=true;
trustServerCertificate=true;
integratedSecurity=true;
authenticationScheme=JavaKerberos;
userName={KERBEROS_PRINCIPAL};
password={PASSWORD};
Run an application which uses connection pool for DB connection, and check if there're 10 acitve connections by running (ref)
SELECT * FROM sys.dm_exec_connections;
Refer to this document, the default ticket lifetime is 10 hours on many systems.
Therefore, leave it until next day.
Check it again.
The connect_time
changed! The interval is about 16 hours.
And again, next day.
The interval is about 24 hours.
Therefore, by the result of the experiment, I guess the driver will renew the TGT about every 8 hours.
But what will happen if the renew lifetime expires?
The default renew lifetime is 7 days, which is too long for an experiment. Modify the maximum lifetime of the ticket granted by the KDC.
Refer to this document, the Kerberos policy is at Group Policy Management Editor, Default Domain Policy > Computer Configuration > Policies > Windows Settings > Security Settings > Account Policies > Kerberos Settings.
Set these lifetime to the minimum value.
Policy | Policy Setting |
---|---|
Maximum lifetime for service ticket | 10 minutes |
Maximum lifetime for user ticket | 1 hours |
Maximum lifetime for user ticket renewal | 1 days |
Initialize a TGT to check the change is effective.
βββ[user@example ~]$ kinit principal@EXAMPLE.COM
βββPassword for principal@EXAMPLE.COM:
βββ[user@example ~]$ klist
βββTicket cache: KCM:1000
βββDefault principal: principal@EXAMPLE.COM
βββValid starting Expires Service principal
βββ02/06/23 17:10:02 02/06/23 18:10:02 krbtgt/EXAMPLE.COM@EXAMPLE.COM
βββ renew until 02/07/23 17:10:02
Checked!
Run the same application as the previous experiment, and check if the connections exist.
Wait 1 hour and 1 day.
at tomorrow 8:48 AM.
at tomorrow 05:17 PM (more than 1 day after).
The connections are still there.
userName
and password
aren't provided in the JDBC connection string, what will happen if the TGT expires?The settings of this experiment is the same as experiment 1, except that the connection string doesn't have userName
and password
:
ββββjdbc:sqlserver://{SQL_SERVER_HOST}:1433;
ββββ database={DB_NAME};
ββββ encrypt=true;
ββββ trustServerCertificate=true;
ββββ integratedSecurity=true;
ββββ authenticationScheme=JavaKerberos;
Run kinit
manually (shorten lifetime to 1 minute), and run klist
to check the TGT.
ββββ[user@example ~]$ kinit -l 2m principal@EXAMPLE.COM
ββββ Password for principal@EXAMPLE.COM:
ββββ [user@example ~]$ klist
ββββ Ticket cache: KCM:1000
ββββ Default principal: principal@EXAMPLE.COM
ββββ Valid starting Expires Service principal
ββββ 02/07/23 10:15:08 02/07/23 10:17:56 krbtgt/EXAMPLE.COM@EXAMPLE.COM
ββββ renew until 02/08/23 10:15:08
Run the same application, check if the connections exist.
Wait 2 minutes.
At 10:28:14, still aren't renewed. Wait until the default TGT lifetime expired (11:15:08, 1 hour after).
After 1 hour, the connection is no longer available.
And the application also throws some exceptions.
Ans: After TGT expired, the connection is no longer available.
principal
with TGT.principal
.kinit -R
. Check if it's passed.userName
and password
.Check if the modification of passowrd will affect the TGT renewal.
principal
with TGT.
ββββ[user@example ~]$ kinit principal@EXAMPLE.COM
ββββPassword for principal@EXAMPLE.COM:
ββββ[user@example ~]$ klist
ββββTicket cache: KCM:1000:875
ββββDefault principal: principal@EXAMPLE.COM
ββββValid starting Expires Service principal
ββββ02/07/23 17:06:40 02/07/23 18:06:40 krbtgt/OA.TEST.COM@OA.TEST.COM
ββββ renew until 02/08/23 17:06:40
principal
.kinit -R
. Check if it's passed.
ββββ[user@example ~]$ kinit -R principal@EXAMPLE.COM
ββββ[user@example ~]$ klist
ββββTicket cache: KCM:1000:875
ββββDefault principal: principal@EXAMPLE.COM
ββββValid starting Expires Service principal
ββββ02/07/23 17:07:25 02/07/23 18:07:25 krbtgt/OA.TEST.COM@OA.TEST.COM
ββββ renew until 02/08/23 17:06:40
ββββ[user@example ~]$ kinit principal@EXAMPLE.COM
ββββPassword for principal@EXAMPLE.COM:
ββββkinit: Password incorrect while getting initial credentials
Conclusion: The modification of passowrd won't affect the TGT renewal.
Therefore, what JDBC driver for SQL server does for the TGT lifetime is to get a new TGT whenever the TGT is about to expire.