Manage User Permissions

This document describes how to manage user permissions in Chaos Mesh, including creating user accounts with different roles, binding permissions to user accounts, managing tokens, and enabling or disabling permission authentication.

Chaos Mesh uses RBAC Authorization to manage user permissions. To create, view and manage chaos experiments, users must have the appropriate permissions in the apiGroups of chaos-mesh.org to refer the resources of chaos experiments.

Manage User Permissions - 图1caution

Chaos Mesh allows you to disable permission authentication, see Enable or disable permission authentication to learn how to disable it.

Note that we do not recommend disabling permission authentication in production environments.

Create user accounts and bind permissions

You can use the Chaos Dashboard to help you create user accounts and bind permissions. When you access the dashboard, a login window will appear. Click on the Click here to generate link:

Dashboard Token Login 1

When you click on the link, a Token Generator will appear, as follows:

Dashboard Token Generator

The steps to create user accounts and bind permissions are as follows:

Choose the scope of permissions

If you want to give the account the appropriate permissions for all chaos experiments in the cluster, tick the Cluster scoped checkbox. If you specify a namespace in the Namespace dropdown, the account will only have permissions in the specified namespace.

In summary, there are two options to choose from:

  • Cluster scoped: the account has permissions for all chaos experiments in cluster.
  • Namespace scoped: the account has permissions for all chaos experiments in the specified namespace.

Select the role of users

Currently, Chaos Mesh provides the following user roles

  • Manager: who has all permissions to create, view, update and delete chaos experiments.
  • Viewer: who only has the right to view chaos experiments.

Generate the permission

Once the permission scope and user role have been defined, the Dashboard will display the corresponding RBAC configuration in the Token Generator. For example, the permission for a manager with the default namespace will look like this:

  1. kind: ServiceAccount
  2. apiVersion: v1
  3. metadata:
  4. namespace: default
  5. name: account-default-manager-vfmot
  6. ---
  7. kind: Role
  8. apiVersion: rbac.authorization.k8s.io/v1
  9. metadata:
  10. namespace: default
  11. name: role-default-manager-vfmot
  12. rules:
  13. - apiGroups: ['']
  14. resources: ['pods', 'namespaces']
  15. verbs: ['get', 'watch', 'list']
  16. - apiGroups:
  17. - chaos-mesh.org
  18. resources: ['*']
  19. verbs: ['get', 'list', 'watch', 'create', 'delete', 'patch', 'update']
  20. ---
  21. apiVersion: rbac.authorization.k8s.io/v1
  22. kind: RoleBinding
  23. metadata:
  24. name: bind-default-manager-vfmot
  25. namespace: default
  26. subjects:
  27. - kind: ServiceAccount
  28. name: account-default-manager-vfmot
  29. namespace: default
  30. roleRef:
  31. kind: Role
  32. name: role-default-manager-vfmot
  33. apiGroup: rbac.authorization.k8s.io

Click COPY in the top right corner of the configuration section to copy the RBAC configuration and then save the contents locally as rbac.yaml.

Create the user account and bind permissions

Run the following command in your terminal:

  1. kubectl apply -f rbac.yaml

Manage User Permissions - 图4note

You need to ensure that the local user running kubectl has permissions to the cluster so that they can create user accounts, bind permissions for other users and generate tokens.

Get the token

Manage User Permissions - 图5info

Versions of Kubernetes before v1.22 automatically created long term credentials for accessing the Kubernetes API. In recent versions of Kubernetes, you must manually create a service account token Secret.

For more details, see Manually create an API token for a ServiceAccount.

Copy the command shown in the third step to the Token Generator and run it in your terminal. The following is a sample command:

  1. kubectl describe -n default secrets account-default-manager-vfmot

The output is as follows:

  1. Name: account-default-manager-vfmot-token-n4tg8
  2. Namespace: default
  3. Labels: <none>
  4. Annotations: kubernetes.io/service-account.name: account-default-manager-vfmot
  5. kubernetes.io/service-account.uid: b71b3bf4-cd5e-4efb-8bf6-ff9a55fd7e07
  6. Type: kubernetes.io/service-account-token
  7. Data
  8. ====
  9. ca.crt: 1111 bytes
  10. namespace: 7 bytes
  11. token: eyJhbG...

Copy the token at the bottom and use it in the next step to login.

Log in to Chaos Dashboard with the user account you have created

Close the Token Generator. In the Token field, enter the token you obtained in the previous step and in the Name field, enter a meaningful name for the token. It is recommended that you use a name that is a combination of the permission scope and the user role, e.g. default-manager. Once you have completed these two fields, click Submit to log in:

Dashboard Token Login 2

Manage User Permissions - 图7info

If you have not deployed Chaos Dashboard, you can also generate RBAC configurations by yourself and then use kubectl to create user accounts and bind permissions.

Log out of Chaos Dashboard

If you need to replace the token with another one, click the Settings on the left side bar of the Dashboard:

Dashboard Token Logout

At the top of the page you will see the Logout button. Click it to log out the current account.

FAQ

Enable or disable permission authentication

When Chaos Mesh is installed using Helm, Permission Authentication is enabled by default. For production environments and other high security scenarios, it is recommended to leave permission authentication enabled. If you are just trying out Chaos Mesh and want to quickly create chaos experiments, you can set --set dashboard.securityMode=false in a Helm command to disable authentication. The command looks like this:

If you want to enable the permission authentication again, then reset --set dashboard.securityMode=true in a Helm command.