-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance controller RBAC and helm charts generation
This patch enhances the permissions for controllers with the addiotion of multi-namespace watch mode. The controlelrs now have more fine-grained permissions, enabling them to watch specific namespaces exclusively. Key changes: - Refactored helm chart generation tooling, especially Roles and ClusterRoles - Addressed a bug where the RoleBinding was incorrectly assigning the roles into a different namespace when the controller was installed ina namespace that is different fro the one it monitored. Notable features: - We start generating one Role/RoleBinding for each monitored namespace. - We introduced seperate Role and ClusterRoles for the CARM feature (prefixed with ack-*-cache) Less importantly we are replacing some bash-fu that used to inject RBAC rules into Roles and ClusterRoles, with a different bash-fu that allows reusing rules for different Roles. Signed-off-by: Amine Hilaly <[email protected]>
- Loading branch information
Showing
8 changed files
with
132 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
templates/helm/templates/_controller-role-kind-patch.yaml.tpl
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: ack-namespaces-cache-{{ .ServicePackageName }}-controller | ||
roleRef: | ||
kind: ClusterRole | ||
apiGroup: rbac.authorization.k8s.io | ||
name: ack-namespaces-cache-{{ .ServicePackageName }}-controller | ||
subjects: | ||
- kind: ServiceAccount | ||
name: ack-{{ .ServicePackageName }}-controller | ||
namespace: {{ "{{ .Release.Namespace }}" }} | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: ack-configmaps-cache-{{ .ServicePackageName }}-controller | ||
namespace: {{ "{{ .Release.Namespace }}" }} | ||
roleRef: | ||
kind: Role | ||
apiGroup: rbac.authorization.k8s.io | ||
name: ack-configmaps-cache-{{ .ServicePackageName }}-controller | ||
subjects: | ||
- kind: ServiceAccount | ||
name: ack-{{ .ServicePackageName }}-controller | ||
namespace: {{ "{{ .Release.Namespace }}" }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: ack-namespaces-cache-{{ .ServicePackageName }}-controller | ||
rules: | ||
- apiGroups: | ||
- "" | ||
resources: | ||
- namespaces | ||
verbs: | ||
- get | ||
- list | ||
- watch | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: Role | ||
metadata: | ||
name: ack-configmaps-cache-{{ .ServicePackageName }}-controller | ||
namespace: {{ "{{ .Release.Namespace }}" }} | ||
rules: | ||
- apiGroups: | ||
- "" | ||
resources: | ||
- configmaps | ||
verbs: | ||
- get | ||
- list | ||
- watch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,35 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
{{ "{{ if eq .Values.installScope \"cluster\" }}" }} | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: {{ "{{ include \"app.fullname\" . }}" }} | ||
roleRef: | ||
kind: ClusterRole | ||
{{ "{{ else }}" }} | ||
apiGroup: rbac.authorization.k8s.io | ||
name: ack-{{ .ServicePackageName }}-controller | ||
subjects: | ||
- kind: ServiceAccount | ||
name: {{ "{{ include \"service-account.name\" . }}" }} | ||
namespace: {{ "{{ .Release.Namespace }}" }} | ||
{{ "{{ else if .Values.watchNamespace }}" }} | ||
{{ "{{ $namespaces := split \",\" .Values.watchNamespace }}" }} | ||
{{ "{{ $fullname := include \"app.fullname\" . }}" }} | ||
{{ "{{ $releaseNamespace := .Release.Namespace }}" }} | ||
{{ "{{ $serviceAccountName := include \"service-account.name\" . }}" }} | ||
{{ "{{ range $namespaces }}" }} | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: {{ "{{ include \"app.fullname\" . }}" }} | ||
namespace: {{ "{{ .Release.Namespace }}" }} | ||
name: {{ "{{ $fullname }}" }} | ||
namespace: {{ "{{ . }}" }} | ||
roleRef: | ||
kind: Role | ||
{{ "{{ end }}" }} | ||
apiGroup: rbac.authorization.k8s.io | ||
name: ack-{{ .ServicePackageName }}-controller | ||
subjects: | ||
- kind: ServiceAccount | ||
name: {{ "{{ include \"service-account.name\" . }}" }} | ||
namespace: {{ "{{ .Release.Namespace }}" }} | ||
name: {{ "{{ $serviceAccountName }}" }} | ||
namespace: {{ "{{ $releaseNamespace }}" }} | ||
{{ "{{ end }}" }} | ||
{{ "{{ end }}" }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{{ "{{ $labels := .Values.role.labels }}" }} | ||
{{ "{{ $rules := include \"controller-role-rules\" . }}" }} | ||
{{ "{{ if eq .Values.installScope \"cluster\" }}" }} | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: ack-{{ .ServicePackageName }}-controller | ||
labels: | ||
{{ "{{- range $key, $value := $labels }}" }} | ||
{{ "{{ $key }}: {{ $value | quote }}" }} | ||
{{ "{{- end }}" }} | ||
{{ "{{- $rules }}" }} | ||
{{ "{{ else if .Values.watchNamespace }}" }} | ||
{{ "{{ $namespaces := split \",\" .Values.watchNamespace }}" }} | ||
{{ "{{ range $namespaces }}" }} | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: Role | ||
metadata: | ||
name: ack-{{ .ServicePackageName }}-controller | ||
namespace: {{ "{{ . }}" }} | ||
labels: | ||
{{ "{{- range $key, $value := $labels }}" }} | ||
{{ "{{ $key }}: {{ $value | quote }}" }} | ||
{{ "{{- end }}" }} | ||
{{ "{{- $rules }}" }} | ||
{{ "{{ end }}" }} | ||
{{ "{{ end }}" }} |