Skip to content

Commit a4f6c18

Browse files
committed
address review comments
1 parent d700614 commit a4f6c18

File tree

4 files changed

+31
-24
lines changed

4 files changed

+31
-24
lines changed

launcher/image/preload.sh

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ readonly EXPERIMENTS_BINARY="confidential_space_experiments"
66
readonly GPU_REF_VALUES_PATH="${CS_PATH}/gpu"
77
readonly COS_GPU_INSTALLER_IMAGE_REF="${GPU_REF_VALUES_PATH}/cos_gpu_installer_image_ref"
88
readonly 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

1212
copy_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

181188
main() {

launcher/internal/gpu/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ const (
1010
// InstallerImageDigestFile is a filename which has the container image digest of cos_gpu_installer.
1111
InstallerImageDigestFile = "/usr/share/oem/confidential_space/gpu/cos_gpu_installer_image_digest"
1212
// ReferenceDriverDigestFile is a filename which has the reference digest of nvidia driver installer.
13-
ReferenceDriverDigestFile = "/usr/share/oem/confidential_space/gpu/driver_digest_sha256sum"
13+
ReferenceDriverDigestFile = "/usr/share/oem/confidential_space/gpu/driver_digest"
1414
)

launcher/internal/gpu/driverinstaller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func verifyDriverDigest(driverFile, referenceHash string) error {
220220
return err
221221
}
222222
if calculatedHash != referenceHash {
223-
return fmt.Errorf("gpu driver digest verification failed - expected : %s, got : %s", referenceHash, calculatedHash)
223+
return fmt.Errorf("GPU driver digest verification failed - expected : %s, got : %s", referenceHash, calculatedHash)
224224
}
225225
return nil
226226
}

launcher/internal/gpu/driverinstaller_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,14 +291,14 @@ func TestVerifyDriverDigest(t *testing.T) {
291291
driverDigest: "test-digest",
292292
refDriverDigest: "8edf273aa28919d86f9f0ab68b1f267280821a3251c281d19748f940c180d27a",
293293
wantErr: true,
294-
errSubstr: "gpu driver digest verification failed",
294+
errSubstr: "GPU driver digest verification failed",
295295
},
296296
{
297297
name: "Empty reference driver digest",
298298
driverDigest: "test-digest",
299299
refDriverDigest: "",
300300
wantErr: true,
301-
errSubstr: "gpu driver digest verification failed",
301+
errSubstr: "GPU driver digest verification failed",
302302
},
303303
{
304304
name: "Installed driver file does not exist",

0 commit comments

Comments
 (0)