rbac_test.yaml 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. suite: test rbac
  2. templates:
  3. - rbac.yaml
  4. tests:
  5. - it: should remove the labels aggregate-to-view to the view ClusterRole
  6. set:
  7. rbac:
  8. aggregateToView: false
  9. asserts:
  10. - notExists:
  11. path: metadata.labels["rbac.authorization.k8s.io/aggregate-to-view"]
  12. documentSelector:
  13. kind: ClusterRole
  14. path: metadata.name
  15. value: RELEASE-NAME-external-secrets-view
  16. - it: should remove the labels aggregate-to-edit to the view and edit ClusterRoles
  17. set:
  18. rbac:
  19. aggregateToEdit: false
  20. asserts:
  21. - notExists:
  22. path: metadata.labels["rbac.authorization.k8s.io/aggregate-to-edit"]
  23. documentSelector:
  24. kind: ClusterRole
  25. path: metadata.name
  26. value: RELEASE-NAME-external-secrets-view
  27. - notExists:
  28. path: metadata.labels["rbac.authorization.k8s.io/aggregate-to-edit"]
  29. documentSelector:
  30. kind: ClusterRole
  31. path: metadata.name
  32. value: RELEASE-NAME-external-secrets-edit
  33. - it: should not create auth delegator ClusterRoleBinding by default
  34. documentSelector:
  35. path: kind
  36. value: ClusterRoleBinding
  37. asserts:
  38. - notEqual:
  39. path: metadata.name
  40. value: RELEASE-NAME-external-secrets-auth-delegator
  41. - it: should create auth delegator ClusterRoleBinding when systemAuthDelegator is true
  42. set:
  43. systemAuthDelegator: true
  44. documentSelector:
  45. path: metadata.name
  46. value: RELEASE-NAME-external-secrets-auth-delegator
  47. asserts:
  48. - isKind:
  49. of: ClusterRoleBinding
  50. - equal:
  51. path: roleRef.apiGroup
  52. value: rbac.authorization.k8s.io
  53. - equal:
  54. path: roleRef.kind
  55. value: ClusterRole
  56. - equal:
  57. path: roleRef.name
  58. value: system:auth-delegator
  59. - equal:
  60. path: subjects[0].kind
  61. value: ServiceAccount
  62. - equal:
  63. path: subjects[0].name
  64. value: RELEASE-NAME-external-secrets
  65. - equal:
  66. path: subjects[0].namespace
  67. value: NAMESPACE
  68. - it: should configure custom lease name when leaderElectionID is set
  69. set:
  70. leaderElectionID: "custom-eso-lease"
  71. asserts:
  72. - matchSnapshot: {}
  73. - it: should render resourceName as external-secrets-controller by default
  74. set:
  75. scopedRBAC: true
  76. documentSelector:
  77. path: rules[0].resourceNames[0]
  78. value: "external-secrets-controller"
  79. asserts:
  80. - isKind:
  81. of: Role
  82. - equal:
  83. path: metadata.name
  84. value: RELEASE-NAME-external-secrets-leaderelection
  85. - it: should include serviceaccounts/token create by default
  86. documentIndex: 0
  87. asserts:
  88. - isKind:
  89. of: ClusterRole
  90. - equal:
  91. path: metadata.name
  92. value: RELEASE-NAME-external-secrets-controller
  93. - contains:
  94. path: rules
  95. content:
  96. apiGroups:
  97. - ""
  98. resources:
  99. - "serviceaccounts/token"
  100. verbs:
  101. - "create"
  102. - it: should not include serviceaccounts/token create when serviceAccountTokenCreate is false
  103. set:
  104. rbac:
  105. serviceAccountTokenCreate: false
  106. documentIndex: 0
  107. asserts:
  108. - isKind:
  109. of: ClusterRole
  110. - equal:
  111. path: metadata.name
  112. value: RELEASE-NAME-external-secrets-controller
  113. - notContains:
  114. path: rules
  115. content:
  116. apiGroups:
  117. - ""
  118. resources:
  119. - "serviceaccounts/token"
  120. verbs:
  121. - "create"
  122. - it: should include externalsecrets create/update/delete when processClusterExternalSecret is true
  123. set:
  124. processClusterExternalSecret: true
  125. documentIndex: 0
  126. asserts:
  127. - isKind:
  128. of: ClusterRole
  129. - equal:
  130. path: metadata.name
  131. value: RELEASE-NAME-external-secrets-controller
  132. - contains:
  133. path: rules
  134. content:
  135. apiGroups:
  136. - "external-secrets.io"
  137. resources:
  138. - "externalsecrets"
  139. verbs:
  140. - "create"
  141. - "update"
  142. - "delete"
  143. - it: should not include externalsecrets create/update/delete when processClusterExternalSecret is false
  144. set:
  145. processClusterExternalSecret: false
  146. documentIndex: 0
  147. asserts:
  148. - isKind:
  149. of: ClusterRole
  150. - equal:
  151. path: metadata.name
  152. value: RELEASE-NAME-external-secrets-controller
  153. - notContains:
  154. path: rules
  155. content:
  156. apiGroups:
  157. - "external-secrets.io"
  158. resources:
  159. - "externalsecrets"
  160. verbs:
  161. - "create"
  162. - "update"
  163. - "delete"
  164. - it: should render controller Role with explicit scopedNamespace when scopedRBAC is true
  165. set:
  166. scopedRBAC: true
  167. scopedNamespace: "my-ns"
  168. documentIndex: 0
  169. asserts:
  170. - isKind:
  171. of: Role
  172. - equal:
  173. path: metadata.name
  174. value: RELEASE-NAME-external-secrets-controller
  175. - equal:
  176. path: metadata.namespace
  177. value: "my-ns"
  178. - it: should render controller Role with release namespace when scopedRBAC is true and scopedNamespace is empty
  179. set:
  180. scopedRBAC: true
  181. scopedNamespace: ""
  182. documentIndex: 0
  183. asserts:
  184. - isKind:
  185. of: Role
  186. - equal:
  187. path: metadata.name
  188. value: RELEASE-NAME-external-secrets-controller
  189. - equal:
  190. path: metadata.namespace
  191. value: NAMESPACE
  192. - it: should render controller ClusterRole when scopedRBAC is false
  193. set:
  194. scopedRBAC: false
  195. documentIndex: 0
  196. asserts:
  197. - isKind:
  198. of: ClusterRole
  199. - equal:
  200. path: metadata.name
  201. value: RELEASE-NAME-external-secrets-controller
  202. - notExists:
  203. path: metadata.namespace
  204. - it: should render view Role with release namespace when scopedRBAC is true
  205. set:
  206. scopedRBAC: true
  207. documentSelector:
  208. path: metadata.name
  209. value: RELEASE-NAME-external-secrets-view
  210. asserts:
  211. - isKind:
  212. of: Role
  213. - equal:
  214. path: metadata.namespace
  215. value: NAMESPACE
  216. - it: should render edit Role with release namespace when scopedRBAC is true
  217. set:
  218. scopedRBAC: true
  219. documentSelector:
  220. path: metadata.name
  221. value: RELEASE-NAME-external-secrets-edit
  222. asserts:
  223. - isKind:
  224. of: Role
  225. - equal:
  226. path: metadata.namespace
  227. value: NAMESPACE
  228. - it: should render ClusterRole when scopedNamespace is set without scopedRBAC
  229. set:
  230. scopedRBAC: false
  231. scopedNamespace: "my-ns"
  232. documentIndex: 0
  233. asserts:
  234. - isKind:
  235. of: ClusterRole
  236. - equal:
  237. path: metadata.name
  238. value: RELEASE-NAME-external-secrets-controller
  239. - notExists:
  240. path: metadata.namespace
  241. - it: should render controller RoleBinding when scopedRBAC is true and scopedNamespace is empty
  242. set:
  243. scopedRBAC: true
  244. scopedNamespace: ""
  245. documentIndex: 3
  246. asserts:
  247. - isKind:
  248. of: RoleBinding
  249. - equal:
  250. path: metadata.name
  251. value: RELEASE-NAME-external-secrets-controller
  252. - equal:
  253. path: metadata.namespace
  254. value: NAMESPACE
  255. - equal:
  256. path: roleRef.kind
  257. value: Role
  258. - equal:
  259. path: roleRef.name
  260. value: RELEASE-NAME-external-secrets-controller
  261. - it: should render controller RoleBinding with explicit scopedNamespace when scopedRBAC is true
  262. set:
  263. scopedRBAC: true
  264. scopedNamespace: "my-ns"
  265. documentIndex: 3
  266. asserts:
  267. - isKind:
  268. of: RoleBinding
  269. - equal:
  270. path: metadata.name
  271. value: RELEASE-NAME-external-secrets-controller
  272. - equal:
  273. path: metadata.namespace
  274. value: "my-ns"
  275. - equal:
  276. path: roleRef.kind
  277. value: Role
  278. - equal:
  279. path: roleRef.name
  280. value: RELEASE-NAME-external-secrets-controller
  281. - it: should render controller ClusterRoleBinding when scopedRBAC is false
  282. set:
  283. scopedRBAC: false
  284. documentIndex: 3
  285. asserts:
  286. - isKind:
  287. of: ClusterRoleBinding
  288. - equal:
  289. path: metadata.name
  290. value: RELEASE-NAME-external-secrets-controller
  291. - notExists:
  292. path: metadata.namespace
  293. - equal:
  294. path: roleRef.kind
  295. value: ClusterRole
  296. - equal:
  297. path: roleRef.name
  298. value: RELEASE-NAME-external-secrets-controller