-
Notifications
You must be signed in to change notification settings - Fork 244
feat: add Ubuntu 22.04 FIPS VHDs #7721
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
base: main
Are you sure you want to change the base?
Changes from all commits
2baebb9
684b605
c022464
994caa9
186484f
6e26082
f85d958
2dda3f8
0399d50
30612c2
8b44033
c01eb31
e91b84d
f1073bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,125 @@ | ||||||||||||||||
| #!/bin/bash | ||||||||||||||||
| # FIPS Helper Functions for VHD Scanning | ||||||||||||||||
|
|
||||||||||||||||
| # FIPS 140-3 encryption is not automatically supported in Linux VMs. | ||||||||||||||||
| # Because not all extensions are onboarded to FIPS 140-3 yet, subscriptions must register the Microsoft.Compute/OptInToFips1403Compliance feature. | ||||||||||||||||
| # After registering the feature, the VM must be created via Azure REST API calls to enable support for FIPS 140-3. | ||||||||||||||||
| # There is currently no ETA for when FIPS 140-3 encryption is natively supported, but all information can be found here: https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/agent-linux-fips | ||||||||||||||||
|
|
||||||||||||||||
| # This script contains functions related to FIPS 140-3 compliance for Ubuntu 22.04 | ||||||||||||||||
|
|
||||||||||||||||
mxj220 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
| # Function to ensure FIPS 140-3 compliance feature is registered | ||||||||||||||||
mxj220 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
| ensure_fips_feature_registered() { | ||||||||||||||||
| echo "Detected Ubuntu 22.04 + FIPS scenario, enabling FIPS 140-3 compliance..." | ||||||||||||||||
|
|
||||||||||||||||
| # Enable FIPS 140-3 compliance feature if not already enabled | ||||||||||||||||
| echo "Checking FIPS 140-3 compliance feature registration..." | ||||||||||||||||
| FIPS_FEATURE_STATE=$(az feature show --namespace Microsoft.Compute --name OptInToFips1403Compliance --query 'properties.state' -o tsv 2>/dev/null || echo "NotRegistered") | ||||||||||||||||
mxj220 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
|
|
||||||||||||||||
| if [ "$FIPS_FEATURE_STATE" != "Registered" ]; then | ||||||||||||||||
| echo "Registering FIPS 140-3 compliance feature..." | ||||||||||||||||
| az feature register --namespace Microsoft.Compute --name OptInToFips1403Compliance | ||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is we get that the feature is not available ? we will poll and retry ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently it will try for 5 min, time out, and echo a warning before continuing. This means it will attempt to create the vm without the feature, which will fail. |
||||||||||||||||
|
|
||||||||||||||||
| # Poll until registered (timeout after 5 minutes) | ||||||||||||||||
| local TIMEOUT=300 | ||||||||||||||||
| local ELAPSED=0 | ||||||||||||||||
| while [ "$FIPS_FEATURE_STATE" != "Registered" ] && [ $ELAPSED -lt $TIMEOUT ]; do | ||||||||||||||||
| sleep 10 | ||||||||||||||||
| ELAPSED=$((ELAPSED + 10)) | ||||||||||||||||
| FIPS_FEATURE_STATE=$(az feature show --namespace Microsoft.Compute --name OptInToFips1403Compliance --query 'properties.state' -o tsv) | ||||||||||||||||
| echo "Feature state: $FIPS_FEATURE_STATE (waited ${ELAPSED}s)" | ||||||||||||||||
| done | ||||||||||||||||
|
|
||||||||||||||||
| if [ "$FIPS_FEATURE_STATE" != "Registered" ]; then | ||||||||||||||||
| echo "Warning: FIPS 140-3 feature registration timed out. Continuing anyway..." | ||||||||||||||||
| else | ||||||||||||||||
| echo "FIPS 140-3 feature registered successfully. Refreshing provider..." | ||||||||||||||||
| az provider register -n Microsoft.Compute | ||||||||||||||||
| fi | ||||||||||||||||
| else | ||||||||||||||||
| echo "FIPS 140-3 compliance feature already registered" | ||||||||||||||||
| fi | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| # Function to build FIPS-enabled VM request body | ||||||||||||||||
| build_fips_vm_body() { | ||||||||||||||||
| local location="$1" | ||||||||||||||||
| local vm_name="$2" | ||||||||||||||||
| local admin_username="$3" | ||||||||||||||||
| local admin_password="$4" | ||||||||||||||||
| local image_id="$5" | ||||||||||||||||
| local nic_id="$6" | ||||||||||||||||
| local umsi_resource_id="$7" | ||||||||||||||||
| local vm_size="$8" | ||||||||||||||||
|
|
||||||||||||||||
| cat <<EOF | ||||||||||||||||
| { | ||||||||||||||||
| "location": "$location", | ||||||||||||||||
| "identity": { | ||||||||||||||||
| "type": "UserAssigned", | ||||||||||||||||
| "userAssignedIdentities": { | ||||||||||||||||
| "$umsi_resource_id": {} | ||||||||||||||||
| } | ||||||||||||||||
| }, | ||||||||||||||||
| "properties": { | ||||||||||||||||
| "additionalCapabilities": { | ||||||||||||||||
| "enableFips1403Encryption": true | ||||||||||||||||
mxj220 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
| }, | ||||||||||||||||
| "hardwareProfile": { | ||||||||||||||||
| "vmSize": "$vm_size" | ||||||||||||||||
| }, | ||||||||||||||||
| "osProfile": { | ||||||||||||||||
| "computerName": "$vm_name", | ||||||||||||||||
| "adminUsername": "$admin_username", | ||||||||||||||||
| "adminPassword": "$admin_password" | ||||||||||||||||
| }, | ||||||||||||||||
| "storageProfile": { | ||||||||||||||||
| "imageReference": { | ||||||||||||||||
| "id": "$image_id" | ||||||||||||||||
| }, | ||||||||||||||||
| "osDisk": { | ||||||||||||||||
| "createOption": "FromImage", | ||||||||||||||||
| "diskSizeGB": 50, | ||||||||||||||||
| "managedDisk": { | ||||||||||||||||
| "storageAccountType": "Premium_LRS" | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
| }, | ||||||||||||||||
| "networkProfile": { | ||||||||||||||||
| "networkInterfaces": [ | ||||||||||||||||
| { | ||||||||||||||||
| "id": "$nic_id" | ||||||||||||||||
| } | ||||||||||||||||
| ] | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
| EOF | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| # Function to create FIPS-enabled VM using REST API | ||||||||||||||||
| create_fips_vm() { | ||||||||||||||||
| local vm_size="$1" | ||||||||||||||||
| echo "Creating VM with FIPS 140-3 encryption using REST API..." | ||||||||||||||||
|
|
||||||||||||||||
| # Build the VM request body for FIPS scenario | ||||||||||||||||
| local VM_BODY=$(build_fips_vm_body \ | ||||||||||||||||
| "$PACKER_BUILD_LOCATION" \ | ||||||||||||||||
| "$SCAN_VM_NAME" \ | ||||||||||||||||
| "$SCAN_VM_ADMIN_USERNAME" \ | ||||||||||||||||
| "$SCAN_VM_ADMIN_PASSWORD" \ | ||||||||||||||||
| "$VHD_IMAGE" \ | ||||||||||||||||
| "$SCANNING_NIC_ID" \ | ||||||||||||||||
| "$UMSI_RESOURCE_ID" \ | ||||||||||||||||
| "$vm_size") | ||||||||||||||||
|
|
||||||||||||||||
| # Create the VM using REST API | ||||||||||||||||
| az rest \ | ||||||||||||||||
| --method put \ | ||||||||||||||||
| --url "https://management.azure.com/subscriptions/${SUBSCRIPTION_ID}/resourceGroups/${RESOURCE_GROUP_NAME}/providers/Microsoft.Compute/virtualMachines/${SCAN_VM_NAME}?api-version=2024-11-01" \ | ||||||||||||||||
| --body "$VM_BODY" | ||||||||||||||||
|
Comment on lines
+106
to
+120
|
||||||||||||||||
|
|
||||||||||||||||
|
||||||||||||||||
| local az_rest_exit_code=$? | |
| if [ "$az_rest_exit_code" -ne 0 ]; then | |
| echo "Error: Failed to create VM with FIPS 140-3 encryption via REST API (exit code: $az_rest_exit_code)" >&2 | |
| return "$az_rest_exit_code" | |
| fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a timeout for this wait command ? could we make is explicit on the CLI so we know what it is form code inspection ?
Also, should we catch timeout cases, and return an error code and error message that that VM was never created ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- default timeout is 1h and can be explicitly set. Would a shorter time ~30min be better?
- the existing vm creation pattern in vhd-scanning.sh only attempts to create the vm and does not have any error handling. I can look into catching the timeout case for the fips vm though.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,19 +74,22 @@ function cleanup() { | |
| trap cleanup EXIT | ||
| capture_benchmark "${SCRIPT_NAME}_set_variables_and_create_scan_resource_group" | ||
|
|
||
| VM_OPTIONS="--size Standard_D8ds_v5" | ||
| VM_SIZE="Standard_D8ds_v5" | ||
| VM_OPTIONS="--size $VM_SIZE" | ||
| # shellcheck disable=SC3010 | ||
| if [[ "${ARCHITECTURE,,}" == "arm64" ]]; then | ||
| VM_OPTIONS="--size Standard_D8pds_v5" | ||
| VM_SIZE="Standard_D8pds_v5" | ||
| VM_OPTIONS="--size $VM_SIZE" | ||
| fi | ||
|
|
||
| if [ "${OS_TYPE}" = "Linux" ] && [ "${ENABLE_TRUSTED_LAUNCH}" = "True" ]; then | ||
| VM_OPTIONS+=" --security-type TrustedLaunch --enable-secure-boot true --enable-vtpm true" | ||
| fi | ||
|
|
||
| if [ "${OS_TYPE}" = "Linux" ] && grep -q "cvm" <<< "$FEATURE_FLAGS"; then | ||
| VM_SIZE="Standard_DC8ads_v5" | ||
| # We completely re-assign the VM_OPTIONS string here to ensure that no artifacts from earlier conditionals are included | ||
| VM_OPTIONS="--size Standard_DC8ads_v5 --security-type ConfidentialVM --enable-secure-boot true --enable-vtpm true --os-disk-security-encryption-type VMGuestStateOnly --specialized true" | ||
| VM_OPTIONS="--size $VM_SIZE --security-type ConfidentialVM --enable-secure-boot true --enable-vtpm true --os-disk-security-encryption-type VMGuestStateOnly --specialized true" | ||
| fi | ||
|
|
||
| # GB200 specific VM options for scanning (uses standard ARM64 VM for now) | ||
|
|
@@ -101,15 +104,30 @@ if [ -z "$SCANNING_NIC_ID" ]; then | |
| exit 1 | ||
| fi | ||
|
|
||
| az vm create --resource-group $RESOURCE_GROUP_NAME \ | ||
| --name $SCAN_VM_NAME \ | ||
| --image $VHD_IMAGE \ | ||
| --nics $SCANNING_NIC_ID \ | ||
| --admin-username $SCAN_VM_ADMIN_USERNAME \ | ||
| --admin-password $SCAN_VM_ADMIN_PASSWORD \ | ||
| --os-disk-size-gb 50 \ | ||
| ${VM_OPTIONS} \ | ||
| --assign-identity "${UMSI_RESOURCE_ID}" | ||
| # Create VM using appropriate method based on scenario | ||
| if [ "${OS_SKU}" = "Ubuntu" ] && [ "${OS_VERSION}" = "22.04" ] && [ "$(printf %s "${ENABLE_FIPS}" | tr '[:upper:]' '[:lower:]')" = "true" ]; then | ||
mxj220 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # Source the FIPS helper functions | ||
| FULL_PATH=$(realpath $0) | ||
| CDIR=$(dirname $FULL_PATH) | ||
| source "$CDIR/fips-helper.sh" | ||
|
|
||
| # Register FIPS feature and create VM using REST API | ||
| ensure_fips_feature_registered | ||
| create_fips_vm "$VM_SIZE" | ||
| else | ||
| echo "Creating VM using standard az vm create command..." | ||
|
|
||
| # Use the standard VM creation approach for all other scenarios | ||
| az vm create --resource-group $RESOURCE_GROUP_NAME \ | ||
| --name $SCAN_VM_NAME \ | ||
| --image $VHD_IMAGE \ | ||
| --nics $SCANNING_NIC_ID \ | ||
| --admin-username $SCAN_VM_ADMIN_USERNAME \ | ||
| --admin-password $SCAN_VM_ADMIN_PASSWORD \ | ||
| --os-disk-size-gb 50 \ | ||
|
Comment on lines
+121
to
+127
|
||
| ${VM_OPTIONS} \ | ||
| --assign-identity "${UMSI_RESOURCE_ID}" | ||
| fi | ||
|
|
||
| capture_benchmark "${SCRIPT_NAME}_create_scan_vm" | ||
| set +x | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.