github.com/koderover/helm@v2.17.0+incompatible/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 --history-max 200
    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  
   110  $ helm install stable/lamp --tiller-namespace tiller-world --namespace tiller-world
   111  NAME:   wayfaring-yak
   112  LAST DEPLOYED: Mon Aug  7 16:00:16 2017
   113  NAMESPACE: tiller-world
   114  STATUS: DEPLOYED
   115  
   116  RESOURCES:
   117  ==> v1/Pod
   118  NAME                  READY  STATUS             RESTARTS  AGE
   119  wayfaring-yak-alpine  0/1    ContainerCreating  0         0s
   120  ```
   121  
   122  ### Example: Deploy Tiller in a namespace, restricted to deploying resources in another namespace
   123  
   124  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!
   125  
   126  For example, let's install Tiller in the namespace `myorg-system` and allow Tiller to deploy resources in the namespace `myorg-users`.
   127  
   128  ```console
   129  $ kubectl create namespace myorg-system
   130  namespace "myorg-system" created
   131  $ kubectl create serviceaccount tiller --namespace myorg-system
   132  serviceaccount "tiller" created
   133  ```
   134  
   135  Define a Role that allows Tiller to manage all resources in `myorg-users` like in `role-tiller.yaml`:
   136  
   137  ```yaml
   138  kind: Role
   139  apiVersion: rbac.authorization.k8s.io/v1
   140  metadata:
   141    name: tiller-manager
   142    namespace: myorg-users
   143  rules:
   144  - apiGroups: ["", "batch", "extensions", "apps"]
   145    resources: ["*"]
   146    verbs: ["*"]
   147  ```
   148  
   149  ```console
   150  $ kubectl create -f role-tiller.yaml
   151  role "tiller-manager" created
   152  ```
   153  
   154  Bind the service account to that role. In `rolebinding-tiller.yaml`,
   155  
   156  ```yaml
   157  kind: RoleBinding
   158  apiVersion: rbac.authorization.k8s.io/v1
   159  metadata:
   160    name: tiller-binding
   161    namespace: myorg-users
   162  subjects:
   163  - kind: ServiceAccount
   164    name: tiller
   165    namespace: myorg-system
   166  roleRef:
   167    kind: Role
   168    name: tiller-manager
   169    apiGroup: rbac.authorization.k8s.io
   170  ```
   171  
   172  ```console
   173  $ kubectl create -f rolebinding-tiller.yaml
   174  rolebinding "tiller-binding" created
   175  ```
   176  
   177  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`:
   178  
   179  ```yaml
   180  kind: Role
   181  apiVersion: rbac.authorization.k8s.io/v1
   182  metadata:
   183    namespace: myorg-system
   184    name: tiller-manager
   185  rules:
   186  - apiGroups: ["", "extensions", "apps"]
   187    resources: ["configmaps"]
   188    verbs: ["*"]
   189  ```
   190  
   191  ```console
   192  $ kubectl create -f role-tiller-myorg-system.yaml
   193  role "tiller-manager" created
   194  ```
   195  
   196  And the respective role binding. In `rolebinding-tiller-myorg-system.yaml`:
   197  
   198  ```yaml
   199  kind: RoleBinding
   200  apiVersion: rbac.authorization.k8s.io/v1
   201  metadata:
   202    name: tiller-binding
   203    namespace: myorg-system
   204  subjects:
   205  - kind: ServiceAccount
   206    name: tiller
   207    namespace: myorg-system
   208  roleRef:
   209    kind: Role
   210    name: tiller-manager
   211    apiGroup: rbac.authorization.k8s.io
   212  ```
   213  
   214  ```console
   215  $ kubectl create -f rolebinding-tiller-myorg-system.yaml
   216  rolebinding "tiller-binding" created
   217  ```
   218  
   219  ## Helm and Role-based Access Control
   220  
   221  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).
   222  
   223  ### Example: Deploy Helm in a namespace, talking to Tiller in another namespace
   224  
   225  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.
   226  
   227  In `helm-user.yaml`:
   228  
   229  ```yaml
   230  apiVersion: v1
   231  kind: ServiceAccount
   232  metadata:
   233    name: helm
   234    namespace: helm-world
   235  ---
   236  apiVersion: rbac.authorization.k8s.io/v1
   237  kind: Role
   238  metadata:
   239    name: tiller-user
   240    namespace: tiller-world
   241  rules:
   242  - apiGroups:
   243    - ""
   244    resources:
   245    - pods/portforward
   246    verbs:
   247    - create
   248  - apiGroups:
   249    - ""
   250    resources:
   251    - pods
   252    verbs:
   253    - list
   254  ---
   255  apiVersion: rbac.authorization.k8s.io/v1
   256  kind: RoleBinding
   257  metadata:
   258    name: tiller-user-binding
   259    namespace: tiller-world
   260  roleRef:
   261    apiGroup: rbac.authorization.k8s.io
   262    kind: Role
   263    name: tiller-user
   264  subjects:
   265  - kind: ServiceAccount
   266    name: helm
   267    namespace: helm-world
   268  ```
   269  
   270  ```console
   271  $ kubectl create -f helm-user.yaml
   272  serviceaccount "helm" created
   273  role "tiller-user" created
   274  rolebinding "tiller-user-binding" created
   275  ```