gravitational / teleport

The easiest, and most secure way to access and protect all of your infrastructure.
https://goteleport.com
GNU Affero General Public License v3.0
17.33k stars 1.74k forks source link

tsh kube login client_idle_timeout Not Functioning as Expected #46310

Open pnrao1983 opened 1 week ago

pnrao1983 commented 1 week ago

Expected behavior: The client_idle_timeout=30s configuration works as expected for SSH and database (DB) resources, disconnecting clients after the specified idle time. However, this timeout does not work with Kubernetes (kube) resources when using.   Current behavior:  SSH, DB, Desktop, and App resources are getting disconnected after the 30s idle timeout but not with kube sessions: Observed that the session remains active beyond the 30-second idle timeout.

pnrao@pnrao ~ % k get po -A
NAMESPACE     NAME                                      READY   STATUS    RESTARTS      AGE
kube-system   coredns-7db6d8ff4d-bw446                  1/1     Running   0             59d
kube-system   etcd-minikube                             1/1     Running   0             59d
pnrao@pnrao ~ % date
Tue Sep  3 10:11:06 EDT 2024
pnrao@pnrao ~ % date
Tue Sep  3 10:12:03 EDT 2024
pnrao@pnrao ~ % k get po -A
NAMESPACE     NAME                                      READY   STATUS    RESTARTS      AGE
kube-system   coredns-7db6d8ff4d-bw446                  1/1     Running   0             59d
kube-system   etcd-minikube                             1/1     Running   0             59d
pnrao@pnrao ~ %
pnrao@pnrao ~ % kubectl exec -it my-pod -- /bin/bash 

root@my-pod:/# date
Thu Sep  5 15:21:54 UTC 2024
root@my-pod:/# date
Thu Sep  5 15:22:44 UTC 2024
root@my-pod:/# date
Thu Sep  5 15:22:47 UTC 2024
root@my-pod:/# date
Thu Sep  5 15:23:52 UTC 2024

Additional Context: Testing with kubectl exec confirms that the timeout does not apply to Kube resources.   Here is the output for SSH session which work as expected:

root@ip-10-0-139-134 ~]# date
Tue Sep  3 02:13:37 PM UTC 2024
[root@ip-10-0-139-134 ~]# uptime
 14:13:39 up 83 days, 19:16,  3 users,  load average: 0.00, 0.00, 0.00
[root@ip-10-0-139-134 ~]# Client exceeded idle timeout of 30sERROR: wait: remote command exited without exit status or exit signal

The timeout does work correctly for database connections, as shown by the following: sql

mysql> SELECT CURDATE();
ERROR 2013 (HY000): Lost connection to MySQL server during query
The connection was lost due to inactivity, but it reconnected in the same window.

  Bug details:

zmb3 commented 1 week ago

Thank you @pnrao1983 for linking to the other relevant discussions!

tigrato commented 1 week ago

Kubernetes has a special behavior by using SPDY PING frames behind the scenes as a keep-alive mechanism. For connection monitoring, this activity ensures the connection remains active and is never terminated.

The PING frames are sent every 10s, so the connection is marked as active and never terminated.