securityContext.yaml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. suite: pod securityContext test
  2. templates:
  3. - common.yaml
  4. tests:
  5. - it: should pass with securityContext from "global"
  6. set:
  7. securityContext:
  8. pod:
  9. fsGroup: 1000
  10. fsGroupChangePolicy: OnRootMismatch
  11. supplementalGroups:
  12. - 1000
  13. - 1001
  14. sysctls:
  15. - name: some_name
  16. value: "some_value"
  17. - name: some_other_name
  18. value: "some_other_value"
  19. workload:
  20. workload-name1:
  21. enabled: true
  22. primary: true
  23. type: Deployment
  24. podSpec: {}
  25. asserts:
  26. - documentIndex: &deploymentDoc 0
  27. isKind:
  28. of: Deployment
  29. - documentIndex: *deploymentDoc
  30. equal:
  31. path: spec.template.spec.securityContext
  32. value:
  33. fsGroup: 1000
  34. fsGroupChangePolicy: OnRootMismatch
  35. supplementalGroups:
  36. - 1000
  37. - 1001
  38. sysctls:
  39. - name: some_name
  40. value: "some_value"
  41. - name: some_other_name
  42. value: "some_other_value"
  43. - it: should pass with securityContext from "global" and partial override with "pod"
  44. set:
  45. securityContext:
  46. pod:
  47. fsGroup: 1000
  48. fsGroupChangePolicy: OnRootMismatch
  49. supplementalGroups:
  50. - 1000
  51. - 1001
  52. sysctls:
  53. - name: some_name
  54. value: "some_value"
  55. - name: some_other_name
  56. value: "some_other_value"
  57. workload:
  58. workload-name1:
  59. enabled: true
  60. primary: true
  61. type: Deployment
  62. podSpec:
  63. securityContext:
  64. fsGroup: 1001
  65. asserts:
  66. - documentIndex: *deploymentDoc
  67. isKind:
  68. of: Deployment
  69. - documentIndex: *deploymentDoc
  70. equal:
  71. path: spec.template.spec.securityContext
  72. value:
  73. fsGroup: 1001
  74. fsGroupChangePolicy: OnRootMismatch
  75. supplementalGroups:
  76. - 1000
  77. - 1001
  78. sysctls:
  79. - name: some_name
  80. value: "some_value"
  81. - name: some_other_name
  82. value: "some_other_value"
  83. - it: should pass with securityContext from "global" and full override with "pod"
  84. set:
  85. some_sysctl_name: some_name
  86. some_sysctl_value: 2
  87. securityContext:
  88. pod:
  89. fsGroup: 1000
  90. fsGroupChangePolicy: OnRootMismatch
  91. supplementalGroups:
  92. - 1000
  93. - 1001
  94. sysctls:
  95. - name: some_name
  96. value: "some_value"
  97. - name: some_other_name
  98. value: "some_other_value"
  99. workload:
  100. workload-name1:
  101. enabled: true
  102. primary: true
  103. type: Deployment
  104. podSpec:
  105. securityContext:
  106. fsGroup: 1001
  107. fsGroupChangePolicy: Always
  108. supplementalGroups:
  109. - 1002
  110. - 1003
  111. sysctls:
  112. - name: "{{ .Values.some_sysctl_name }}"
  113. value: "{{ .Values.some_sysctl_value }}"
  114. - name: some_other_name
  115. value: "some_different_value"
  116. asserts:
  117. - documentIndex: *deploymentDoc
  118. isKind:
  119. of: Deployment
  120. - documentIndex: *deploymentDoc
  121. equal:
  122. path: spec.template.spec.securityContext
  123. value:
  124. fsGroup: 1001
  125. fsGroupChangePolicy: Always
  126. supplementalGroups:
  127. - 1002
  128. - 1003
  129. sysctls:
  130. - name: some_name
  131. value: "2"
  132. - name: some_other_name
  133. value: "some_different_value"
  134. - it: should pass with sysctls automatically appended based on services
  135. set:
  136. some_sysctl_name: some_name
  137. some_sysctl_value: 2
  138. workload:
  139. workload-name1:
  140. enabled: true
  141. primary: true
  142. type: Deployment
  143. podSpec:
  144. securityContext:
  145. fsGroup: 1001
  146. fsGroupChangePolicy: Always
  147. supplementalGroups:
  148. - 1002
  149. - 1003
  150. sysctls:
  151. - name: "{{ .Values.some_sysctl_name }}"
  152. value: "{{ .Values.some_sysctl_value }}"
  153. - name: some_other_name
  154. value: "some_different_value"
  155. workload-name2:
  156. enabled: true
  157. type: Deployment
  158. podSpec: {}
  159. service:
  160. service-name1:
  161. enabled: true
  162. primary: true
  163. type: ClusterIP
  164. ports:
  165. port-name:
  166. enabled: true
  167. primary: true
  168. port: 80
  169. service-name2:
  170. enabled: true
  171. type: ClusterIP
  172. ports:
  173. port-name:
  174. enabled: true
  175. primary: true
  176. port: 53
  177. service-name3:
  178. enabled: true
  179. type: ClusterIP
  180. targetSelector: workload-name2
  181. ports:
  182. port-name:
  183. enabled: true
  184. primary: true
  185. port: 443
  186. asserts:
  187. - documentIndex: *deploymentDoc
  188. isKind:
  189. of: Deployment
  190. - documentIndex: *deploymentDoc
  191. equal:
  192. path: spec.template.spec.securityContext
  193. value:
  194. fsGroup: 1001
  195. fsGroupChangePolicy: Always
  196. supplementalGroups:
  197. - 1002
  198. - 1003
  199. sysctls:
  200. - name: some_name
  201. value: "2"
  202. - name: some_other_name
  203. value: "some_different_value"
  204. - name: net.ipv4.ip_unprivileged_port_start
  205. value: "53"
  206. - documentIndex: &otherdeploymentDoc 1
  207. isKind:
  208. of: Deployment
  209. - documentIndex: *otherdeploymentDoc
  210. equal:
  211. path: spec.template.spec.securityContext
  212. value:
  213. fsGroup: 568
  214. fsGroupChangePolicy: OnRootMismatch
  215. supplementalGroups: []
  216. sysctls:
  217. - name: net.ipv4.ip_unprivileged_port_start
  218. value: "443"
  219. - it: should pass with fsGroup 0
  220. set:
  221. securityContext:
  222. pod:
  223. fsGroup: 0
  224. workload:
  225. workload-name1:
  226. enabled: true
  227. primary: true
  228. type: Deployment
  229. podSpec: {}
  230. asserts:
  231. - documentIndex: &deploymentDoc 0
  232. isKind:
  233. of: Deployment
  234. - documentIndex: *deploymentDoc
  235. equal:
  236. path: spec.template.spec.securityContext
  237. value:
  238. fsGroup: 0
  239. fsGroupChangePolicy: OnRootMismatch
  240. supplementalGroups: []
  241. sysctls: []
  242. - it: should pass with no sysctls port_start automatically appended based on services when port is higher than 1024
  243. set:
  244. workload:
  245. workload-name1:
  246. enabled: true
  247. primary: true
  248. type: Deployment
  249. podSpec: {}
  250. service:
  251. service-name1:
  252. enabled: true
  253. primary: true
  254. type: ClusterIP
  255. ports:
  256. port-name:
  257. enabled: true
  258. primary: true
  259. port: 25000
  260. targetPort: 3000
  261. asserts:
  262. - documentIndex: &deploymentDoc 0
  263. isKind:
  264. of: Deployment
  265. - documentIndex: *deploymentDoc
  266. equal:
  267. path: spec.template.spec.securityContext
  268. value:
  269. fsGroup: 568
  270. fsGroupChangePolicy: OnRootMismatch
  271. supplementalGroups: []
  272. sysctls: []
  273. - it: should pass with with gpu assigned to primary pod
  274. set:
  275. workload:
  276. workload-name1:
  277. enabled: true
  278. primary: true
  279. type: Deployment
  280. podSpec:
  281. securityContext:
  282. supplementalGroups:
  283. - 1000
  284. workload-name2:
  285. enabled: true
  286. primary: false
  287. type: Deployment
  288. podSpec: {}
  289. scaleGPU:
  290. - gpu:
  291. nvidia: "1"
  292. asserts:
  293. - documentIndex: &deploymentDoc 0
  294. isKind:
  295. of: Deployment
  296. - documentIndex: *deploymentDoc
  297. equal:
  298. path: spec.template.spec.securityContext
  299. value:
  300. fsGroup: 568
  301. fsGroupChangePolicy: OnRootMismatch
  302. supplementalGroups:
  303. - 1000
  304. - 44
  305. - 107
  306. sysctls: []
  307. - documentIndex: &otherDeploymentDoc 1
  308. isKind:
  309. of: Deployment
  310. - documentIndex: *otherDeploymentDoc
  311. equal:
  312. path: spec.template.spec.securityContext
  313. value:
  314. fsGroup: 568
  315. fsGroupChangePolicy: OnRootMismatch
  316. supplementalGroups: []
  317. sysctls: []
  318. - it: should pass with with gpu assigned to specific pod
  319. set:
  320. workload:
  321. workload-name1:
  322. enabled: true
  323. primary: true
  324. type: Deployment
  325. podSpec:
  326. securityContext:
  327. supplementalGroups:
  328. - 1000
  329. workload-name2:
  330. enabled: true
  331. primary: false
  332. type: Deployment
  333. podSpec: {}
  334. scaleGPU:
  335. - gpu:
  336. nvidia: "1"
  337. targetSelector:
  338. workload-name1:
  339. - container-name1
  340. asserts:
  341. - documentIndex: &deploymentDoc 0
  342. isKind:
  343. of: Deployment
  344. - documentIndex: *deploymentDoc
  345. equal:
  346. path: spec.template.spec.securityContext
  347. value:
  348. fsGroup: 568
  349. fsGroupChangePolicy: OnRootMismatch
  350. supplementalGroups:
  351. - 1000
  352. - 44
  353. - 107
  354. sysctls: []
  355. - documentIndex: &otherDeploymentDoc 1
  356. isKind:
  357. of: Deployment
  358. - documentIndex: *otherDeploymentDoc
  359. equal:
  360. path: spec.template.spec.securityContext
  361. value:
  362. fsGroup: 568
  363. fsGroupChangePolicy: OnRootMismatch
  364. supplementalGroups: []
  365. sysctls: []
  366. - it: should pass with with gpu assigned to multiple pod
  367. set:
  368. workload:
  369. workload-name1:
  370. enabled: true
  371. primary: true
  372. type: Deployment
  373. podSpec:
  374. securityContext:
  375. supplementalGroups:
  376. - 1000
  377. workload-name2:
  378. enabled: true
  379. primary: false
  380. type: Deployment
  381. podSpec: {}
  382. scaleGPU:
  383. - gpu:
  384. nvidia: "1"
  385. targetSelector:
  386. workload-name1:
  387. - container-name1
  388. workload-name2:
  389. - container-name1
  390. asserts:
  391. - documentIndex: &deploymentDoc 0
  392. isKind:
  393. of: Deployment
  394. - documentIndex: *deploymentDoc
  395. equal:
  396. path: spec.template.spec.securityContext
  397. value:
  398. fsGroup: 568
  399. fsGroupChangePolicy: OnRootMismatch
  400. supplementalGroups:
  401. - 1000
  402. - 44
  403. - 107
  404. sysctls: []
  405. - documentIndex: &otherDeploymentDoc 1
  406. isKind:
  407. of: Deployment
  408. - documentIndex: *otherDeploymentDoc
  409. equal:
  410. path: spec.template.spec.securityContext
  411. value:
  412. fsGroup: 568
  413. fsGroupChangePolicy: OnRootMismatch
  414. supplementalGroups:
  415. - 44
  416. - 107
  417. sysctls: []
  418. # Failures
  419. - it: should fail with empty securityContext from "global"
  420. set:
  421. securityContext:
  422. pod: null
  423. workload:
  424. workload-name1:
  425. enabled: true
  426. primary: true
  427. type: Deployment
  428. podSpec: {}
  429. asserts:
  430. - failedTemplate:
  431. errorMessage: Pod - Expected non-empty <.Values.securityContext.pod>
  432. - it: should fail with empty fsGroup
  433. set:
  434. securityContext:
  435. pod:
  436. fsGroup: ""
  437. workload:
  438. workload-name1:
  439. enabled: true
  440. primary: true
  441. type: Deployment
  442. podSpec: {}
  443. asserts:
  444. - failedTemplate:
  445. errorMessage: Pod - Expected non-empty <fsGroup>
  446. - it: should fail with empty fsGroupChangePolicy
  447. set:
  448. securityContext:
  449. pod:
  450. fsGroup: 568
  451. fsGroupChangePolicy: ""
  452. workload:
  453. workload-name1:
  454. enabled: true
  455. primary: true
  456. type: Deployment
  457. podSpec: {}
  458. asserts:
  459. - failedTemplate:
  460. errorMessage: Pod - Expected non-empty <fsGroupChangePolicy>
  461. - it: should fail with invalid fsGroupChangePolicy
  462. set:
  463. securityContext:
  464. pod:
  465. fsGroup: 568
  466. fsGroupChangePolicy: invalid
  467. workload:
  468. workload-name1:
  469. enabled: true
  470. primary: true
  471. type: Deployment
  472. podSpec: {}
  473. asserts:
  474. - failedTemplate:
  475. errorMessage: Pod - Expected <fsGroupChangePolicy> to be one of [Always, OnRootMismatch], but got [invalid]
  476. - it: should fail with empty name in sysctls
  477. set:
  478. securityContext:
  479. pod:
  480. fsGroup: 568
  481. fsGroupChangePolicy: OnRootMismatch
  482. sysctls:
  483. - name: ""
  484. value: "some_value"
  485. workload:
  486. workload-name1:
  487. enabled: true
  488. primary: true
  489. type: Deployment
  490. podSpec: {}
  491. asserts:
  492. - failedTemplate:
  493. errorMessage: Pod - Expected non-empty <name> in <sysctls>
  494. - it: should fail with empty value in sysctls
  495. set:
  496. securityContext:
  497. pod:
  498. fsGroup: 568
  499. fsGroupChangePolicy: OnRootMismatch
  500. sysctls:
  501. - name: some_name
  502. value: ""
  503. workload:
  504. workload-name1:
  505. enabled: true
  506. primary: true
  507. type: Deployment
  508. podSpec: {}
  509. asserts:
  510. - failedTemplate:
  511. errorMessage: Pod - Expected non-empty <value> in <sysctls>