data_test.yaml 6.6 KB

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