@@ -6,8 +6,8 @@ readonly EXPERIMENTS_BINARY="confidential_space_experiments"
66readonly GPU_REF_VALUES_PATH=" ${CS_PATH} /gpu"
77readonly COS_GPU_INSTALLER_IMAGE_REF=" ${GPU_REF_VALUES_PATH} /cos_gpu_installer_image_ref"
88readonly COS_GPU_INSTALLER_IMAGE_DIGEST=" ${GPU_REF_VALUES_PATH} /cos_gpu_installer_image_digest"
9- readonly DRIVER_DIGEST_SHA256SUM =" ${GPU_REF_VALUES_PATH} /driver_digest_sha256sum "
10- readonly DRIVERS_GCS_BUCKET =" cos-nvidia-gpu-drivers"
9+ readonly DRIVER_DIGEST =" ${GPU_REF_VALUES_PATH} /driver_digest "
10+ readonly DRIVER_GCS_BUCKET =" cos-nvidia-gpu-drivers"
1111
1212copy_launcher () {
1313 cp launcher " ${CS_PATH} /cs_container_launcher"
@@ -128,24 +128,35 @@ get_cos_gpu_installer_image_digest() {
128128 echo " ${image_digest} "
129129}
130130
131- set_reference_driver_digest () {
131+ validate_sha256_hex () {
132+ driver_digest=" ${1} "
133+ # Check for the expected length of the SHA256 digest (64 hex characters)
134+ if [ ${# driver_digest} -ne 64 ]; then
135+ echo " Error: driver digest has an unexpected length: ${# driver_digest} , Expected 64." >&2
136+ return 1
137+ fi
138+ # Check for valid hexadecimal string
139+ if [[ ! ${driver_digest} =~ ^[0-9a-fA-F]+$ ]]; then
140+ return " Error: driver digest ${driver_digest} is not a valid hexadecimal string." >&2
141+ return 1
142+ fi
143+ }
144+
145+ store_driver_digest () {
146+ local gpu_type=" ${1} "
132147 local driver_version
133148 local driver_digest_gcs_url
134149
135- # Fetching the default driver version for H100 GPU.
136- driver_version=$( cos-extensions list -- --target-gpu NVIDIA_H100_80GB | grep DEFAULT | cut -d" " -f 1)
137- driver_digest_gcs_url=" https://storage.googleapis.com/${DRIVERS_GCS_BUCKET } /sha256/NVIDIA-Linux-x86_64-${driver_version} .run.sha256"
138- if ! curl -sSL ${driver_digest_gcs_url} -o ${DRIVER_DIGEST_SHA256SUM } ; then
150+ # Fetching the default driver version for the given GPU.
151+ driver_version=$( cos-extensions list -- --target-gpu ${gpu_type} | grep DEFAULT | cut -d" " -f 1)
152+ driver_digest_gcs_url=" https://storage.googleapis.com/${DRIVER_GCS_BUCKET } /sha256/NVIDIA-Linux-x86_64-${driver_version} .run.sha256"
153+ if ! curl -sSL ${driver_digest_gcs_url} -o ${DRIVER_DIGEST } ; then
139154 echo " Error: failed to download the driver digest file from ${driver_digest_gcs_url} ." >&2
140155 return 1
141156 fi
142157
143- driver_digest=$( cat ${DRIVER_DIGEST_SHA256SUM} | cut -d " " -f 1)
144- # Check for the expected length of the SHA256 digest (64 hex characters)
145- if [ ${# driver_digest} -ne 64 ]; then
146- echo " Error: driver digest has an unexpected length: ${# driver_digest} , Expected 64." >&2
147- return 1
148- fi
158+ driver_digest=$( cat ${DRIVER_DIGEST} | cut -d " " -f 1)
159+ validate_sha256_hex ${driver_digest}
149160}
150161
151162
@@ -161,21 +172,17 @@ set_gpu_driver_ref_values() {
161172 fi
162173
163174 cos_gpu_installer_image_digest=$( get_cos_gpu_installer_image_digest ${cos_gpu_installer_image_ref} )
164- if [ -z " ${cos_gpu_installer_image_ref } " ]; then
175+ if [ -z " ${cos_gpu_installer_image_digest } " ]; then
165176 echo " Error: get_cos_gpu_installer_image_digest returned an empty or invalid digest for: ${cos_gpu_installer_image_ref} ." >&2
166177 return 1
167178 fi
168179
169180 image_digest_hex_part=$( echo " ${cos_gpu_installer_image_digest} " | sed ' s/^sha256://' | tr -d ' [:space:]' )
170- # Check for the expected length of the SHA256 digest (64 hex characters)
171- if [ ${# image_digest_hex_part} -ne 64 ]; then
172- echo " Error: cos_gpu_installer image digest has an unexpected length: ${# image_digest_hex_part} , Expected 64." >&2
173- return 1
174- fi
181+ validate_sha256_hex ${image_digest_hex_part}
175182
176183 echo ${cos_gpu_installer_image_ref} > ${COS_GPU_INSTALLER_IMAGE_REF}
177184 echo ${cos_gpu_installer_image_digest} > ${COS_GPU_INSTALLER_IMAGE_DIGEST}
178- set_reference_driver_digest
185+ store_driver_digest " NVIDIA_H100_80GB "
179186}
180187
181188main () {
0 commit comments