kubernetes: Kubelet stops rotating service account tokens when pod is terminating, breaking preStop hooks

What happened?

We have pods that use the kube API during their preStop hooks and we use 12h service account token expirations. Today we had a pod where the token was approaching expiration at the time the pod was deleted. 4h into the preStop hook, the token expired and the preStop hook started failing.

What did you expect to happen?

Service account token rotation should continue working until pods have fully terminated.

How can we reproduce it (as minimally and precisely as possible)?

Run a pod with a 10-minute service account token expiration and long terminationGracePeriodSeconds and a preStop hook that does sleep infinity. Exec into the pod after 10 minutes have elapsed and check the token, it will be expired.

Anything else we need to know?

No response

Kubernetes version

Client Version: version.Info{Major:"1", Minor:"23", GitVersion:"v1.23.16", GitCommit:"60e5135f758b6e43d0523b3277e8d34b4ab3801f", GitTreeState:"clean", BuildDate:"2023-01-18T16:01:10Z", GoVersion:"go1.19.5", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"23", GitVersion:"v1.23.16", GitCommit:"60e5135f758b6e43d0523b3277e8d34b4ab3801f", GitTreeState:"archive", BuildDate:"2023-03-01T14:28:40Z", GoVersion:"go1.19.5", Compiler:"gc", Platform:"linux/amd64"}

Cloud provider

AWS, but N/A for this issue

OS version

CentOS 8 stream, but N/A for this issue

Install tools

N/A

Container runtime (CRI) and version (if applicable)

Occurs with both cri-o and cri-dockerd

Related plugins (CNI, CSI, …) and versions (if applicable)

N/A

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 4
  • Comments: 31 (9 by maintainers)

Commits related to this issue

Most upvoted comments

Here’s a workaround we came up with: https://github.com/SumoLogic-Labs/service-account-token-refresher

Basically, taking on the responsibility of refreshing the token in the sidecar since Kubelet fails to do so.

Working

@liggitt I attempted to resolve the problem in #117329 - however, there were some performance concerns noted. I’ve opened a new PR, #122161, that I hope resolves the performance concerns.

Glad to see this is getting some renewed attention. We just ran into this in the context of using a projected service account token to do federated auth/token exchange from AWS to GCP. We have some long-running data processing jobs where we set a long terminationGracePeriod to allow the processing to complete, and were seeing sporadic failures when they attempt to auth to a GCP API. Narrowed it down to the projected token being expired, and this explains why.

Hi @DaGenix! I’m looking on your fix and discussions, around it. That’s great that you didn’t abandoned it, I believe we find a proper way to finish it then, thank you!

This got reported again in https://github.com/kubernetes/kubernetes/issues/122102

is there a plan to resolve the issue with volume plugins not refreshing during graceful termination?