|
| 1 | +suite: test security context configuration |
| 2 | +templates: |
| 3 | + - _helpers.tpl |
| 4 | + - controller-configmap.yaml |
| 5 | + - controller-deployment.yaml |
| 6 | + - ui-deployment.yaml |
| 7 | +tests: |
| 8 | + # ============================================================================= |
| 9 | + # Controller Security Context Tests |
| 10 | + # ============================================================================= |
| 11 | + - it: should apply default pod security context to controller |
| 12 | + template: controller-deployment.yaml |
| 13 | + asserts: |
| 14 | + - equal: |
| 15 | + path: spec.template.spec.securityContext.runAsNonRoot |
| 16 | + value: true |
| 17 | + |
| 18 | + - it: should apply default container security context to controller |
| 19 | + template: controller-deployment.yaml |
| 20 | + asserts: |
| 21 | + - equal: |
| 22 | + path: spec.template.spec.containers[0].securityContext.readOnlyRootFilesystem |
| 23 | + value: true |
| 24 | + |
| 25 | + - it: should allow controller pod security context override |
| 26 | + template: controller-deployment.yaml |
| 27 | + set: |
| 28 | + controller: |
| 29 | + podSecurityContext: |
| 30 | + runAsNonRoot: true |
| 31 | + fsGroup: 2000 |
| 32 | + asserts: |
| 33 | + - equal: |
| 34 | + path: spec.template.spec.securityContext.runAsNonRoot |
| 35 | + value: true |
| 36 | + - equal: |
| 37 | + path: spec.template.spec.securityContext.fsGroup |
| 38 | + value: 2000 |
| 39 | + |
| 40 | + - it: should allow controller container security context override |
| 41 | + template: controller-deployment.yaml |
| 42 | + set: |
| 43 | + controller: |
| 44 | + securityContext: |
| 45 | + readOnlyRootFilesystem: false |
| 46 | + runAsUser: 1000 |
| 47 | + asserts: |
| 48 | + - equal: |
| 49 | + path: spec.template.spec.containers[0].securityContext.readOnlyRootFilesystem |
| 50 | + value: false |
| 51 | + - equal: |
| 52 | + path: spec.template.spec.containers[0].securityContext.runAsUser |
| 53 | + value: 1000 |
| 54 | + |
| 55 | + - it: should fallback to global pod security context for controller |
| 56 | + template: controller-deployment.yaml |
| 57 | + set: |
| 58 | + podSecurityContext: |
| 59 | + runAsNonRoot: true |
| 60 | + fsGroup: 3000 |
| 61 | + asserts: |
| 62 | + - equal: |
| 63 | + path: spec.template.spec.securityContext.runAsNonRoot |
| 64 | + value: true |
| 65 | + - equal: |
| 66 | + path: spec.template.spec.securityContext.fsGroup |
| 67 | + value: 3000 |
| 68 | + |
| 69 | + - it: should fallback to global container security context for controller |
| 70 | + template: controller-deployment.yaml |
| 71 | + set: |
| 72 | + securityContext: |
| 73 | + readOnlyRootFilesystem: true |
| 74 | + capabilities: |
| 75 | + drop: |
| 76 | + - ALL |
| 77 | + asserts: |
| 78 | + - equal: |
| 79 | + path: spec.template.spec.containers[0].securityContext.readOnlyRootFilesystem |
| 80 | + value: true |
| 81 | + - contains: |
| 82 | + path: spec.template.spec.containers[0].securityContext.capabilities.drop |
| 83 | + content: ALL |
| 84 | + |
| 85 | + # ============================================================================= |
| 86 | + # UI Security Context Tests |
| 87 | + # ============================================================================= |
| 88 | + - it: should apply UI-specific container security context override |
| 89 | + template: ui-deployment.yaml |
| 90 | + asserts: |
| 91 | + - equal: |
| 92 | + path: spec.template.spec.containers[0].securityContext.readOnlyRootFilesystem |
| 93 | + value: true |
| 94 | + |
| 95 | + - it: should have nextjs-cache volume for UI |
| 96 | + template: ui-deployment.yaml |
| 97 | + asserts: |
| 98 | + - contains: |
| 99 | + path: spec.template.spec.volumes |
| 100 | + content: |
| 101 | + name: nextjs-cache |
| 102 | + emptyDir: |
| 103 | + sizeLimit: 100Mi |
| 104 | + |
| 105 | + - it: should have tmp volume for UI |
| 106 | + template: ui-deployment.yaml |
| 107 | + asserts: |
| 108 | + - contains: |
| 109 | + path: spec.template.spec.volumes |
| 110 | + content: |
| 111 | + name: tmp |
| 112 | + emptyDir: |
| 113 | + sizeLimit: 50Mi |
| 114 | + |
| 115 | + - it: should have nextjs-cache volume mount for UI |
| 116 | + template: ui-deployment.yaml |
| 117 | + asserts: |
| 118 | + - contains: |
| 119 | + path: spec.template.spec.containers[0].volumeMounts |
| 120 | + content: |
| 121 | + name: nextjs-cache |
| 122 | + mountPath: /app/ui/.next/cache |
| 123 | + |
| 124 | + - it: should have tmp volume mount for UI |
| 125 | + template: ui-deployment.yaml |
| 126 | + asserts: |
| 127 | + - contains: |
| 128 | + path: spec.template.spec.containers[0].volumeMounts |
| 129 | + content: |
| 130 | + name: tmp |
| 131 | + mountPath: /tmp |
| 132 | + |
| 133 | + - it: should allow UI pod security context override |
| 134 | + template: ui-deployment.yaml |
| 135 | + set: |
| 136 | + ui: |
| 137 | + podSecurityContext: |
| 138 | + runAsNonRoot: true |
| 139 | + fsGroup: 5000 |
| 140 | + asserts: |
| 141 | + - equal: |
| 142 | + path: spec.template.spec.securityContext.runAsNonRoot |
| 143 | + value: true |
| 144 | + - equal: |
| 145 | + path: spec.template.spec.securityContext.fsGroup |
| 146 | + value: 5000 |
| 147 | + |
| 148 | + - it: should allow UI container security context override |
| 149 | + template: ui-deployment.yaml |
| 150 | + set: |
| 151 | + ui: |
| 152 | + securityContext: |
| 153 | + readOnlyRootFilesystem: false |
| 154 | + runAsUser: 2000 |
| 155 | + asserts: |
| 156 | + - equal: |
| 157 | + path: spec.template.spec.containers[0].securityContext.readOnlyRootFilesystem |
| 158 | + value: false |
| 159 | + - equal: |
| 160 | + path: spec.template.spec.containers[0].securityContext.runAsUser |
| 161 | + value: 2000 |
| 162 | + |
| 163 | + - it: should fallback to global pod security context for UI |
| 164 | + template: ui-deployment.yaml |
| 165 | + set: |
| 166 | + ui: |
| 167 | + podSecurityContext: {} |
| 168 | + podSecurityContext: |
| 169 | + runAsNonRoot: true |
| 170 | + runAsUser: 3001 |
| 171 | + asserts: |
| 172 | + - equal: |
| 173 | + path: spec.template.spec.securityContext.runAsNonRoot |
| 174 | + value: true |
| 175 | + - equal: |
| 176 | + path: spec.template.spec.securityContext.runAsUser |
| 177 | + value: 3001 |
| 178 | + |
| 179 | + - it: should prefer UI security context over global |
| 180 | + template: ui-deployment.yaml |
| 181 | + set: |
| 182 | + ui: |
| 183 | + securityContext: |
| 184 | + readOnlyRootFilesystem: false |
| 185 | + securityContext: |
| 186 | + readOnlyRootFilesystem: true |
| 187 | + asserts: |
| 188 | + - equal: |
| 189 | + path: spec.template.spec.containers[0].securityContext.readOnlyRootFilesystem |
| 190 | + value: false |
0 commit comments