github.com/defensepoint-snyk-test/helm-new@v0.0.0-20211130153739-c57ea64d6603/docs/rbac.md (about)

     1  # Role-based Access Control
     2  
     3  In Kubernetes, granting a role to an application-specific service account is a best practice to ensure that your application is operating in the scope that you have specified. Read more about service account permissions [in the official Kubernetes docs](https://kubernetes.io/docs/admin/authorization/rbac/#service-account-permissions).
     4  
     5  Bitnami also has a fantastic guide for [configuring RBAC in your cluster](https://docs.bitnami.com/kubernetes/how-to/configure-rbac-in-your-kubernetes-cluster/) that takes you through RBAC basics.
     6  
     7  This guide is for users who want to restrict Tiller's capabilities to install resources to certain namespaces, or to grant a Helm client running access to a Tiller instance.
     8  
     9  ## Tiller and Role-based Access Control
    10  
    11  You can add a service account to Tiller using the `--service-account <NAME>` flag while you're configuring Helm. As a prerequisite, you'll have to create a role binding which specifies a [role](https://kubernetes.io/docs/admin/authorization/rbac/#role-and-clusterrole) and a [service account](https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/) name that have been set up in advance.
    12  
    13  Once you have satisfied the pre-requisite and have a service account with the correct permissions, you'll run a command like this: `helm init --service-account <NAME>`
    14  
    15  ### Example: Service account with cluster-admin role
    16  
    17  In `rbac-config.yaml`:
    18  
    19  ```yaml
    20  apiVersion: v1
    21  kind: ServiceAccount
    22  metadata:
    23    name: tiller
    24    namespace: kube-system
    25  ---
    26  apiVersion: rbac.authorization.k8s.io/v1
    27  kind: ClusterRoleBinding
    28  metadata:
    29    name: tiller
    30  roleRef:
    31    apiGroup: rbac.authorization.k8s.io
    32    kind: ClusterRole
    33    name: cluster-admin
    34  subjects:
    35    - kind: ServiceAccount
    36      name: tiller
    37      namespace: kube-system
    38  ```
    39  
    40  _Note: The cluster-admin role is created by default in a Kubernetes cluster, so you don't have to define it explicitly._
    41  
    42  ```console
    43  $ kubectl create -f rbac-config.yaml
    44  serviceaccount "tiller" created
    45  clusterrolebinding "tiller" created
    46  $ helm init --service-account tiller
    47  ```
    48  
    49  ### Example: Deploy Tiller in a namespace, restricted to deploying resources only in that namespace
    50  
    51  In the example above, we gave Tiller admin access to the entire cluster. You are not at all required to give Tiller cluster-admin access for it to work. Instead of specifying a ClusterRole or a ClusterRoleBinding, you can specify a Role and RoleBinding to limit Tiller's scope to a particular namespace.
    52  
    53  ```console
    54  $ kubectl create namespace tiller-world
    55  namespace "tiller-world" created
    56  $ kubectl create serviceaccount tiller --namespace tiller-world
    57  serviceaccount "tiller" created
    58  ```
    59  
    60  Define a Role that allows Tiller to manage all resources in `tiller-world` like in `role-tiller.yaml`:
    61  
    62  ```yaml
    63  kind: Role
    64  apiVersion: rbac.authorization.k8s.io/v1
    65  metadata:
    66    name: tiller-manager
    67    namespace: tiller-world
    68  rules:
    69  - apiGroups: ["", "batch", "extensions", "apps"]
    70    resources: ["*"]
    71    verbs: ["*"]
    72  ```
    73  
    74  ```console
    75  $ kubectl create -f role-tiller.yaml
    76  role "tiller-manager" created
    77  ```
    78  
    79  In `rolebinding-tiller.yaml`,
    80  
    81  ```yaml
    82  kind: RoleBinding
    83  apiVersion: rbac.authorization.k8s.io/v1
    84  metadata:
    85    name: tiller-binding
    86    namespace: tiller-world
    87  subjects:
    88  - kind: ServiceAccount
    89    name: tiller
    90    namespace: tiller-world
    91  roleRef:
    92    kind: Role
    93    name: tiller-manager
    94    apiGroup: rbac.authorization.k8s.io
    95  ```
    96  
    97  ```console
    98  $ kubectl create -f rolebinding-tiller.yaml
    99  rolebinding "tiller-binding" created
   100  ```
   101  
   102  Afterwards you can run `helm init` to install Tiller in the `tiller-world` namespace.
   103  
   104  ```console
   105  $ helm init --service-account tiller --tiller-namespace tiller-world
   106  $HELM_HOME has been configured at /Users/awesome-user/.helm.
   107  
   108  Tiller (the Helm server side component) has been installed into your Kubernetes Cluster.
   109  Happy Helming!
   110  
   111  $ helm install nginx --tiller-namespace tiller-world --namespace tiller-world
   112  NAME:   wayfaring-yak
   113  LAST DEPLOYED: Mon Aug  7 16:00:16 2017
   114  NAMESPACE: tiller-world
   115  STATUS: DEPLOYED
   116  
   117  RESOURCES:
   118  ==> v1/Pod
   119  NAME                  READY  STATUS             RESTARTS  AGE
   120  wayfaring-yak-alpine  0/1    ContainerCreating  0         0s
   121  ```
   122  
   123  ### Example: Deploy Tiller in a namespace, restricted to deploying resources in another namespace
   124  
   125  In the example above, we gave Tiller admin access to the namespace it was deployed inside. Now, let's limit Tiller's scope to deploy resources in a different namespace!
   126  
   127  For example, let's install Tiller in the namespace `myorg-system` and allow Tiller to deploy resources in the namespace `myorg-users`.
   128  
   129  ```console
   130  $ kubectl create namespace myorg-system
   131  namespace "myorg-system" created
   132  $ kubectl create serviceaccount tiller --namespace myorg-system
   133  serviceaccount "tiller" created
   134  ```
   135  
   136  Define a Role that allows Tiller to manage all resources in `myorg-users` like in `role-tiller.yaml`:
   137  
   138  ```yaml
   139  kind: Role
   140  apiVersion: rbac.authorization.k8s.io/v1
   141  metadata:
   142    name: tiller-manager
   143    namespace: myorg-users
   144  rules:
   145  - apiGroups: ["", "batch", "extensions", "apps"]
   146    resources: ["*"]
   147    verbs: ["*"]
   148  ```
   149  
   150  ```console
   151  $ kubectl create -f role-tiller.yaml
   152  role "tiller-manager" created
   153  ```
   154  
   155  Bind the service account to that role. In `rolebinding-tiller.yaml`,
   156  
   157  ```yaml
   158  kind: RoleBinding
   159  apiVersion: rbac.authorization.k8s.io/v1
   160  metadata:
   161    name: tiller-binding
   162    namespace: myorg-users
   163  subjects:
   164  - kind: ServiceAccount
   165    name: tiller
   166    namespace: myorg-system
   167  roleRef:
   168    kind: Role
   169    name: tiller-manager
   170    apiGroup: rbac.authorization.k8s.io
   171  ```
   172  
   173  ```console
   174  $ kubectl create -f rolebinding-tiller.yaml
   175  rolebinding "tiller-binding" created
   176  ```
   177  
   178  We'll also need to grant Tiller access to read configmaps in myorg-system so it can store release information. In `role-tiller-myorg-system.yaml`:
   179  
   180  ```yaml
   181  kind: Role
   182  apiVersion: rbac.authorization.k8s.io/v1
   183  metadata:
   184    namespace: myorg-system
   185    name: tiller-manager
   186  rules:
   187  - apiGroups: ["", "extensions", "apps"]
   188    resources: ["configmaps"]
   189    verbs: ["*"]
   190  ```
   191  
   192  ```console
   193  $ kubectl create -f role-tiller-myorg-system.yaml
   194  role "tiller-manager" created
   195  ```
   196  
   197  And the respective role binding. In `rolebinding-tiller-myorg-system.yaml`:
   198  
   199  ```yaml
   200  kind: RoleBinding
   201  apiVersion: rbac.authorization.k8s.io/v1
   202  metadata:
   203    name: tiller-binding
   204    namespace: myorg-system
   205  subjects:
   206  - kind: ServiceAccount
   207    name: tiller
   208    namespace: myorg-system
   209  roleRef:
   210    kind: Role
   211    name: tiller-manager
   212    apiGroup: rbac.authorization.k8s.io
   213  ```
   214  
   215  ```console
   216  $ kubectl create -f rolebinding-tiller-myorg-system.yaml
   217  rolebinding "tiller-binding" created
   218  ```
   219  
   220  ## Helm and Role-based Access Control
   221  
   222  When running a Helm client in a pod, in order for the Helm client to talk to a Tiller instance, it will need certain privileges to be granted. Specifically, the Helm client will need to be able to create pods, forward ports and be able to list pods in the namespace where Tiller is running (so it can find Tiller).
   223  
   224  ### Example: Deploy Helm in a namespace, talking to Tiller in another namespace
   225  
   226  In this example, we will assume Tiller is running in a namespace called `tiller-world` and that the Helm client is running in a namespace called `helm-world`. By default, Tiller is running in the `kube-system` namespace.
   227  
   228  In `helm-user.yaml`:
   229  
   230  ```yaml
   231  apiVersion: v1
   232  kind: ServiceAccount
   233  metadata:
   234    name: helm
   235    namespace: helm-world
   236  ---
   237  apiVersion: rbac.authorization.k8s.io/v1
   238  kind: Role
   239  metadata:
   240    name: tiller-user
   241    namespace: tiller-world
   242  rules:
   243  - apiGroups:
   244    - ""
   245    resources:
   246    - pods/portforward
   247    verbs:
   248    - create
   249  - apiGroups:
   250    - ""
   251    resources:
   252    - pods
   253    verbs:
   254    - list
   255  ---
   256  apiVersion: rbac.authorization.k8s.io/v1
   257  kind: RoleBinding
   258  metadata:
   259    name: tiller-user-binding
   260    namespace: tiller-world
   261  roleRef:
   262    apiGroup: rbac.authorization.k8s.io
   263    kind: Role
   264    name: tiller-user
   265  subjects:
   266  - kind: ServiceAccount
   267    name: helm
   268    namespace: helm-world
   269  ```
   270  
   271  ```console
   272  $ kubectl create -f helm-user.yaml
   273  serviceaccount "helm" created
   274  role "tiller-user" created
   275  rolebinding "tiller-user-binding" created
   276  ```