在 Azure 上佈建 Fedora CoreOS
本指南說明如何在 Azure 上佈建新的 Fedora CoreOS(FCOS)節點。Fedora 目前不會直接在 Azure 中發布 Fedora CoreOS 映像檔,因此您必須從 Fedora 下載 Azure 映像檔,再上傳至您的 Azure 訂用帳戶。
| FCOS 不支援舊式的 Azure Service Manager 虛擬機器。 |
先決條件
Fedora CoreOS 支援在此平台透過 Afterburn 使用 SSH 金鑰設定存取權。只要已在平台設定中設定 SSH 金鑰,就能使用預設使用者 core 佈建並存取 Fedora CoreOS 執行個體,而不需要 Ignition 組態。
熟悉 Fedora CoreOS 並希望自動化系統部署後,建議改用 Ignition 設定。
您需要能夠存取 Azure 訂用帳戶。以下範例使用 Azure CLI。
下載 Azure 映像檔
Fedora CoreOS 設計為自動更新,不同更新串流具有不同排程。選定適合的串流後,請下載、驗證並解壓縮最新的 Azure 映像檔:
STREAM="stable"
coreos-installer download --decompress -s $STREAM -p azure -f vhd.xz
或者,您也可以從 下載頁面手動下載 Azure 映像檔。請依照該頁面的指示驗證下載內容,然後解壓縮。
將映像檔上傳至 Azure
-
建立 Azure 帳戶中尚未存在的必要資源:
建立 Azure 資源的範例az_region="westus2" az_resource_group="my-group" az_storage_account="mystorageacct" az_container="my-container" # Create resource group az group create -l "${az_region}" -n "${az_resource_group}" # Create storage account for uploading FCOS image az storage account create -g "${az_resource_group}" -n "${az_storage_account}" # Retrieve connection string for storage account cs=$(az storage account show-connection-string -n "${az_storage_account}" -g "${az_resource_group}" | jq -r .connectionString) # Create storage container for uploading FCOS image az storage container create --connection-string "${cs}" -n "${az_container}" -
建立 FCOS 映像檔:
建立 Azure 映像檔的範例downloaded_image_file="./image.vhd" az_image_name="my-fcos-image" az_image_blob="${az_image_name}.vhd" # Upload image blob az storage blob upload --connection-string "${cs}" -c "${az_container}" -f "${downloaded_image_file}" -n "${az_image_blob}" # Create the image az image create -n "${az_image_name}" -g "${az_resource_group}" --source "https://${az_storage_account}.blob.core.windows.net/${az_container}/${az_image_blob}" --location "${az_region}" --os-type Linux # Delete the uploaded blob az storage blob delete --connection-string "$cs" -c "${az_container}" -n "${az_image_blob}"
使用 custom-data 啟動 VM 執行個體
-
啟動 VM。您可以將 Ignition 設定以 custom data 傳給 VM;如果只需要 SSH 存取,也可以略過 custom data。系統會自動將
~/.ssh中的 SSH 公開金鑰加入 VM。如此一來,即使尚未建立 Ignition 設定,也能方便地測試 FCOS。啟動 Azure 映像檔的範例az_vm_name="my-fcos-vm" ignition_path="./config.ign" az vm create -n "${az_vm_name}" -g "${az_resource_group}" --image "${az_image_name}" --admin-username core --custom-data "$(cat ${ignition_path})" -
現在您應該可以使用相關聯的 IP 位址,透過 SSH 連線至該執行個體。
連線範例ssh core@<ip address>
使用 custom-data 與私人 Azure Blob 啟動 VM 執行個體
-
定義 VM 名稱與 Ignition 設定的變數:
定義變數az_vm_name=my-fcos-vm ignition_path="./config.ign" az_blob_ignition_path=./privateConfig.ign az_blob_ignition_file_name=privateConfig.ign將 ign 檔案上傳至 Azure Blob 儲存體az storage blob upload --connection-string "${cs}" -c "${az_blob_ignition_file_name}" -f "${az_blob_ignition_path}" -n "${ignition_file_name}" -
建立遠端 Ignition 設定以參照這個新的 Blob。相關說明請參閱 使用遠端 Ignition 設定。
-
建立身分識別,並授予其適當的儲存體帳戶存取權:
az identity create --name "${az_vm_name}-identity" --resource-group "${az_resource_group}" identity_principal_id=$(az identity show --name "${az_vm_name}-identity" --resource-group "${az_resource_group}" --query principalId -o tsv) identity_id=$(az identity show --name "${az_vm_name}-identity" --resource-group "${az_resource_group}" --query id -o tsv) az role assignment create --assignee "${identity_principal_id}" --role "Storage Blob Data Contributor" --scope /subscriptions/${subscription_id}/resourceGroups/${az_resource_group}/providers/Microsoft.Storage/storageAccounts/${az_storage_account}建立 VM,並傳入新的身分識別az vm create -n "${az_vm_name}" -g "${az_resource_group}" --image "${az_image_name}" --admin-username core --custom-data "$(cat ${ignition_path})" --assign-identity "${identity_id}"
啟動機密 VM 執行個體
| Fedora CoreOS 對機密運算(Confidential Computing)的支援仍在開發中。 請參閱 issue #1719。 |
| 若要瞭解 Azure 機密 VM 的概觀,請參閱 機密 VM 概觀。 |
若要啟動機密 VM,需要在 Azure Compute Gallery 中建立支援機密運算的映像檔。
# Create an image gallery
gallery_name="mygallery"
az sig create --resource-group "${az_resource_group}" --gallery-name "${gallery_name}"
# Create a gallery image definition
gallery_image_definition="mygallery-def"
az sig image-definition create \
--resource-group "${az_resource_group}" \
--gallery-name "${gallery_name}" \
--gallery-image-definition "${gallery_image_definition}" \
--publisher azure \
--offer example \
--sku standard \
--features SecurityType=ConfidentialVmSupported \
--os-type Linux \
--hyper-v-generation V2
# Get the source VHD URI of OS disk
os_vhd_storage_account=$(az storage account list -g ${az_resource_group} | jq -r .[].id)
# Create a new image version
gallery_image_version="1.0.0"
az sig image-version create \
--resource-group "${az_resource_group}" \
--gallery-name "${gallery_name}" \
--gallery-image-definition "${gallery_image_definition}" \
--gallery-image-version "${gallery_image_version}" \
--os-vhd-storage-account "${os_vhd_storage_account}" \
--os-vhd-uri https://${az_storage_account}.blob.core.windows.net/${az_container}/${az_image_blob}
若要啟動機密 FCOS 執行個體,您需要指定機密運算類型,並使用支援機密運算的 機器類型。
在命令列中,請使用 --security-type ConfidentialVM 與 --size。
vm_name="my-fcos-cvm"
ignition_path="./config.ign"
# Specify a size that supports confidential computing (using AMD SEV-SNP for example)
vm_size="Standard_DC2as_v5"
# Get gallery image id
gallery_image_id=$(az sig image-version show --gallery-image-definition "${gallery_image_definition}" --gallery-image-version "${gallery_image_version}" --gallery-name "${gallery_name}" --resource-group $az_resource_group | jq -r .id)
# Create a VM with confidential computing enabled using the gallery image and an ignition config as custom-data
az vm create \
--name "${vm_name}" \
--resource-group $az_resource_group \
--size "${vm_size}" \
--image "${gallery_image_id}" \
--admin-username core \
--generate-ssh-keys \
--custom-data "$(cat ${ignition_path})" \
--enable-vtpm true \
--public-ip-sku Standard \
--security-type ConfidentialVM \
--os-disk-security-encryption-type VMGuestStateOnly \
--enable-secure-boot true
我們會傳入 --enable-secure-boot true 參數來啟用安全開機(Secure Boot)。若要停用安全開機,請使用 false。
|
若要取得完整的主控台紀錄,請附加參數 --boot-diagnostics-storage ${az_storage_account}。
|
ssh core@<ip address>
# Confirm the VM is using `AMD SEV-SNP` confidential type
sudo systemd-detect-virt --cvm
sev-snp
# Confirm the VM is using `Intel TDX` confidential type
sudo systemd-detect-virt --cvm
tdx
注意:另一種確認方式是查看「Group B」,確認其結尾為 2(HV_ISOLATION_TYPE_SNP)或 3(HV_ISOLATION_TYPE_TDX)。
# `AMD SEV-SNP` confidential type
dmesg | grep "Hyper-V: Isolation Config"
[ 0.000000] Hyper-V: Isolation Config: Group A 0x1, Group B 0xba2
# `Intel TDX` confidential type
dmesg | grep "Hyper-V: Isolation Config"
[ 0.000000] Hyper-V: Isolation Config: Group A 0x1, Group B 0xbe3
Want to help? Learn how to contribute to Fedora Docs ›