-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
2baebb9
try another sku with lower core counts
calvin197 684b605
Update vhd-scanning.sh
calvin197 c022464
clean up the test script
calvin197 994caa9
Update vhd-scanning.sh
calvin197 186484f
refactor
calvin197 6e26082
Update vhd-scanning.sh
calvin197 f85d958
Update fips-helper.sh
calvin197 2dda3f8
fix bug
calvin197 0399d50
Merge branch 'calvinsh/fips-2204-test' into markibrahim/enable-fips-2204
mxj220 30612c2
Add 2204 FIPS to sig config, tests, and build pipeline
mxj220 8b44033
convert script from bash to posix compatible
mxj220 c01eb31
add fips disclaimer
mxj220 e91b84d
typo
mxj220 f1073bc
pass vm size into fips helper script
mxj220 0763a82
Add error handling to fail faster
mxj220 1ef2126
typo
mxj220 46c5638
uppercase variable
mxj220 92cebe1
disable tracing for sensitive commands
mxj220 860c2a1
Add e2e for 2204 fips
mxj220 e25052f
remove e2e
mxj220 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| #!/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 | ||
mxj220 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| local az_register_exit_code=$? | ||
| if [ "$az_register_exit_code" -ne 0 ]; then | ||
| echo "Error: Failed to register FIPS 140-3 compliance feature (exit code: $az_register_exit_code)" >&2 | ||
| return "$az_register_exit_code" | ||
| fi | ||
|
|
||
| # 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 "Error: FIPS 140-3 feature registration timed out after ${TIMEOUT}s" >&2 | ||
| return 1 | ||
| fi | ||
|
|
||
| echo "FIPS 140-3 feature registered successfully. Refreshing provider..." | ||
| az provider register -n Microsoft.Compute | ||
| 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..." | ||
|
|
||
| # Disable tracing to prevent password from appearing in logs | ||
| set +x | ||
| # 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" | ||
mxj220 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
mxj220 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # Check for errors in the REST API call | ||
| local az_rest_exit_code=$? | ||
| # Re-enable tracing after sensitive command | ||
| set -x | ||
| 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 | ||
|
|
||
| # Wait for VM to be ready (timeout after 10 minutes) | ||
| echo "Waiting for VM to be ready..." | ||
| az vm wait --created --name $SCAN_VM_NAME --resource-group $RESOURCE_GROUP_NAME --timeout 600 | ||
|
|
||
| # Check for errors in the az wait command | ||
| local az_wait_exit_code=$? | ||
| if [ "$az_wait_exit_code" -ne 0 ]; then | ||
| echo "Error: Failed to await VM readiness (exit code: $az_wait_exit_code)" >&2 | ||
| return "$az_wait_exit_code" | ||
| fi | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.