Clear KubeConfig
Container Compute Service (ACS) issues kubeconfig credentials that carry the identity information of different Alibaba Cloud accounts, RAM users, or RAM roles, for connecting to clusters. An Alibaba Cloud account, RAM user, or RAM role can use the kubeconfig management feature to get the status of all issued kubeconfig from the cluster dimension or the user dimension. It can also clean up and revoke the authorization of some kubeconfig that pose security risks.
Make sure that no risk exists before you clear the kubeconfig. Otherwise, you will not be able to use this kubeconfig to access the cluster API Server.
According to Shared responsibility model, you are responsible for the kubeconfig credentials and must maintain them. Be sure to promptly clear any kubeconfig that poses a security risk.
kubeconfig overview
kubeconfig is used to configure the access credentials of a cluster on a client. You can get it in several ways, such as through the ACS console or the API operation Query the kubeconfig file of a cluster. Properly manage the kubeconfig credentials of your clusters to avoid security risks such as data leaks caused by a leaked kubeconfig.
An obtained kubeconfig has a specific effective time and automatically becomes invalid after it expires. To query the validity period of a kubeconfig, see How do I obtain the expiration time of the certificate used by KubeConfig?
kubeconfig status
The kubeconfig of Container Compute Service (ACS) has the following four statuses.
kubeconfig Status | Description |
Not issued | No kubeconfig of this cluster has ever been issued to the current RAM user or RAM role. |
Valid | The cluster kubeconfig of the current RAM user or RAM role exists and has not expired. |
The cluster kubeconfig of the current RAM user or RAM role has been cleared, but residual RBAC permissions still exist. | |
Expired | The cluster kubeconfig of the current RAM user or RAM role exists but has expired. |
Cleared | A cluster kubeconfig was previously issued to the current RAM user or RAM role, but the kubeconfig has now been cleared. Clearing the kubeconfig deletes the kubeconfig information of the cluster and the RBAC Binding of that RAM user or RAM role. |
To clear a kubeconfig that is currently valid, carefully verify that the credential was issued appropriately and is still legitimately needed. For example, clear the kubeconfig held by former employees one by one so that KubeConfigs in legitimate use do not expire.
kubeconfig management
Management dimension | Scenarios | Required permissions | Usage examples |
Cluster dimension | Manage the kubeconfig of all users in the target cluster. |
| |
RAM user or RAM role dimension | Manage the cluster kubeconfig owned by a specified user. |
| Example of RAM user or RAM role dimension kubeconfig management |
Invalidated RAM user or RAM role dimension | The account contains deleted RAM users or RAM roles whose kubeconfig is still valid. |
|
Example of cluster-dimension kubeconfig management
Log on to the ACS console and choose Authorizations in the left-side navigation pane.
On the Authorizations page, click the KubeConfig File Management tab, and then click KubeConfig File Management on the right of the target cluster to go to the KubeConfig File Management page.
On this page, you can view the list of users who hold a KubeConfig of this cluster, or whose KubeConfig was previously cleared but still has residual RBAC authorization. The list contains two parts: user information and kubeconfig certificate information:
User information: the username, user ID, account type, and account status.
kubeconfig certificate information: the kubeconfig expiration time, kubeconfig status, and other details.
Confirm that no business application depends on the kubeconfig of the user to be cleared. In the Actions column on the right of the target user, click Delete KubeConfig File to clear the kubeconfig of the target user in this cluster.
When you click Delete KubeConfig File, the system checks the access records of the kubeconfig to be deleted in the API Server audit log of the specified cluster over the past seven days. This auxiliary check requires that the cluster has the API Server audit feature enabled.
Example of RAM user or RAM role dimension kubeconfig management
Log on to the ACS console and choose Authorizations in the left-side navigation pane.
On the Authorizations page, click the RAM Users tab, and then click Manage KubeConfig on the right of the target user to go to that user's KubeConfig Management page.
On this page, you can view the list of issuance statuses of this user's kubeconfig for each cluster. The list contains two parts: cluster information and kubeconfig certificate information:
Cluster information: the cluster name and cluster ID.
kubeconfig certificate information: the kubeconfig expiration time and status, and the seven-day log check (that is, the certificate access records).
Clear the kubeconfig of the clusters for this user, individually or in bulk. Before you clear them, confirm that no business application depends on the kubeconfig of the user to be cleared.
Clear individually: In the Actions column on the right of the target cluster, click Delete KubeConfig File to clear the kubeconfig of the current user in that cluster.
Clear in bulk: In the cluster name column, select multiple clusters to be cleared, and then click Delete KubeConfig File in the lower-left corner of the page.
NoteWhen you click Delete KubeConfig File, the system checks the access records of the kubeconfig to be deleted in the API Server audit log of the specified cluster over the past seven days. This auxiliary check requires that the cluster has the API Server audit feature enabled.
Example of clearing the kubeconfig of invalid users
Clear them in the Container Service console
Log on to the ACS console and choose Authorizations in the left-side navigation pane.
On the Authorizations page, if your account has residual kubeconfig of deleted invalid users, the page displays the following prompt.

In the red prompt box, click manage the kubeconfig files associated with invalid accounts to go to the Delete KubeConfig Files of Deleted RAM Users/Roles page.
This page lists the deleted RAM users or RAM roles whose KubeConfig and RBAC authorization are still valid.
Confirm that no business application depends on the kubeconfig of the user to be cleared. Click Delete KubeConfig File on the right of the invalid user to clear the kubeconfig of that invalid user.
When you click Delete KubeConfig File, the system checks the access records of the kubeconfig to be deleted in the API Server audit log of the specified cluster over the past seven days. This auxiliary check requires that the cluster has the API Server audit feature enabled.
kubeconfig usage FAQ
When you clear a kubeconfig, what is the seven-day log check?
The seven-day log check is an auxiliary method used to find out whether the kubeconfig has accessed this cluster in the last seven days. The prerequisite is that the cluster Use the cluster API server auditing feature. This check has limitations and is for reference only. You must still verify for yourself that no business application depends on the kubeconfig.
How do I interpret the results of the seven-day log check?
Check result | Result type | Possible cause |
Succeeded | No access records found | The user may not have used this kubeconfig to access the cluster API Server in the last seven days. |
Access records exist | The user has used this kubeconfig to access the cluster API Server in the last seven days. | |
Failed | Access records cannot be queried | Log auditing is not enabled for the cluster, so the check cannot run automatically. |
Other error causes, such as a cluster connection failure or network issues. |
When can you not clear a kubeconfig?
Abnormal cluster status: Deletion failed, Deleting, Deleted, and Failed — you cannot clear the kubeconfig for a cluster in any of these four statuses.
kubeconfig or certificate status is abnormal: users whose cluster kubeconfig is in the Not issued, Cleared, or Unknown status cannot clear the kubeconfig.
A user cannot clear their own kubeconfig.
A user cannot clear the kubeconfig of the Alibaba Cloud account.
kubeconfig management: What are the best security practices?
You must manage the access credentials of your account and Container Service clusters yourself and keep them secure, such as RAM AKs, tokens, and Container Service cluster kubeconfig clients. When you manage the authorization scope of your account and Container Service clusters yourself, follow the principle of least privilege and promptly update and clear inappropriate or invalid authorizations. For example, former employees should no longer hold access permissions to Container Service clusters.
According to Shared responsibility model, you are responsible for the kubeconfig credentials and must maintain them. Carefully maintain the appropriateness and validity of the credentials to avoid the security risks caused by a leaked kubeconfig.
References
When an employee leaves your enterprise or an issued kubeconfig is suspected of being leaked, you can revoke the kubeconfig of the cluster and generate a new kubeconfig. For instructions, see Revoke a cluster kubeconfig file.