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
- kb: clarifications for renewing cloud credentials - Fix "Edit this page" link at the bottom of KB article pages - Clarification for what is supposed to be the first parameter to the supplied scrip... — committed to m-ildefons/harvesterhci.io by m-ildefons 2 years ago
- kb: clarifications for renewing cloud credentials (#69) - Fix "Edit this page" link at the bottom of KB article pages - Clarification for what is supposed to be the first parameter to the suppl... — committed to harvester/harvesterhci.io by m-ildefons 2 years ago
I could manually fix it:
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.
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:
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-minutesin 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:
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.cloudCredentialSecretNamepoints 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/
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
migrateharvestercloudcredentialexpirationin thecattle-systemnamespace of Rancher’slocalcluster and what the content of that config map is.Hi @Mithrandir2k18
This is exactly what the warning is about. There is no need to change another token.
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.
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