From a4aaf53212493f124b9ceee12c2dee8cd351b071 Mon Sep 17 00:00:00 2001 From: Maciej Szulik Date: Tue, 30 Jan 2018 12:00:49 +0100 Subject: [PATCH] Add proper rbac to run patroni on k8s (#616) Adds 3 resources that will properly setup the RBAC: 1. service account, which is also assigned to the pods of the cluster, so that they use those particular permissions 2. a role, which holds only the necessary permissions that patroni members need to interact with k8s cluster 3. a rolebinding, which connects two two former things together to use. The role and rolebinding was created using this tool https://github.com/liggitt/audit2rbac which looks at [audit logs](https://kubernetes.io/docs/tasks/debug-application-cluster/audit/#advanced-audit) provided by the api server. --- kubernetes/patroni_k8s.yaml | 60 +++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/kubernetes/patroni_k8s.yaml b/kubernetes/patroni_k8s.yaml index ed465352..71e82350 100644 --- a/kubernetes/patroni_k8s.yaml +++ b/kubernetes/patroni_k8s.yaml @@ -14,6 +14,7 @@ spec: application: patroni cluster-name: *cluster_name spec: + serviceAccountName: patronidemo containers: - name: *cluster_name image: patroni # docker build -t patroni . @@ -120,3 +121,62 @@ type: Opaque data: superuser-password: emFsYW5kbw== replication-password: cmVwLXBhc3M= + +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: patronidemo + +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: patronidemo +rules: +- apiGroups: + - "" + resources: + - configmaps + verbs: + - create + - get + - list + - patch + - update + - watch +- apiGroups: + - "" + resources: + - endpoints + verbs: + - get + - patch + - update + # the following three privileges are necessary only when using endpoints + - create + - list + - watch +- apiGroups: + - "" + resources: + - pods + verbs: + - get + - list + - patch + - update + - watch + +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: patronidemo +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: patronidemo +subjects: +- kind: ServiceAccount + name: patronidemo