data_test.yaml 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. suite: rbac data test
  2. templates:
  3. - common.yaml
  4. tests:
  5. - it: should pass with rules and subjects added with tpl and primary rbac/sa
  6. set:
  7. some_verb: list
  8. some_group: apps
  9. some_resource: deployments
  10. some_kind: some-kind
  11. some_name: some-name
  12. some_api_group: rbac.authorization.k8s.io
  13. serviceAccount:
  14. my-sa:
  15. enabled: true
  16. primary: true
  17. my-other-sa:
  18. enabled: true
  19. primary: false
  20. rbac:
  21. my-rbac:
  22. enabled: true
  23. primary: true
  24. rules:
  25. - apiGroups:
  26. - ""
  27. resources:
  28. - pods
  29. verbs:
  30. - get
  31. - apiGroups:
  32. - "{{ .Values.some_group }}"
  33. resources:
  34. - "{{ .Values.some_resource }}"
  35. resourceNames:
  36. - "{{ .Values.some_name }}"
  37. verbs:
  38. - "{{ .Values.some_verb }}"
  39. subjects:
  40. - kind: a-kind
  41. name: a-name
  42. apiGroup: rbac.authorization.k8s.io
  43. - kind: "{{ .Values.some_kind }}"
  44. name: "{{ .Values.some_name }}"
  45. apiGroup: "{{ .Values.some_api_group }}"
  46. asserts:
  47. - documentIndex: &roleDoc 2
  48. isKind:
  49. of: Role
  50. - documentIndex: *roleDoc
  51. equal:
  52. path: metadata.name
  53. value: release-name-common-test
  54. - documentIndex: *roleDoc
  55. equal:
  56. path: rules
  57. value:
  58. - apiGroups:
  59. - ""
  60. resources:
  61. - pods
  62. verbs:
  63. - get
  64. - apiGroups:
  65. - apps
  66. resources:
  67. - deployments
  68. resourceNames:
  69. - some-name
  70. verbs:
  71. - list
  72. - documentIndex: &roleBinding 3
  73. isKind:
  74. of: RoleBinding
  75. - documentIndex: *roleBinding
  76. equal:
  77. path: metadata.name
  78. value: release-name-common-test
  79. - documentIndex: *roleBinding
  80. equal:
  81. path: subjects
  82. value:
  83. - kind: ServiceAccount
  84. name: release-name-common-test
  85. namespace: NAMESPACE
  86. - kind: a-kind
  87. name: a-name
  88. apiGroup: rbac.authorization.k8s.io
  89. - kind: some-kind
  90. name: some-name
  91. apiGroup: rbac.authorization.k8s.io
  92. - it: should pass with rules and subjects added with tpl and allSA on clusterWide
  93. set:
  94. some_verb: list
  95. some_group: apps
  96. some_resource: deployments
  97. some_kind: some-kind
  98. some_name: some-name
  99. some_api_group: rbac.authorization.k8s.io
  100. serviceAccount:
  101. my-sa:
  102. enabled: true
  103. primary: true
  104. my-other-sa:
  105. enabled: true
  106. primary: false
  107. rbac:
  108. z-rbac:
  109. enabled: true
  110. primary: true
  111. rules:
  112. - apiGroups:
  113. - ""
  114. resources:
  115. - pods
  116. verbs:
  117. - get
  118. my-rbac2:
  119. enabled: true
  120. clusterWide: true
  121. allServiceAccounts: true
  122. rules:
  123. - apiGroups:
  124. - ""
  125. resources:
  126. - pods
  127. verbs:
  128. - get
  129. - apiGroups:
  130. - "{{ .Values.some_group }}"
  131. resources:
  132. - "{{ .Values.some_resource }}"
  133. verbs:
  134. - "{{ .Values.some_verb }}"
  135. subjects:
  136. - kind: a-kind
  137. name: a-name
  138. apiGroup: rbac.authorization.k8s.io
  139. - kind: "{{ .Values.some_kind }}"
  140. name: "{{ .Values.some_name }}"
  141. apiGroup: "{{ .Values.some_api_group }}"
  142. asserts:
  143. - documentIndex: &clusterRoleDoc 2
  144. isKind:
  145. of: ClusterRole
  146. - documentIndex: *clusterRoleDoc
  147. equal:
  148. path: metadata.name
  149. value: release-name-common-test-my-rbac2
  150. - documentIndex: *clusterRoleDoc
  151. equal:
  152. path: rules
  153. value:
  154. - apiGroups:
  155. - ""
  156. resources:
  157. - pods
  158. verbs:
  159. - get
  160. - apiGroups:
  161. - apps
  162. resources:
  163. - deployments
  164. verbs:
  165. - list
  166. - documentIndex: &clusterRoleBinding 3
  167. isKind:
  168. of: ClusterRoleBinding
  169. - documentIndex: *clusterRoleBinding
  170. equal:
  171. path: metadata.name
  172. value: release-name-common-test-my-rbac2
  173. - documentIndex: *clusterRoleBinding
  174. equal:
  175. path: subjects
  176. value:
  177. - kind: ServiceAccount
  178. name: release-name-common-test-my-other-sa
  179. namespace: NAMESPACE
  180. - kind: ServiceAccount
  181. name: release-name-common-test
  182. namespace: NAMESPACE
  183. - apiGroup: rbac.authorization.k8s.io
  184. kind: a-kind
  185. name: a-name
  186. - apiGroup: rbac.authorization.k8s.io
  187. kind: some-kind
  188. name: some-name
  189. - it: should pass with serviceAccount selector
  190. set:
  191. serviceAccount:
  192. my-sa:
  193. enabled: true
  194. primary: true
  195. my-other-sa:
  196. enabled: true
  197. primary: false
  198. rbac:
  199. z-rbac:
  200. enabled: true
  201. primary: true
  202. rules:
  203. - apiGroups:
  204. - ""
  205. resources:
  206. - pods
  207. verbs:
  208. - get
  209. my-rbac3:
  210. enabled: true
  211. serviceAccounts:
  212. - my-other-sa
  213. rules:
  214. - apiGroups:
  215. - ""
  216. resources:
  217. - pods
  218. verbs:
  219. - get
  220. asserts:
  221. - documentIndex: &roleDoc 2
  222. isKind:
  223. of: Role
  224. - documentIndex: *roleDoc
  225. equal:
  226. path: metadata.name
  227. value: release-name-common-test-my-rbac3
  228. - documentIndex: *roleDoc
  229. equal:
  230. path: rules
  231. value:
  232. - apiGroups:
  233. - ""
  234. resources:
  235. - pods
  236. verbs:
  237. - get
  238. - documentIndex: &roleBinding 3
  239. isKind:
  240. of: RoleBinding
  241. - documentIndex: *roleBinding
  242. equal:
  243. path: metadata.name
  244. value: release-name-common-test-my-rbac3
  245. - documentIndex: *roleBinding
  246. equal:
  247. path: subjects
  248. value:
  249. - kind: ServiceAccount
  250. name: release-name-common-test-my-other-sa
  251. namespace: NAMESPACE