Skip to content

Commit

Permalink
Helm: restrict RBAC namespaced deployments (#145)
Browse files Browse the repository at this point in the history
* Helm: restrict RBAC namespaced deployments

* Helm: restrict RBAC verbs, same changes as PR #143
  • Loading branch information
Smana authored and wallyqs committed Mar 13, 2019
1 parent 16b0dfc commit 37a60dc
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 46 deletions.
32 changes: 0 additions & 32 deletions helm/nats-operator/templates/clusterrole.yaml

This file was deleted.

14 changes: 0 additions & 14 deletions helm/nats-operator/templates/clusterrolebinding.yaml

This file was deleted.

104 changes: 104 additions & 0 deletions helm/nats-operator/templates/rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
{{- if .Values.rbacEnabled }}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: nats-io:nats-operator-crd
rules:
# Allow creating CRDs
- apiGroups:
- apiextensions.k8s.io
resources:
- customresourcedefinitions
verbs: ["get", "list", "create", "update", "watch"]
# Allow all actions on NatsClusters
- apiGroups:
- nats.io
resources:
- natsclusters
- natsserviceroles
verbs: ["*"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: nats-io:nats-operator-crd-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: nats-io:nats-operator-crd
subjects:
- kind: ServiceAccount
name: nats-operator
namespace: {{ .Release.Namespace }}
---
apiVersion: rbac.authorization.k8s.io/v1
{{- if .Values.clusterScoped }}
kind: ClusterRole
{{- else }}
kind: Role
{{- end }}
metadata:
name: nats-io:nats-operator
rules:
# Allowed actions on Pods
- apiGroups: [""]
resources:
- pods
verbs: ["create", "get", "patch", "update", "delete", "list"]

# Allowed actions on Services
- apiGroups: [""]
resources:
- services
verbs: ["create", "get", "patch", "update", "delete", "list"]

# Allowed actions on Secrets
- apiGroups: [""]
resources:
- secrets
verbs: ["create", "get", "update", "delete", "list"]

# Allow all actions on some special subresources
- apiGroups: [""]
resources:
- pods/exec
- pods/log
- serviceaccounts/token
- events
verbs: ["*"]

# Allow listing Namespaces and ServiceAccounts
- apiGroups: [""]
resources:
- namespaces
- serviceaccounts
verbs:
- list

# Allow actions on Endpoints
- apiGroups: [""]
resources:
- endpoints
verbs: ["get", "list", "update"]
---
apiVersion: rbac.authorization.k8s.io/v1
{{- if .Values.clusterScoped }}
kind: ClusterRoleBinding
{{- else }}
kind: RoleBinding
{{- end }}
metadata:
name: nats-io:nats-operator-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
{{- if .Values.clusterScoped }}
kind: ClusterRole
{{- else }}
kind: Role
{{- end }}
name: nats-io:nats-operator
subjects:
- kind: ServiceAccount
name: nats-operator
namespace: {{ .Release.Namespace }}
{{- end }}

0 comments on commit 37a60dc

Please sign in to comment.