[COMMON][SA] Add default role creation to ServiceAccount
[oom.git] / kubernetes / common / serviceAccount / templates / role.yaml
1 {{/*
2 # Copyright © 2020 Orange
3 # Modifications Copyright © 2023 Deutsche Telekom AG
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #       http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 */}}
17
18 {{- $dot := . -}}
19 {{- range $role_type := $dot.Values.roles }}
20 {{/* Default roles are already created, just creating specific ones */}}
21 {{-   if not (has $role_type $dot.Values.defaultRoles) }}
22 ---
23 apiVersion: rbac.authorization.k8s.io/v1
24 kind: Role
25 metadata:
26   name: {{ include "common.fullname" (dict "suffix" $role_type "dot" $dot ) }}
27   namespace: {{ include "common.namespace" $dot }}
28 rules:
29 {{-     if hasKey $dot.Values.new_roles_definitions $role_type  }}
30 {{ include "common.tplValue" ( dict "value" (index $dot.Values.new_roles_definitions $role_type ) "context" $dot) }}
31 {{-     else}}
32 # if no rules are provided, you're back to 'nothing' role
33 - apiGroups:
34   - authorization.k8s.io
35   resources:
36   - selfsubjectaccessreviews
37   - selfsubjectrulesreviews
38   verbs:
39   - create
40 {{-     end }}
41 {{-   else if or ($dot.Values.global.createDefaultRoles) ($dot.Values.createDefaultRoles) }}
42 ---
43 apiVersion: rbac.authorization.k8s.io/v1
44 kind: Role
45 metadata:
46   name: {{ include "common.fullname" (dict "suffix" $role_type "dot" $dot ) }}
47   namespace: {{ include "common.namespace" $dot }}
48 rules:
49 {{-     if eq $role_type "read" }}
50 - apiGroups:
51   - "" # "" indicates the core API group
52   - apps
53   - batch
54   - extensions
55   resources:
56   - pods
57   - deployments
58   - deployments/status
59   - jobs
60   - jobs/status
61   - statefulsets
62   - replicasets
63   - replicasets/status
64   - daemonsets
65   verbs:
66   - get
67   - watch
68   - list
69 {{-     else  }}
70 {{-       if eq $role_type "create" }}
71 - apiGroups:
72   - "" # "" indicates the core API group
73   - apps
74   - batch
75   - extensions
76   resources:
77   - pods
78   - deployments
79   - deployments/status
80   - jobs
81   - jobs/status
82   - statefulsets
83   - replicasets
84   - replicasets/status
85   - daemonsets
86   - secrets
87   - services
88   verbs:
89   - get
90   - watch
91   - list
92 - apiGroups:
93   - "" # "" indicates the core API group
94   - apps
95   resources:
96   - statefulsets
97   - configmaps
98   verbs:
99   - patch
100 - apiGroups:
101   - "" # "" indicates the core API group
102   - apps
103   resources:
104   - deployments
105   - secrets
106   - services
107   - pods
108   verbs:
109   - create
110 - apiGroups:
111   - "" # "" indicates the core API group
112   - apps
113   resources:
114   - pods
115   - persistentvolumeclaims
116   - secrets
117   - deployments
118   - services
119   verbs:
120   - delete
121 - apiGroups:
122   - "" # "" indicates the core API group
123   - apps
124   resources:
125   - pods/exec
126   verbs:
127   - create
128 - apiGroups:
129   - cert-manager.io
130   resources:
131   - certificates
132   verbs:
133   - create
134   - delete
135 {{-       else }}
136 # if you don't match read or create, then you're not allowed to use API
137 # except to see basic information about yourself
138 - apiGroups:
139   - authorization.k8s.io
140   resources:
141   - selfsubjectaccessreviews
142   - selfsubjectrulesreviews
143   verbs:
144   - create
145 {{-       end }}
146 {{-     end }}
147 {{-   end }}
148 {{- end }}