rancher: [BUG] Rancher can no longer provision harvester machines after restart

Rancher Server Setup

  • Rancher version: v2.8.0
  • Installation option (Docker install/Helm Chart): as a helm chart on a single-node k3s cluster
  • Proxy/Cert Details:

Information about the Cluster

  • Infrastructure Provider = Harvester

User Information

  • What is the role of the user logged in? (Admin/Cluster Owner/Cluster Member/Project Owner/Project Member/Custom)
    • Admin

Describe the bug

After one of my harvester nodes was unexpected rebooted, rancher is no longer able to provision machines in the upstream harvester HCI infrastructure.

Trying to scale up an existing managed RKE2 cluster from rancher gets the following error:

 machine Downloading driver from https://192.168.20.10/assets/docker-machine-driver-harvester
 machine Doing /etc/rancher/ssl
 machine docker-machine-driver-harvester
 machine docker-machine-driver-harvester: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, stripped
 machine Trying to access option  which does not exist
 machine THIS ***WILL*** CAUSE UNEXPECTED BEHAVIOR
 machine Type assertion did not go smoothly to string for key
 machine Running pre-create checks...
 machine Error with pre-create check: "the server has asked for the client to provide credentials (get settings.harvesterhci.io server-version)"
 machine The default lines below are for a sh/bash shell, you can specify the shell you're using, with the --shell flag.

And creating a brand new cluster has a different error:

 machine Downloading driver from https://192.168.20.10/assets/docker-machine-driver-harvester
 machine Doing /etc/rancher/ssl
 machine docker-machine-driver-harvester
 machine docker-machine-driver-harvester: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, stripped
 machine error loading host testing-pool1-31b05da3-dlchl: Docker machine "testing-pool1-31b05da3-dlchl" does not exist. Use "docker-machine ls" to list machines. Use "docker-machine create" to add a new one.

Looks like the connection between Rancher and Harvester is broken?

SURE-8423 SURE-8516

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 54 (16 by maintainers)

Commits related to this issue

Most upvoted comments

I could manually fix it:

  1. go to the harvester embedded rancher and get the kube config
  2. update the kubeconfig in the harvester credential in the cattle-global-data namespace in the local cluster (running rancher). they are probably name hv-cred<n>

Hi @sarahhenkens ,

thanks for drawing attention to https://github.com/rancher/rancher/issues/45449, this issue looks to me like it’s the same as this one.

its unclear where we should do this. Is this in the rancher instance from Harvester itself?

No, this is supposed to be done in the Rancher Manager instance that is used to manage the downstream clusters. It may be hosted on the Harvester cluster itself using a VM or the vcluster plugin, but it can also be completely separate from the Harvester cluster.

Let me draw a diagram to give you a clearer picture:

           ┌────────────────────────────────────────────────────────────────────────┐
           │Harvester Cluster                                                       │
           │                                                                        │
           │                  ┌─────────────────────────────────────────────────────┤
┌─────────►│                  │Workloads                                            │
│access to │                  │                                                     │
│  ┌──────►│                  │                                                     │
│  │       │                  │                                                     │
│  │       │                  │                                                     │
│  │       │                  │                                                     │
│  │       │                  │ ┌───────────────┐ ┌───────────────┐ ┌───────────────┤
│  │       │                  │ │Guest Cluster 1│ │Guest Cluster 2│ │Guest Cluster 3│
│  │       │                  │ │               │ │               │ │               │
│  │       ├────────────────┐ │ │               │ │               │ │               │
│  │       │Integrated      │ │ │               │ │               │ │               │
│  │       │Rancher         │ │ │               │ │               │ │               │
│  │       │                │ │ │               │ │               │ │               │
│  │       │                │ │ │               │ │               │ │               │
│  │       │                │ │ │               │ │               │ │               │
│  │       │                │ │ │               │ │               │ │               │
│  │       │                │ │ │               │ │               │ │               │
│  │       │                │ │ │               │ │               │ │               │
│  │       │                │ │ │      ▲        │ │      ▲        │ │       ▲       │
│  │       │                │ │ │      │        │ │      │        │ │       │       │
│  │       └────────────────┴─┴─┴──────┼────────┴─┴──────┼────────┴─┴───────┼───────┘
│  │                                   │                 │                  │        
│  │                                   │                 │                  │        
│  │                                   └─────────────────┤                  │        
│  │                                                     │                  │        
│  │       ┌─────────────────────────────────────────┐   │                  │        
│  │       │Rancher Manager (MCM)                    │   │                  │        
│  │       │                                         │   │                  │        
│  │       │ ┌──────────────────────┐ (used for)     │   │                  │        
│  └───────┼─┤Cloud Creds 1         ├────────────────┼───┘                  │        
│          │ ├──────────────────────┤                │                      │        
│          │ │Token 1               │                │                      │        
│          │ └──────────────────────┘                │                      │        
│          │                                         │                      │        
│          │ ┌──────────────────────┐                │  (used for)          │        
└──────────┼─┤Cloud Creds 2         ├────────────────┼──────────────────────┘        
           │ ├──────────────────────┤                │                               
           │ │Token 2               │                │                               
           │ └──────────────────────┘                │                               
           │                                         │                               
           └─────────────────────────────────────────┘                               

You haven’t provided exact details of your environment, but I assume it looks similar to the above.

For your Harvester cluster, you’ll have one or more cloud credentials in your Rancher Manager (MCM) instance. Each of the Cloud Credential objects is associated with a token, provides access to the Harvester cluster and may be used for managing one or more downstream clusters. If the token expires, the Rancher Manager instance loses its ability to use that Cloud Credential object to authenticate actions for managing the associated downstream cluster’s VMs. Any scaling or management operation that interacts with the VMs of that downstream cluster will fail from then on, until the token is replaced for the Cloud Credential object.

By default the tokens of the Cloud Credentials expire 30 days after the Cloud Credential object has been created, which is why your downstream clusters become fragile after 30 days. You can change the default values for the expiration using the setting kubeconfig-default-token-ttl-minutes in the settings of the Rancher Manager (MCM) instance, but keep the security implications in mind. To avoid weakening security, the tokens have to be rotated on a regular basis. The KB article describes how to do that. The workaround can also be applied to recover downstream clusters that are already affected by expired tokens.

There is indeed an integrated Rancher instance in Harvester, but that shouldn’t be the one used to manage downstream clusters.

I hope this clears up the picture.

I was able to replicate the issue by setting the token expiry to 10 minutes as shared by @m-ildefons. The Rancher deployed is v2.8.3, and the Harvester version is v1.2.1. I noticed that when the token associated with the downstream cluster expires, the connection between Rancher and Harvester is disrupted. Well, this token expiry value is set to 30 days by default, as documented here. This change has been introduced in Rancher 2.8, as mentioned in this PR.

I guess this issue has not been observed in earlier versions of Rancher, as the token value was set to infinite, as documented here. It appears that it has been implemented for security reasons, performance enhancements, and to manage too many unexpired tokens.

I’ve managed to reproduce the issue in a test environment:

  1. Install Harvester (tested with v1.2.1, likely irrelevant)
  2. Install Rancher (tested with v2.8.2, testing with other versions TBD)
  3. Import Harvester cluster
  4. Upload a suitable cloud image and create a VM network, so VMs can be created
  5. To shorten the time to reproduce, set the default token TTL in Rancher to e.g. 10 minutes. This is a global config setting in Rancher.
  6. Create a Cloud Credential for the Harvester cluster
  7. Create a K8s cluster with the Harvester cluster as infrastructure provider, using the previously created Cloud Credential for authentication
  8. Wait until the default token TTL is over. The token associated with the Cloud Credentials will be expired and eventually removed, but the Cloud Credential will remain. This will not cause an error just yet though.
  9. Scale the K8s cluster from step 8 up or down. This operation will fail with behavior and errors similar to the reported problem.

I’m not sure if and how OIDC interacts here, since it wasn’t in my test environment. Since the original bug report does not include any mention of an external identity provider and it makes my test environment simpler, I’ll focus on locally provided users.

~As a workaround, I suggest to create Cloud Credentials associated with a token without an expiration date. To do that, set the maximum token TTL and the default token TTL settings (both global settings in Rancher) both to 0. Then create the Cloud Credentials to be used to create a K8s cluster on Harvester. Then create a K8s cluster using these Cloud Credentials.~

~To recover an existing cluster, adjust the maximum token TTL and default token TTL to 0, create a new Cloud Credential for the Harvester cluster and edit the Yaml for the cluster, such that .spec.cloudCredentialSecretName points to the new Cloud Credentials. The K8s cluster will eventually recover and any outstanding scaling operation will be completed. The old Cloud Credentials can be disposed of afterwards.~

Edit: Please follow the instructions in our knowledge base to recover: https://harvesterhci.io/kb/renew_harvester_cloud_credentials/

Sorry, replying a bit late, was out for SUSEcon. I’ve confirmed that the 2.9.6 actions menu unfortunately does not show the renewal option without adding the annotation in my last comment

No problem, hope you enjoyed it.

Unfortunately, I can’t reproduce this in my local test environment. Please file a separate bug, so we can investigate without derailing the conversation here. Particularly interesting here would be which versions of Rancher you’ve been using for that instance in the past, i.e. what the upgrade path was. Also interesting would be if there is a config map named migrateharvestercloudcredentialexpiration in the cattle-system namespace of Rancher’s local cluster and what the content of that config map is.

Hi @Mithrandir2k18

  1. Is this warning just a general warning about cloud credentials needing renewal every 30 days which is fixed by pressing the renewal button? Or do I need to change another token? I am assuming hitting renew, renews the token this warning mentions.

This is exactly what the warning is about. There is no need to change another token.

  1. Is there a way to tell rancher to automatically renew the harvester cloud credentials? Doing it manually every 30 days seems kind of needlessly arduous and error prone.

At the moment, no. But we are currently working on fixing this, so you don’t have to manually renew the cloud credentials.

There are two settings which you can use to tune this: The auth-token-max-ttl-minutes and the kubeconfig-default-token-ttl-minutes. If you increase these settings, you can stretch the interval in which you need to renew the cloud credentials. But be warned, this has security implications.

Now i have this error:

	Failed deleting server [fleet-default/rke2-rc-control-plane-3fba9236-dxptf] of kind (HarvesterMachine) for machine rke2-rc-control-plane-77f9455c9dx9xgsk-4kcwf in infrastructure provider: DeleteError: Downloading driver from https://HOST/assets/docker-machine-driver-harvester Doing /etc/rancher/ssl docker-machine-driver-harvester docker-machine-driver-harvester: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, stripped About to remove rke2-rc-control-plane-3fba9236-dxptf WARNING: This action will delete both local reference and remote instance. Error removing host "rke2-rc-control-plane-3fba9236-dxptf": the server has asked for the client to provide credentials (get virtualmachines.kubevirt.io rke2-rc-control-plane-3fba9236-dxptf)

As mentioned here. The work around does allow the guest cluster to create new VMs, but it seems to fail to delete previously made VMs using the previous credentials.

For example, changing the worker machine spec. The work around will allow new machines to be provisioned, but rancher will hang on deleting the old servers.

Is there a work around for this?

I wonder if this bug is related https://github.com/rancher/rancher/issues/45449

My downstream clusters always become really unstable after 30 days and generally just break. Forcing me to restore the entire cluster from backups. Rebooting or touching any control plane nodes is always a gamble whether it will recover or not

When reading the original issue https://github.com/rancher/rancher/issues/41919 which introduces the default TTL value (30 minutes for kubeconf) to securely manage tokens for users (or headless users for programming purposes).

However, Harvester cloud credentials, which are used for authenticating and authorizing the Rancher cluster to manage downstream Harvester clusters, should not use the unified TTL applied in this case, as the token is not for users but an internal mechanism instead.

cc @ibrokethecloud @bk201 @Vicente-Cheng @m-ildefons