securityContext.yaml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  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 sysctls net.ipv4.ip_unprivileged_port_start NOT appended with hostnet
  220. set:
  221. workload:
  222. workload-name1:
  223. enabled: true
  224. primary: true
  225. type: Deployment
  226. podSpec:
  227. hostNetwork: true
  228. workload-name2:
  229. enabled: true
  230. type: Deployment
  231. podSpec: {}
  232. service:
  233. service-name:
  234. enabled: true
  235. primary: true
  236. type: ClusterIP
  237. targetSelector: workload-name2
  238. ports:
  239. port-name:
  240. enabled: true
  241. primary: true
  242. port: 443
  243. asserts:
  244. - documentIndex: &deploymentDoc 0
  245. isKind:
  246. of: Deployment
  247. - documentIndex: *deploymentDoc
  248. equal:
  249. path: spec.template.spec.securityContext
  250. value:
  251. fsGroup: 568
  252. fsGroupChangePolicy: OnRootMismatch
  253. supplementalGroups: []
  254. sysctls: []
  255. - it: should pass with fsGroup 0
  256. set:
  257. securityContext:
  258. pod:
  259. fsGroup: 0
  260. workload:
  261. workload-name1:
  262. enabled: true
  263. primary: true
  264. type: Deployment
  265. podSpec: {}
  266. asserts:
  267. - documentIndex: &deploymentDoc 0
  268. isKind:
  269. of: Deployment
  270. - documentIndex: *deploymentDoc
  271. equal:
  272. path: spec.template.spec.securityContext
  273. value:
  274. fsGroup: 0
  275. fsGroupChangePolicy: OnRootMismatch
  276. supplementalGroups: []
  277. sysctls: []
  278. - it: should pass with no sysctls port_start automatically appended based on services when port is higher than 1024
  279. set:
  280. workload:
  281. workload-name1:
  282. enabled: true
  283. primary: true
  284. type: Deployment
  285. podSpec: {}
  286. service:
  287. service-name1:
  288. enabled: true
  289. primary: true
  290. type: ClusterIP
  291. ports:
  292. port-name:
  293. enabled: true
  294. primary: true
  295. port: 25000
  296. targetPort: 3000
  297. asserts:
  298. - documentIndex: &deploymentDoc 0
  299. isKind:
  300. of: Deployment
  301. - documentIndex: *deploymentDoc
  302. equal:
  303. path: spec.template.spec.securityContext
  304. value:
  305. fsGroup: 568
  306. fsGroupChangePolicy: OnRootMismatch
  307. supplementalGroups: []
  308. sysctls: []
  309. - it: should pass with with gpu assigned to primary pod
  310. set:
  311. workload:
  312. workload-name1:
  313. enabled: true
  314. primary: true
  315. type: Deployment
  316. podSpec:
  317. securityContext:
  318. supplementalGroups:
  319. - 1000
  320. workload-name2:
  321. enabled: true
  322. primary: false
  323. type: Deployment
  324. podSpec: {}
  325. scaleGPU:
  326. - gpu:
  327. nvidia: "1"
  328. asserts:
  329. - documentIndex: &deploymentDoc 0
  330. isKind:
  331. of: Deployment
  332. - documentIndex: *deploymentDoc
  333. equal:
  334. path: spec.template.spec.securityContext
  335. value:
  336. fsGroup: 568
  337. fsGroupChangePolicy: OnRootMismatch
  338. supplementalGroups:
  339. - 1000
  340. - 44
  341. - 107
  342. sysctls: []
  343. - documentIndex: &otherDeploymentDoc 1
  344. isKind:
  345. of: Deployment
  346. - documentIndex: *otherDeploymentDoc
  347. equal:
  348. path: spec.template.spec.securityContext
  349. value:
  350. fsGroup: 568
  351. fsGroupChangePolicy: OnRootMismatch
  352. supplementalGroups: []
  353. sysctls: []
  354. - it: should pass with with gpu assigned to specific pod
  355. set:
  356. workload:
  357. workload-name1:
  358. enabled: true
  359. primary: true
  360. type: Deployment
  361. podSpec:
  362. securityContext:
  363. supplementalGroups:
  364. - 1000
  365. workload-name2:
  366. enabled: true
  367. primary: false
  368. type: Deployment
  369. podSpec: {}
  370. scaleGPU:
  371. - gpu:
  372. nvidia: "1"
  373. targetSelector:
  374. workload-name1:
  375. - container-name1
  376. asserts:
  377. - documentIndex: &deploymentDoc 0
  378. isKind:
  379. of: Deployment
  380. - documentIndex: *deploymentDoc
  381. equal:
  382. path: spec.template.spec.securityContext
  383. value:
  384. fsGroup: 568
  385. fsGroupChangePolicy: OnRootMismatch
  386. supplementalGroups:
  387. - 1000
  388. - 44
  389. - 107
  390. sysctls: []
  391. - documentIndex: &otherDeploymentDoc 1
  392. isKind:
  393. of: Deployment
  394. - documentIndex: *otherDeploymentDoc
  395. equal:
  396. path: spec.template.spec.securityContext
  397. value:
  398. fsGroup: 568
  399. fsGroupChangePolicy: OnRootMismatch
  400. supplementalGroups: []
  401. sysctls: []
  402. - it: should pass with with gpu assigned to multiple pod
  403. set:
  404. workload:
  405. workload-name1:
  406. enabled: true
  407. primary: true
  408. type: Deployment
  409. podSpec:
  410. securityContext:
  411. supplementalGroups:
  412. - 1000
  413. workload-name2:
  414. enabled: true
  415. primary: false
  416. type: Deployment
  417. podSpec: {}
  418. scaleGPU:
  419. - gpu:
  420. nvidia: "1"
  421. targetSelector:
  422. workload-name1:
  423. - container-name1
  424. workload-name2:
  425. - container-name1
  426. asserts:
  427. - documentIndex: &deploymentDoc 0
  428. isKind:
  429. of: Deployment
  430. - documentIndex: *deploymentDoc
  431. equal:
  432. path: spec.template.spec.securityContext
  433. value:
  434. fsGroup: 568
  435. fsGroupChangePolicy: OnRootMismatch
  436. supplementalGroups:
  437. - 1000
  438. - 44
  439. - 107
  440. sysctls: []
  441. - documentIndex: &otherDeploymentDoc 1
  442. isKind:
  443. of: Deployment
  444. - documentIndex: *otherDeploymentDoc
  445. equal:
  446. path: spec.template.spec.securityContext
  447. value:
  448. fsGroup: 568
  449. fsGroupChangePolicy: OnRootMismatch
  450. supplementalGroups:
  451. - 44
  452. - 107
  453. sysctls: []
  454. # Failures
  455. - it: should fail with empty securityContext from "global"
  456. set:
  457. securityContext:
  458. pod: null
  459. workload:
  460. workload-name1:
  461. enabled: true
  462. primary: true
  463. type: Deployment
  464. podSpec: {}
  465. asserts:
  466. - failedTemplate:
  467. errorMessage: Pod - Expected non-empty <.Values.securityContext.pod>
  468. - it: should fail with empty fsGroup
  469. set:
  470. securityContext:
  471. pod:
  472. fsGroup: ""
  473. workload:
  474. workload-name1:
  475. enabled: true
  476. primary: true
  477. type: Deployment
  478. podSpec: {}
  479. asserts:
  480. - failedTemplate:
  481. errorMessage: Pod - Expected non-empty <fsGroup>
  482. - it: should fail with empty fsGroupChangePolicy
  483. set:
  484. securityContext:
  485. pod:
  486. fsGroup: 568
  487. fsGroupChangePolicy: ""
  488. workload:
  489. workload-name1:
  490. enabled: true
  491. primary: true
  492. type: Deployment
  493. podSpec: {}
  494. asserts:
  495. - failedTemplate:
  496. errorMessage: Pod - Expected non-empty <fsGroupChangePolicy>
  497. - it: should fail with invalid fsGroupChangePolicy
  498. set:
  499. securityContext:
  500. pod:
  501. fsGroup: 568
  502. fsGroupChangePolicy: invalid
  503. workload:
  504. workload-name1:
  505. enabled: true
  506. primary: true
  507. type: Deployment
  508. podSpec: {}
  509. asserts:
  510. - failedTemplate:
  511. errorMessage: Pod - Expected <fsGroupChangePolicy> to be one of [Always, OnRootMismatch], but got [invalid]
  512. - it: should fail with empty name in sysctls
  513. set:
  514. securityContext:
  515. pod:
  516. fsGroup: 568
  517. fsGroupChangePolicy: OnRootMismatch
  518. sysctls:
  519. - name: ""
  520. value: "some_value"
  521. workload:
  522. workload-name1:
  523. enabled: true
  524. primary: true
  525. type: Deployment
  526. podSpec: {}
  527. asserts:
  528. - failedTemplate:
  529. errorMessage: Pod - Expected non-empty <name> in <sysctls>
  530. - it: should fail with empty value in sysctls
  531. set:
  532. securityContext:
  533. pod:
  534. fsGroup: 568
  535. fsGroupChangePolicy: OnRootMismatch
  536. sysctls:
  537. - name: some_name
  538. value: ""
  539. workload:
  540. workload-name1:
  541. enabled: true
  542. primary: true
  543. type: Deployment
  544. podSpec: {}
  545. asserts:
  546. - failedTemplate:
  547. errorMessage: Pod - Expected non-empty <value> in <sysctls>