Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: build cvm on cvm hardware #5643

Draft
wants to merge 53 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
8e759b4
fix: go dev container
May 2, 2024
afca2bb
revert
May 2, 2024
aa85e4c
feat: add cvm packer tempalte
Jan 15, 2025
30e2a62
feat: use cvm hardware for packer build
Jan 15, 2025
dfbfdec
feat: use cvm hardware for cvm build
Jan 15, 2025
e8f06e7
fix: replicate cvm images to blob storage
Jan 15, 2025
fff3b9b
fix: fix cvm kernel
Jan 15, 2025
d0fe202
fix: resolve vnet and vnet rg for cvm
Jan 15, 2025
6fb5dc2
fix: new image definition for cvm
Jan 15, 2025
16b4e20
fix: use cvm for scanning step
Jan 15, 2025
660c926
fix: scanning rg for cvm
Jan 15, 2025
f3fe319
Merge branch 'master' into zb/cvmKernelFix
Jan 15, 2025
0f1c36d
Merge branch 'zb/cvmKernelFix' into zb/fixCVMBuildCVE
Jan 15, 2025
dc39f15
fix: cvm build location
Jan 15, 2025
92a86c5
fix: set cvm packer build location for pro
Jan 15, 2025
3b063d1
fix: add cvm packer build location
Jan 15, 2025
b822f30
fix: provision cvm for testing step
Jan 15, 2025
e5e7459
fix: resolve azure location for cvm
Jan 15, 2025
4192ad5
fix: resolve location for converting to blob storage
Jan 15, 2025
9bcf631
fix: move vm options location
Jan 15, 2025
caa08c7
fix: location for standard skus
Jan 15, 2025
1703575
fix: dont use managed images for cvm
Jan 15, 2025
5eca9ab
Merge branch 'main' into zb/fixCVMBuildCVE
Jan 15, 2025
6f1858d
fix: cvm template
Jan 15, 2025
20f514f
fix: configure cvm packer template
Jan 15, 2025
0f4312e
fix: location issue for cvm
Jan 15, 2025
107453e
fix: use confidential vm sku
Jan 15, 2025
0e3961c
fix: vm sku
Jan 15, 2025
0d73b67
fix: cvm dist-upgrade
Jan 15, 2025
7262fc2
Merge branch 'main' into zb/fixCVMBuildCVE
Jan 16, 2025
a438ea0
fix: image definition
Jan 16, 2025
d986725
Merge branch 'main' into zb/fixCVMBuildCVE
Jan 17, 2025
328cba9
Merge branch 'main' into zb/fixCVMBuildCVE
Jan 21, 2025
f83dc3a
fix: test
Jan 21, 2025
fab3dc0
fix: re activate testing
Jan 21, 2025
d7bb220
Merge branch 'main' into zb/fixCVMBuildCVE
Jan 22, 2025
7af8cd2
Merge branch 'main' into zb/fixCVMBuildCVE
Jan 22, 2025
5d764ce
fix: typo fix
Jan 22, 2025
6c71814
fix: posix fix
Jan 22, 2025
07cfc03
Merge branch 'main' into zb/fixCVMBuildCVE
Jan 23, 2025
921a4a7
fix: posix standard
Jan 23, 2025
8f21f39
fix: simplify init variables
Jan 23, 2025
b6b366a
fix: bash syntax
Jan 23, 2025
dbd5dab
fix: cvm build location
Jan 23, 2025
3e478de
fix: resolving CVM_PACKER_BUILD_LOCATION var
Jan 23, 2025
8bcef29
fix: packer build location variable
Jan 23, 2025
a74fe0f
fix: bash steps
Jan 23, 2025
409bb6b
fix: separate steps
Jan 23, 2025
8a1e0e8
fix: bash
Jan 23, 2025
72cfc19
fix: ua token var
Jan 23, 2025
9965467
fix: PACKER_BUILD_LOCATION resolution
Jan 23, 2025
b7580de
fix: variable expansion
Jan 23, 2025
5763519
Merge branch 'main' into zb/fixCVMBuildCVE
Jan 23, 2025
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
2 changes: 1 addition & 1 deletion .pipelines/.vsts-vhd-builder-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ stages:
echo '##vso[task.setvariable variable=IMG_SKU]20_04-lts-cvm'
echo '##vso[task.setvariable variable=IMG_VERSION]latest'
echo '##vso[task.setvariable variable=HYPERV_GENERATION]V2'
echo '##vso[task.setvariable variable=AZURE_VM_SIZE]Standard_D16ds_v5'
echo '##vso[task.setvariable variable=AZURE_VM_SIZE]Standard_DC16ads_v5'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's make sure we have quota for this size

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cameronmeissner I was actually going to bring this up in standup today. I attempted to check in TME yesterday, but for some reason every time I tried to switch the directory it was unsuccessful.

echo '##vso[task.setvariable variable=FEATURE_FLAGS]None'
echo '##vso[task.setvariable variable=CONTAINER_RUNTIME]containerd'
echo '##vso[task.setvariable variable=ARCHITECTURE]X86_64'
Expand Down
6 changes: 6 additions & 0 deletions .pipelines/templates/.builder-release-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ steps:
echo "##vso[task.setvariable variable=SKU_NAME]$SKU_NAME"
echo "Set SKU_NAME to $SKU_NAME"
displayName: Set SKU Name

- bash: make -f packer.mk az-login && make -f packer.mk init-packer
displayName: Initialize Variables
env:
UA_TOKEN: $(ua-token)

- bash: make -f packer.mk run-packer
displayName: Build VHD
retryCountOnTaskFailure: 3
Expand Down
9 changes: 7 additions & 2 deletions packer.mk
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@ else
$(error HYPERV_GENERATION was invalid ${HYPERV_GENERATION})
endif
ifeq (${OS_SKU},Ubuntu)
@echo "Using packer template file: vhd-image-builder-base.json"
ifeq (${IMG_SKU},20_04-lts-cvm)
@echo "Using packer template file vhd-image-builder-cvm.json"
@packer build -var-file=vhdbuilder/packer/settings.json vhdbuilder/packer/vhd-image-builder-cvm.json
else
@echo "Using packer template file vhd-image-builder-base.json"
@packer build -var-file=vhdbuilder/packer/settings.json vhdbuilder/packer/vhd-image-builder-base.json
endif
else ifeq (${OS_SKU},CBLMariner)
@echo "Using packer template file vhd-image-builder-mariner.json"
@packer build -var-file=vhdbuilder/packer/settings.json vhdbuilder/packer/vhd-image-builder-mariner.json
Expand Down Expand Up @@ -80,7 +85,7 @@ init-packer:
@./vhdbuilder/packer/init-variables.sh

run-packer: az-login
@packer init ./vhdbuilder/packer/linux-packer-plugin.pkr.hcl && packer version && ($(MAKE) -f packer.mk init-packer | tee packer-output) && ($(MAKE) -f packer.mk build-packer | tee -a packer-output)
@packer init ./vhdbuilder/packer/linux-packer-plugin.pkr.hcl && packer version && ($(MAKE) -f packer.mk build-packer | tee -a packer-output)

run-packer-windows: az-login
@packer init ./vhdbuilder/packer/packer-plugin.pkr.hcl && packer version && ($(MAKE) -f packer.mk init-packer | tee packer-output) && ($(MAKE) -f packer.mk build-packer-windows | tee -a packer-output)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,21 @@ if [[ ${OS_TYPE} == "Linux" && ${ENABLE_TRUSTED_LAUNCH} == "True" ]]; then
} \
} \
}"
elif [ "${OS_TYPE}" == "Linux" ] && [ "${IMG_SKU,,}" == "20_04-lts-cvm" ]; then
az resource create --id $disk_resource_id --is-full-object --location $LOCATION --properties "{\"location\": \"$LOCATION\", \
\"properties\": { \
\"osType\": \"$OS_TYPE\", \
\"securityProfile\": { \
\"securityType\": \"ConfidentialVM_VMGuestStateOnlyEncryptedWithPlatformKey\" \
}, \
\"creationData\": { \
\"createOption\": \"FromImage\", \
\"galleryImageReference\": { \
\"id\": \"${sig_resource_id}\" \
} \
} \
} \
}"
else
az resource create --id $disk_resource_id --is-full-object --location $LOCATION --properties "{\"location\": \"$LOCATION\", \
\"properties\": { \
Expand Down
12 changes: 11 additions & 1 deletion vhdbuilder/packer/init-variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ if [ "$MODE" == "linuxVhdMode" ] && [ -z "${PACKER_BUILD_LOCATION}" ]; then
exit 1
fi

if [ "${IMG_SKU,,}" == "20_04-lts-cvm" ] && [ -n "${CVM_PACKER_BUILD_LOCATION}" ]; then
PACKER_BUILD_LOCATION=${CVM_PACKER_BUILD_LOCATION}
# Must persist new value of PACKER_BUILD_LOCATION for future pipeline steps, bash variable assignment is only scoped to this script
echo "##vso[task.setvariable variable=PACKER_BUILD_LOCATION]${CVM_PACKER_BUILD_LOCATION}"
echo "CVM: PACKER_BUILD_LOCATION is set to ${PACKER_BUILD_LOCATION}"
fi

# Currently only used for linux builds. This determines the environment in which the build is running (either prod or test).
# Used to construct the name of the resource group in which the 1ES pool the build is running on lives in, which also happens.
# to be the resource group in which the packer VNET lives in.
Expand Down Expand Up @@ -111,6 +118,7 @@ if [ -z "${VNET_NAME}" ]; then
fi
fi


if [ -z "${SUBNET_NAME}" ]; then
SUBNET_NAME="packer"
fi
Expand Down Expand Up @@ -167,6 +175,8 @@ if [[ "${MODE}" == "linuxVhdMode" ]]; then
elif [[ "${IMG_OFFER,,}" == "azure-linux-3" ]]; then
# for Azure Linux 3.0, only use AzureLinux prefix
SIG_IMAGE_NAME="AzureLinux${SIG_IMAGE_NAME}"
elif [[ "${IMG_SKU,,}" == "20_04-lts-cvm" ]]; then
SIG_IMAGE_NAME+="Specialized"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indenting seems weird here

fi
echo "No input for SIG_IMAGE_NAME was provided, defaulting to: ${SIG_IMAGE_NAME}"
else
Expand Down Expand Up @@ -259,7 +269,7 @@ if [[ "$MODE" == "linuxVhdMode" || "$MODE" == "windowsVhdMode" ]]; then
if [[ ${ARCHITECTURE,,} == "arm64" ]]; then
TARGET_COMMAND_STRING+="--architecture Arm64"
elif [[ ${IMG_SKU} == "20_04-lts-cvm" ]]; then
TARGET_COMMAND_STRING+="--features SecurityType=ConfidentialVMSupported"
TARGET_COMMAND_STRING+="--os-state Specialized --features SecurityType=ConfidentialVM"
fi

az sig image-definition create \
Expand Down
30 changes: 6 additions & 24 deletions vhdbuilder/packer/pre-install-dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,32 +92,14 @@ else
set -x
fi

# Run apt get update to refresh repo list
# Run apt dist get upgrade to install packages/kernels

# CVM breaks on kernel image updates due to nullboot package post-install.
# it relies on boot measurements from real tpm hardware.
# building on a real CVM would solve this, but packer doesn't support it.
# we could make upstream changes but that takes time, and we are broken now.
# so we just hold the kernel image packages for now on CVM.
# this still allows us base image and package updates on a weekly cadence.
if [[ "$IMG_SKU" != "20_04-lts-cvm" ]]; then
# Canonical snapshot is only implemented for 20.04 LTS, 22.04 LTS and 23.10 and above
# For 20.04, the only SKUs we support are FIPS, and it reaches out to ESM to get the packages, ESM does not have canonical snapshot support
# Therefore keeping this to 22.04 only for now
if [[ -n "${VHD_BUILD_TIMESTAMP}" && "${OS_VERSION}" == "22.04" ]]; then
sed -i "s#http://azure.archive.ubuntu.com/ubuntu/#https://snapshot.ubuntu.com/ubuntu/${VHD_BUILD_TIMESTAMP}#g" /etc/apt/sources.list
fi
apt_get_update || exit $ERR_APT_UPDATE_TIMEOUT
apt_get_dist_upgrade || exit $ERR_APT_DIST_UPGRADE_TIMEOUT
if [[ -n "${VHD_BUILD_TIMESTAMP}" && "${OS_VERSION}" == "22.04" ]]; then
sed -i "s#http://azure.archive.ubuntu.com/ubuntu/#https://snapshot.ubuntu.com/ubuntu/${VHD_BUILD_TIMESTAMP}#g" /etc/apt/sources.list
fi

if [[ "$IMG_SKU" == "20_04-lts-cvm" ]]; then
# Can not currently update kernel in CVM builds due to nullboot post-installation failure when no TPM is present on the VM
# But we can at least update/install the below packages
apt_get_update || exit $ERR_APT_UPDATE_TIMEOUT
apt-get -y install libpython3.8 python3.8-minimal libpython3.8-minimal libpython3.8-stdlib python3.8 libglib2.0-0 libglib2.0-data libglib2.0-bin python3-urllib3 libpython2.7-stdlib libpython2.7-stdlib python2.7-minimal libpython2.7-minimal nano libarchive13
fi
# Run apt get update to refresh repo list
# Run apt dist get upgrade to install packages/kernels
apt_get_update || exit $ERR_APT_UPDATE_TIMEOUT
apt_get_dist_upgrade || exit $ERR_APT_DIST_UPGRADE_TIMEOUT

if [[ "${ENABLE_FIPS,,}" == "true" ]]; then
# This is FIPS Install for Ubuntu, it purges non FIPS Kernel and attaches UA FIPS Updates
Expand Down
6 changes: 5 additions & 1 deletion vhdbuilder/packer/test/run-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if [ "${OS_TYPE,,}" == "linux" ]; then
echo "PACKER_BUILD_LOCATION must be set for linux builds"
exit 1
fi
AZURE_LOCATION=$PACKER_BUILD_LOCATION
AZURE_LOCATION=${PACKER_BUILD_LOCATION}
fi

if [ "${OS_TYPE,,}" == "linux" ]; then
Expand Down Expand Up @@ -75,6 +75,10 @@ if [ "${OS_TYPE}" == "Linux" ] && [ "${ENABLE_TRUSTED_LAUNCH}" == "True" ]; then
TARGET_COMMAND_STRING+="--security-type TrustedLaunch --enable-secure-boot true --enable-vtpm true"
fi

if [ "${OS_TYPE}" == "Linux" ] && [ ${IMG_SKU} == "20_04-lts-cvm" ]; then
TARGET_COMMAND_STRING="--size Standard_DC8ads_v5 --security-type ConfidentialVM --enable-secure-boot true --enable-vtpm true --os-disk-security-encryption-type VMGuestStateOnly --specialized true"
fi

if [ "${OS_TYPE,,}" == "linux" ]; then
# in linux mode, explicitly create the NIC referencing the existing packer subnet to be attached to the testing VM so we avoid creating ephemeral vnets
PACKER_SUBNET_ID="/subscriptions/${SUBSCRIPTION_ID}/resourceGroups/${PACKER_VNET_RESOURCE_GROUP_NAME}/providers/Microsoft.Network/virtualNetworks/${PACKER_VNET_NAME}/subnets/packer"
Expand Down
Loading
Loading