Provisionando Fedora CoreOS no Azure

Este guia mostra como provisionar novos nós Fedora CoreOS (FCOS) no Azure. O Fedora atualmente não publica imagens do Fedora CoreOS no Azure, então você deve baixar uma imagem do Azure do Fedora e carregá-la em sua assinatura do Azure.

O FCOS não dá suporte a máquinas virtuais herdadas Service Manager da Azure.

Pré-requisitos

Antes de provisionar uma máquina FCOS, você deve ter um arquivo de configuração do Ignition contendo suas personalizações. Se você não tiver um, consulte Produzindo um arquivo de Ignition.

Fedora CoreOS tem um usuário padrão core que pode ser usado para explorar o sistema operacional. Se você quiser usá-lo, finalize sua configuração fornecendo, por exemplo, uma chave SSH.

Se você não quiser usar o Ignition para começar, você pode usar o suporte ao Afterburn.

Você também precisa ter acesso a uma assinatura do Azure. Os exemplos abaixo usam o Azure CLI.

Baixando uma imagem do Azure

O Fedora CoreOS é projetado para ser atualizado automaticamente, com horários diferentes por fluxo. Depois de escolher o fluxo relevante, baixe, verifique e descompacte a imagem mais recente do Azure:

STREAM="stable"
coreos-installer download --decompress -s $STREAM -p azure -f vhd.xz

Como alternativa, você pode baixar manualmente uma imagem do Azure na página de download. Verifique o download, seguindo as instruções dessa página, e descompacte-o.

Fazendo upload da imagem para o Azure

  1. Crie quaisquer recursos que ainda não existam em sua conta do Azure:

    Exemplo de criação de recursos do Azure
    az_region="westus2"
    az_resource_group="my-group"
    az_storage_account="mystorageacct"
    az_container="my-container"
    # Cria grupo de recursos
    az group create -l "${az_region}" -n "${az_resource_group}"
    # Cria uma conta de armazenamento para enviar a imagem FCOS
    az storage account create -g "${az_resource_group}" -n "${az_storage_account}"
    # Recupera string de conexão para conta de armazenamento
    cs=$(az storage account show-connection-string -n "${az_storage_account}" -g "${az_resource_group}" | jq -r .connectionString)
    # Cria um contêiner de armazenamento para fazer o upload da imagem FCOS
    az storage container create --connection-string "${cs}" -n "${az_container}"
  2. Crie uma imagem do FCOS:

    Exemplo de criação de imagem do Azure
    downloaded_image_file="./image.vhd"
    az_image_name="my-fcos-image"
    az_image_blob="${az_image_name}.vhd"
    # Upload do blob de imagem
    az storage blob upload --connection-string "${cs}" -c "${az_container}" -f "${downloaded_image_file}" -n "${az_image_blob}"
    # Cria a imagem
    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
    # Excluir o blob enviado
    az storage blob delete --connection-string "$cs" -c "${az_container}" -n "${az_image_blob}"

Launching a VM instance using custom-data

  1. Launch a VM. Your Ignition configuration can be passed to the VM as custom data, or you can skip passing custom data if you just want SSH access. Your SSH public key from ~/.ssh will automatically be added to the VM. This provides an easy way to test out FCOS without first creating an Ignition config.

    Exemplo de inicialização de imagem do 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})"
  2. Agora você deve conseguir fazer SSH na instância usando o endereço IP associado.

    Exemplo de conexão
    ssh core@<endereço ip>

Launching a VM instance using custom-data and a private Azure blob

  1. Define variables for the VM name and Ignition configs:

    Define your variables
    az_vm_name=my-fcos-vm
    ignition_path="./config.ign"
    az_blob_ignition_path=./privateConfig.ign
    az_blob_ignition_file_name=privateConfig.ign
    Upload your ign file to Azure blob storage
    az storage blob upload --connection-string "${cs}" -c "${az_blob_ignition_file_name}" -f  "${az_blob_ignition_path}" -n "${ignition_file_name}"
  2. Create your remote ignition config to reference this new blob. Read about that here Using a remote Ignition config

  3. Create an identity and give it proper access to your storage account:

    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}
    Create the VM passing the new identity
    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}"

Launching a Confidential VM instance

Support for Confidential Computing is a work in progress in Fedora CoreOS. See the issue #1719.
For an overview about confidential VMs on Azure see confidential VM overview.

To launch a confidential VM, we need to create an image that supports confidential computing in an Azure Compute Gallery.

Example creating a gallery image that supports confidential computing
# 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}

To launch a confidential FCOS instance, you need to specify the confidential compute type and use a machine type that supports confidential computing.

From the command-line, use --security-type ConfidentialVM and --size.

Example launching a Confidential VM instance
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
We pass parameter --enable-secure-boot true to enable Secure Boot. Use false to disable secure boot.
To get the full console log, append the parameter --boot-diagnostics-storage ${az_storage_account}.
Example Confidential VM Boot Verification
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

Note: Another way to confirm is looking at "Group B" and see that it ends with 2 (HV_ISOLATION_TYPE_SNP), or ends with 3 (HV_ISOLATION_TYPE_TDX).

Example Confidential VM Boot Verification by checking dmesg log
# `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