Skip to content
This repository has been archived by the owner on Oct 24, 2023. It is now read-only.

fix: parse SGX driver url and compare checksum #2914

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions parts/k8s/cloud-init/artifacts/cse_helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ ERR_GPU_DRIVERS_START_FAIL=84 {{/* nvidia-modprobe could not be started by syste
ERR_GPU_DRIVERS_INSTALL_TIMEOUT=85 {{/* Timeout waiting for GPU drivers install */}}
ERR_SGX_DRIVERS_INSTALL_TIMEOUT=90 {{/* Timeout waiting for SGX prereqs to download */}}
ERR_SGX_DRIVERS_START_FAIL=91 {{/* Failed to execute SGX driver binary */}}
ERR_SGX_DRIVERS_NOT_SUPPORTED=92 {{/* SGX is not supported */}}
ERR_APT_DAILY_TIMEOUT=98 {{/* Timeout waiting for apt daily updates */}}
ERR_APT_UPDATE_TIMEOUT=99 {{/* Timeout waiting for apt-get update to complete */}}
ERR_CSE_PROVISION_SCRIPT_NOT_READY_TIMEOUT=100 {{/* Timeout waiting for cloud-init to place this script on the vm */}}
Expand Down
54 changes: 31 additions & 23 deletions parts/k8s/cloud-init/artifacts/cse_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,31 +112,39 @@ installGPUDrivers() {
}

installSGXDrivers() {
local URL
case $UBUNTU_RELEASE in
"18.04")
URL="https://download.01.org/intel-sgx/latest/dcap-latest/linux/distro/ubuntuServer18.04/sgx_linux_x64_driver_1.21.bin"
;;
"16.04")
URL="https://download.01.org/intel-sgx/latest/dcap-latest/linux/distro/ubuntuServer16.04/sgx_linux_x64_driver_1.21.bin"
;;
"*")
exit $ERR_SGX_DRIVERS_INSTALL_TIMEOUT
;;
esac

local PACKAGES="make gcc dkms"
wait_for_apt_locks
retrycmd_if_failure 30 5 3600 apt-get -y install $PACKAGES || exit $ERR_SGX_DRIVERS_INSTALL_TIMEOUT
[[ "$UBUNTU_RELEASE" == "18.04" || "$UBUNTU_RELEASE" == "16.04" ]] || exit $ERR_SGX_DRIVERS_NOT_SUPPORTED

local DRIVER
DRIVER=$(basename $URL)
local OE_DIR=/opt/azure/containers/oe
mkdir -p ${OE_DIR}
local packages="make gcc dkms"
wait_for_apt_locks
retrycmd_if_failure 30 5 3600 apt-get -y install "$packages" || exit $ERR_SGX_DRIVERS_INSTALL_TIMEOUT

local oe_dir=/opt/azure/containers/oe
rm -rf ${oe_dir}
mkdir -p ${oe_dir}
pushd ${oe_dir} || exit
sgx_driver_folder_url="https://download.01.org/intel-sgx/latest/dcap-latest/linux"
retrycmd_if_failure 10 10 120 wget -r -l1 --no-parent -nd -A "SHA256SUM_dcap*" "${sgx_driver_folder_url}" || exit $ERR_SGX_DRIVERS_INSTALL_TIMEOUT
matched_line="$(grep "distro/ubuntuServer$UBUNTU_RELEASE/sgx_linux_x64_driver_.*bin" SHA256SUM_dcap*)"
read -ra tmp_array <<< "$matched_line"
sgx_driver_sha256sum_expected="${tmp_array[0]}"
sgx_driver_remote_path="${tmp_array[1]}"
sgx_driver_url="${sgx_driver_folder_url}/${sgx_driver_remote_path}"
sgx_driver=$(basename "$sgx_driver_url")

retrycmd_if_failure 10 10 120 curl -fsSL -O "${sgx_driver_url}" || exit $ERR_SGX_DRIVERS_INSTALL_TIMEOUT
read -ra tmp_array <<< "$(sha256sum ./"$sgx_driver")"
sgx_driver_sha256sum_real="${tmp_array[0]}"
if [ "$sgx_driver_sha256sum_real" != "$sgx_driver_sha256sum_expected" ]; then
echo "Downloaded SGX driver sha256sum $sgx_driver_sha256sum_real does not match the expected value $sgx_driver_sha256sum_expected"
fi

retrycmd_if_failure 120 5 25 curl -fsSL ${URL} -o ${OE_DIR}/${DRIVER} || exit $ERR_SGX_DRIVERS_INSTALL_TIMEOUT
chmod a+x ${OE_DIR}/${DRIVER}
${OE_DIR}/${DRIVER} || exit $ERR_SGX_DRIVERS_START_FAIL
chmod a+x ./"${sgx_driver}"
if ! ./"${sgx_driver}"; then
popd || exit
exit $ERR_SGX_DRIVERS_START_FAIL
fi
popd || exit
rm -rf ${oe_dir}
}

installContainerRuntime() {
Expand Down
55 changes: 32 additions & 23 deletions pkg/engine/templates_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.