rancher: [BUG] Stale secrets for impersonation user in downstream cluster

Rancher Server Setup

  • Rancher version: 2.7.9, 2.8.2

Information about the Cluster

  • Kubernetes version: v1.26.11+rke2r1
  • Cluster Type (Local/Downstream): Downstream, created from Rancher on EC2

User Information

  • What is the role of the user logged in? Admin

Describe the bug

  • Multiple stale Secrets created for a single impersonation user/ServiceAccount in the downstream cluster
  • SA shows 1 secret and single reference but multiple secrets with same SA reference found
  • The stale secrets don’t get reconciled even if we delete the current referenced secret in the ServiceAccount
> k get secrets -n cattle-impersonation-system
NAME                                            TYPE                                  DATA   AGE
cattle-impersonation-u-hjxlz-token-24kwk        kubernetes.io/service-account-token   3      22h
cattle-impersonation-u-l767yhswxf-token-lnzc2   kubernetes.io/service-account-token   3      3d23h
cattle-impersonation-u-l767yhswxf-token-rdlkx   kubernetes.io/service-account-token   3      4d22h
cattle-impersonation-u-l767yhswxf-token-w5klt   kubernetes.io/service-account-token   3      3d23h
cattle-impersonation-u-oxfisb4qb2-token-gtjln   kubernetes.io/service-account-token   3      4d23h
cattle-impersonation-user-ptj5z-token-gzjnc     kubernetes.io/service-account-token   3      4d23h
> k get sa -n cattle-impersonation-system -o wide
NAME                                SECRETS   AGE
cattle-impersonation-u-hjxlz        1         22h
cattle-impersonation-u-l767yhswxf   1         4d22h
cattle-impersonation-u-oxfisb4qb2   1         4d23h
cattle-impersonation-user-ptj5z     1         4d23h
default                             0         4d23h
> k get secrets -A -o yaml | grep 'cattle-impersonation-u-l767yhswxf'
      kubernetes.io/service-account.name: cattle-impersonation-u-l767yhswxf
    generateName: cattle-impersonation-u-l767yhswxf-token-
    name: cattle-impersonation-u-l767yhswxf-token-lnzc2
      name: cattle-impersonation-u-l767yhswxf
      kubernetes.io/service-account.name: cattle-impersonation-u-l767yhswxf
    generateName: cattle-impersonation-u-l767yhswxf-token-
    name: cattle-impersonation-u-l767yhswxf-token-rdlkx
      name: cattle-impersonation-u-l767yhswxf
      kubernetes.io/service-account.name: cattle-impersonation-u-l767yhswxf
    generateName: cattle-impersonation-u-l767yhswxf-token-
    name: cattle-impersonation-u-l767yhswxf-token-w5klt
      name: cattle-impersonation-u-l767yhswxf

A snippet from the Rancher pod log shows that the multiple creation happens usually quickly after each other, hinting at lack of concurency while the Ensure func is called for the same ServiceAccount

2024/02/13 11:29:43 [INFO] EnsureSecretForServiceAccount: waiting for secret [cattle-impersonation-user-kgnqk-token-cd6fl] to be populated with token
2024/02/13 11:29:43 [INFO] EnsureSecretForServiceAccount: waiting for secret [cattle-impersonation-user-kgnqk-token-v7r6z] to be populated with token
2024/02/13 11:29:44 [INFO] EnsureSecretForServiceAccount: waiting for secret [cattle-impersonation-user-kgnqk-token-sg9sb] to be populated with token
2024/02/13 11:29:44 [INFO] Creating roleBinding User user-kgnqk Role admin in cattle-system
2024/02/13 11:29:44 [INFO] Updating clusterRole project-owner-promoted for project access to global resource.
2024/02/13 11:29:44 [INFO] [mgmt-auth-crtb-controller] Creating roleBinding for subject u-xpeyhn3op3 with role cluster-owner in namespace p-g8bfg
2024/02/13 11:29:44 [INFO] Creating roleBinding User user-kgnqk Role project-owner in default
2024/02/13 11:29:44 [INFO] [mgmt-auth-crtb-controller] Creating roleBinding for subject u-xpeyhn3op3 with role cluster-owner in namespace p-s2mp7
2024/02/13 11:29:44 [INFO] Creating roleBinding User user-kgnqk Role admin in kube-system

To Reproduce

This seems random at this point, on a Rancher with a downstream cluster, this can be seen out of the box in the downstream cluster. A customer has seen this for a custom user, in my reproducer this is happening for a fleet user. There’s a time difference between the stale secrets creation, so this might not occur at the first try

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 3
  • Comments: 18 (5 by maintainers)

Most upvoted comments

We may have experienced this on 2.8.3 to the point that one of our clusters fully failed. We found over 37,000 impersonation secrets for the same account. Whenever we would start the cluster agent, our cp nodes would all fill up memory in the api-server and etcd and start OOMKilling critical processes.

All of these tokens were created for a single service account for a pod (Portworx) running in the cluster. Once we terminated that pod, Rancher stopped creating impersonation tokens.