rbac_test.yaml 9.7 KB

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