Skip to content

Question: Helm in-cluster w/RBAC #2962

Closed

Description

@alapidas

Are there any docs on using helm in a k8s cluster with RBAC enabled? For example, I have a pod in a cluster that wants to helm install a chart into the same cluster. In general this seems to work fine, but if RBAC is enabled, you can run into issues. Any docs on what (cluster)roles might be needed in this situation would be very helpful.

Activity

  1. bacongobbler commented on Sep 22, 2017

    @bacongobbler
    Member

    https://github.com/kubernetes/helm/blob/master/docs/service_accounts.md explains how to set up the service accounts for tiller based on your requirements. I couldn't find the link in the official documentation though.

  2. alapidas commented on Sep 22, 2017

    @alapidas
    Author

    That doesn't quite cover this use case. In this use case, there' a pod in MyNamespace that has roles that limit him to only being able to really act within the MyNamespace namespace. When he tries to helm install ... using the in-cluster config, it errors out initially on the fact that the service account being used doesn't have access to list pods in kube-system.

    The serviceaccount being used in the MyNamespace pod probably needs some level of access to the namespace that tiller is in (kube-system), I just don't know the extent of what roles are needed.

  3. bacongobbler commented on Sep 22, 2017

    @bacongobbler
    Member

    Isn't that explained in https://github.com/kubernetes/helm/blob/master/docs/service_accounts.md#example-service-account-restricted-to-a-namespace? It goes through the documentation on how to create a tiller service account along with the proper roles and role bindings to grant tiller the ability to create resources in that namespace. If you have a tiller instance in kube-system and you want to grant it access to install resources in my-namespace, just tweak the documentation to suit your needs.

    First, create the namespace and a tiller service account in the kube-system namespace:

    $ kubectl create namespace my-namespace
    $ kubectl create serviceaccount tiller --namespace kube-system
    

    Then, define a role called role-tiller.yaml that allows one to manage resources in my-namespace:

    kind: Role
    apiVersion: rbac.authorization.k8s.io/v1beta1
    metadata:
      namespace: my-namespace
      name: tiller-manager
    rules:
    - apiGroups: ["", "extensions", "apps"]
      resources: ["*"]
      verbs: ["*"]
    

    Then bind that role to the tiller service account in kube-system. In rolebinding-tiller.yaml:

    kind: RoleBinding
    apiVersion: rbac.authorization.k8s.io/v1beta1
    metadata:
      name: tiller-binding
      namespace: my-namespace
    subjects:
    - kind: ServiceAccount
      name: tiller
      namespace: kube-system
    roleRef:
      kind: Role
      name: tiller-manager
      apiGroup: rbac.authorization.k8s.io
    

    You'll also need to grant tiller access to read configmaps in kube-system so it can store release information. In role-tiller-kube-system.yaml:

    kind: Role
    apiVersion: rbac.authorization.k8s.io/v1beta1
    metadata:
      namespace: kube-system
      name: tiller-manager
    rules:
    - apiGroups: ["", "extensions", "apps"]
      resources: ["configmaps", "secrets"]
      verbs: ["*"]
    

    And then the respective role binding (rolebinding-tiller-kube-system.yaml):

    kind: RoleBinding
    apiVersion: rbac.authorization.k8s.io/v1beta1
    metadata:
      name: tiller-binding
      namespace: kube-system
    subjects:
    - kind: ServiceAccount
      name: tiller
      namespace: kube-system
    roleRef:
      kind: Role
      name: tiller-manager
      apiGroup: rbac.authorization.k8s.io
    

    And finally, piecing it all together:

    $ for i in role*.yaml; do kubectl create -f $i; done
    role "tiller-manager" created
    role "tiller-manager" created
    rolebinding "tiller-binding" created
    rolebinding "tiller-binding" created
    

    Et voilà, your tiller instance in kube-system can manage resources in my-namespace after you run helm init --service-account tiller.

    $ helm install stable/nginx-ingress --namespace foo
    Error: release listless-whale failed: User "system:serviceaccount:kube-system:tiller" cannot get namespaces in the namespace "foo". (get namespaces foo)
    $ helm install stable/nginx-ingress --namespace my-namespace
    NAME:   gaudy-gopher
    LAST DEPLOYED: Fri Sep 22 11:20:55 2017
    NAMESPACE: my-namespace
    STATUS: DEPLOYED
    ...
    
  4. alapidas commented on Sep 22, 2017

    @alapidas
    Author

    This is GREAT information, but it doesn't cover what's needed to have helm actually talk to tiller if helm is running in a pod in the same cluster, but in a different namespace. When doing so, I get:

    User \"system:serviceaccount:myOtherNamspace:myOtherServiceAccount\" cannot list pods in the namespace \"kube-system\".
    
  5. bacongobbler commented on Sep 22, 2017

    @bacongobbler
    Member

    Sorry... That wasn't very clear to me from the previous comments. I thought you were just asking about how to run tiller in an RBAC-enabled cluster as a lot of users get confused with helm/tiller. Sorry about that!

    If you're communicating with tiller via helm internal to the cluster, I think you just need to grant the pod running helm the role to list pods in the namespace tiller's running from, as the error suggests. To do that, assuming your helm pod is in namespace foo:

    $ kubectl -n foo create serviceaccount helm-client
    

    role-podlister.yaml

    kind: Role
    apiVersion: rbac.authorization.k8s.io/v1beta1
    metadata:
      namespace: kube-system
      name: pod-lister
    rules:
    - apiGroups: ["", "extensions", "apps"]
      resources: ["pods"]
      verbs: ["list"]
    

    rolebinding-podlister.yaml

    kind: RoleBinding
    apiVersion: rbac.authorization.k8s.io/v1beta1
    metadata:
      name: pod-lister-binding
      namespace: kube-system
    subjects:
    - kind: ServiceAccount
      name: helm-client
      namespace: foo
    roleRef:
      kind: Role
      name: pod-lister
      apiGroup: rbac.authorization.k8s.io
    
    $ for i in role*podlister.yaml; do kubectl create -f $i; done
    role "pod-lister" created
    rolebinding "pod-lister-binding" created
    

    I think that's about as exhaustive of a list of docs I can come up with. Let me know if something doesn't work.

  6. seh commented on Sep 28, 2017

    @seh
    Contributor

    You could narrow the "apiGroups" set on the "pod-lister" Role above.

    Also, in the "tiller-manager" Role above, I don't think Tiller needs access to the "secrets" resource within its containing namespace—unless you're using the new secret-based release backend, right?

  7. bacongobbler commented on Oct 19, 2017

    @bacongobbler
    Member

    @seh correct. I had #2721 in mind when writing this example. :)

    If you're using the default configmap storage backend then you can omit secrets from the tiller-manager role.

  8. bacongobbler commented on Oct 19, 2017

    @bacongobbler
    Member

    @alapidas does that help answer your question, or is there something else you'd like to know?

  9. alapidas commented on Oct 19, 2017

    @alapidas
    Author

    That probably does it - I haven't had a chance to test this, but let's close this out for now. Thanks!

  10. bacongobbler commented on Oct 30, 2017

    @bacongobbler
    Member

    Actually I'm going to re-open this as an action item to put this in the documentation. I've referenced it on several occasions, so it's probably best to get this enshrined in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions