File size: 2,375 Bytes
df0899b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
variables:
- name: containers
  expression: 'has(variables.anyObject.spec.containers) ? variables.anyObject.spec.containers : []'
- name: initContainers
  expression: 'has(variables.anyObject.spec.initContainers) ? variables.anyObject.spec.initContainers : []'
- name: ephemeralContainers
  expression: 'has(variables.anyObject.spec.ephemeralContainers) ? variables.anyObject.spec.ephemeralContainers : []'
- name: exemptImagePrefixes
  expression: |
    !has(variables.params.exemptImages) ? [] :
      variables.params.exemptImages.filter(image, image.endsWith("*")).map(image, string(image).replace("*", ""))
- name: exemptImageExplicit
  expression: |
    !has(variables.params.exemptImages) ? [] : 
      variables.params.exemptImages.filter(image, !image.endsWith("*"))
- name: exemptImages
  expression: |
    (variables.containers + variables.initContainers + variables.ephemeralContainers).filter(container,
      container.image in variables.exemptImageExplicit ||
      variables.exemptImagePrefixes.exists(exemption, string(container.image).startsWith(exemption))
    ).map(container, container.image)
- name: podHostProcess
  expression: |
    has(variables.anyObject.spec.securityContext) &&
    has(variables.anyObject.spec.securityContext.windowsOptions) &&
    has(variables.anyObject.spec.securityContext.windowsOptions.hostProcess) &&
    variables.anyObject.spec.securityContext.windowsOptions.hostProcess
- name: badContainers
  expression: |
    (variables.containers + variables.initContainers + variables.ephemeralContainers).filter(container,
      !(container.image in variables.exemptImages) &&
      has(container.securityContext) &&
      has(container.securityContext.windowsOptions) &&
      has(container.securityContext.windowsOptions.hostProcess) &&
      container.securityContext.windowsOptions.hostProcess
    ).map(container, "HostProcess container is not allowed: " + container.name + ", securityContext.windowsOptions.hostProcess: true")
- name: isUpdate
  expression: has(request.operation) && request.operation == "UPDATE"
validations:
- expression: 'variables.isUpdate || !variables.podHostProcess'
  messageExpression: '"HostProcess is not allowed at pod level: " + variables.anyObject.metadata.name'
- expression: variables.isUpdate || size(variables.badContainers) == 0
  messageExpression: 'variables.badContainers.join(", ")'