Debian Codegraph @

launcher/image/test/test_mounts.yaml

raw
1 substitutions:
2 '_IMAGE_NAME': ''
3 '_IMAGE_PROJECT': ''
4 '_CLEANUP': 'true'
5 '_VM_NAME_PREFIX': 'cs-mounts-test'
6 '_ZONE': 'us-west1-a'
7 '_WORKLOAD_IMAGE': 'us-west1-docker.pkg.dev/confidential-space-images-dev/cs-integ-test-images/mounts_workload:latest'
8 '_DEV_SHM_SIZE_KB': '128000'
9 '_TMPFS_SIZE_KB': '222'
10 steps:
11 - name: 'gcr.io/cloud-builders/gcloud'
12 id: CreateVMWithDefaultDevShmSize
13 entrypoint: 'bash'
14 env:
15 - 'BUILD_ID=$BUILD_ID'
16 args: ['create_vm.sh','-i', '${_IMAGE_NAME}',
17 '-p', '${_IMAGE_PROJECT}',
18 '-m', '^~^tee-image-reference=${_WORKLOAD_IMAGE}~tee-container-log-redirect=true',
19 '-n', '${_VM_NAME_PREFIX}-${BUILD_ID}-default',
20 '-z', '${_ZONE}',
21 ]
22 - name: 'gcr.io/cloud-builders/gcloud'
23 id: CreateVMWithMountsAllowed
24 entrypoint: 'bash'
25 env:
26 - 'BUILD_ID=$BUILD_ID'
27 - '_DEV_SHM_SIZE_KB=$_DEV_SHM_SIZE_KB'
28 - '_TMPFS_SIZE_KB=$_TMPFS_SIZE_KB'
29 args: ['create_vm.sh','-i', '${_IMAGE_NAME}',
30 '-p', '${_IMAGE_PROJECT}',
31 '-m', '^~^tee-image-reference=${_WORKLOAD_IMAGE}~tee-container-log-redirect=true~tee-mount=type=tmpfs,source=tmpfs,destination=/tmp/sized,size=${_TMPFS_SIZE_KB}000~tee-dev-shm-size-kb=${_DEV_SHM_SIZE_KB}',
32 '-n', '${_VM_NAME_PREFIX}-${BUILD_ID}-allowed',
33 '-z', '${_ZONE}',
34 ]
35 - name: 'gcr.io/cloud-builders/gcloud'
36 id: CreateVMWithMountsDenied
37 entrypoint: 'bash'
38 env:
39 - 'BUILD_ID=$BUILD_ID'
40 args: ['create_vm.sh','-i', '${_IMAGE_NAME}',
41 '-p', '${_IMAGE_PROJECT}',
42 '-m', '^~^tee-image-reference=${_WORKLOAD_IMAGE}~tee-container-log-redirect=true~tee-mount=type=tmpfs,source=tmpfs,destination=/disallowed',
43 '-n', '${_VM_NAME_PREFIX}-${BUILD_ID}-denied',
44 '-z', '${_ZONE}',
45 ]
46 - name: 'gcr.io/cloud-builders/gcloud'
47 id: CheckDevShmExists
48 env:
49 - '_VM_NAME_PREFIX=$_VM_NAME_PREFIX'
50 - 'BUILD_ID=$BUILD_ID'
51 - '_ZONE=$_ZONE'
52 script: |
53 #!/bin/bash
54 set -euo pipefail
55 source util/read_serial.sh
56
57 sleep 45
58 SERIAL_OUTPUT=$(read_serial ${_VM_NAME_PREFIX}-${BUILD_ID}-default ${_ZONE})
59 if echo $SERIAL_OUTPUT | grep -q "shm.*/dev/shm"
60 then
61 echo "- Verified /dev/shm mounted by defaul"
62 else
63 echo "FAILED: /dev/shm mount failed"
64 echo 'TEST FAILED' > /workspace/status.txt
65 echo $SERIAL_OUTPUT
66 fi
67 - name: 'gcr.io/cloud-builders/gcloud'
68 id: CheckMountsAllowed
69 env:
70 - '_VM_NAME_PREFIX=$_VM_NAME_PREFIX'
71 - 'BUILD_ID=$BUILD_ID'
72 - '_ZONE=$_ZONE'
73 - '_DEV_SHM_SIZE_KB=$_DEV_SHM_SIZE_KB'
74 - '_TMPFS_SIZE_KB=$_TMPFS_SIZE_KB'
75 script: |
76 #!/bin/bash
77 set -euo pipefail
78 source util/read_serial.sh
79
80 sleep 45
81 SERIAL_OUTPUT=$(read_serial ${_VM_NAME_PREFIX}-${BUILD_ID}-allowed ${_ZONE})
82 if echo $SERIAL_OUTPUT | grep -q "tmpfs.*220.*/tmp/sized"
83 then
84 echo "- Mount verified for sized tmpfs"
85 else
86 echo "FAILED: Mount verification for sized tmpfs"
87 echo 'TEST FAILED' > /workspace/status.txt
88 echo $SERIAL_OUTPUT
89 fi
90 if echo $SERIAL_OUTPUT | grep -q "shm.*${_DEV_SHM_SIZE_KB}.*/dev/shm"
91 then
92 echo "- Mount verified for /dev/shm size"
93 else
94 echo "FAILED: Mount verification for /dev/shm size"
95 echo 'TEST FAILED' > /workspace/status.txt
96 echo $SERIAL_OUTPUT
97 fi
98
99 - name: 'gcr.io/cloud-builders/gcloud'
100 id: CheckMountsDenied
101 env:
102 - '_VM_NAME_PREFIX=$_VM_NAME_PREFIX'
103 - 'BUILD_ID=$BUILD_ID'
104 - '_ZONE=$_ZONE'
105 script: |
106 #!/bin/bash
107 set -euo pipefail
108 source util/read_serial.sh
109
110 sleep 45
111 SERIAL_OUTPUT=$(read_serial ${_VM_NAME_PREFIX}-${BUILD_ID}-denied ${_ZONE})
112 if echo $SERIAL_OUTPUT | grep -q "policy only allows mounts in the following paths"
113 then
114 echo "- Mount launch policy verified for disallowed mounts"
115 else
116 echo "FAILED: Mount launch policy verification for disallowed mounts"
117 echo 'TEST FAILED' > /workspace/status.txt
118 echo $SERIAL_OUTPUT
119 fi
120
121 waitFor: ['CreateVMWithMountsDenied']
122 - name: 'gcr.io/cloud-builders/gcloud'
123 id: CleanUpVMWithDefault
124 entrypoint: 'bash'
125 env:
126 - 'CLEANUP=$_CLEANUP'
127 args: ['cleanup.sh', '${_VM_NAME_PREFIX}-${BUILD_ID}-default', '${_ZONE}']
128 waitFor: ['CheckDevShmExists']
129 - name: 'gcr.io/cloud-builders/gcloud'
130 id: CleanUpVMWithMountsAllowed
131 entrypoint: 'bash'
132 env:
133 - 'CLEANUP=$_CLEANUP'
134 args: ['cleanup.sh', '${_VM_NAME_PREFIX}-${BUILD_ID}-allowed', '${_ZONE}']
135 waitFor: ['CheckMountsAllowed']
136 - name: 'gcr.io/cloud-builders/gcloud'
137 id: CleanUpVMWithMountsDenied
138 entrypoint: 'bash'
139 env:
140 - 'CLEANUP=$_CLEANUP'
141 args: ['cleanup.sh', '${_VM_NAME_PREFIX}-${BUILD_ID}-denied', '${_ZONE}']
142 waitFor: ['CheckMountsDenied']
143
144 # Must come after cleanup.
145 - name: 'gcr.io/cloud-builders/gcloud'
146 id: CheckFailure
147 entrypoint: 'bash'
148 env:
149 - 'BUILD_ID=$BUILD_ID'
150 args: ['check_failure.sh']