Skip to content

Instantly share code, notes, and snippets.

@Hooloovoo
Last active November 3, 2021 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hooloovoo/3e544681a12121a36b5dbda684465b8d to your computer and use it in GitHub Desktop.
Save Hooloovoo/3e544681a12121a36b5dbda684465b8d to your computer and use it in GitHub Desktop.
A basic Azure Shared Image Gallery template for Ubuntu Pro 18.04 with simple CIS hardening for use as part of a tutorial
{
"type": "Microsoft.VirtualMachineImages",
"apiVersion": "2020-02-14",
"location": "<region1>",
"dependsOn": [],
"tags": {
"imagebuilderTemplate": "AzureImageBuilderSIG",
"userIdentity": "enabled"
},
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"<imgBuilderId>": {}
}
},
"properties": {
"buildTimeoutInMinutes" : 80,
"vmProfile":
{
"vmSize": "Standard_D1_v2",
"osDiskSizeGB": 30
},
"source": {
"type": "PlatformImage",
"publisher": "<ProPlanPublisher>",
"offer": "<ProPlanOffer>",
"sku": "<ProPlanSku>",
"version": "latest",
"planInfo": {
"planName": "<ProPlanSku>",
"planProduct": "<ProPlanOffer>",
"planPublisher": "<ProPlanPublisher>"
}
},
"customize": [
{
"type": "Shell",
"name": "WaitForUAtokenAutoAttach",
"inline": [
"sudo ua status --wait"
]
},
{
"type": "Shell",
"name": "EnableCISfeature",
"inline": [
"sudo ua enable cis"
]
},
{
"type": "Shell",
"name": "RunCIShardening - see https://ubuntu.com/security/certifications/docs/cis-compliance",
"inline": [
"sudo /usr/share/ubuntu-scap-security-guides/cis-hardening/Canonical_Ubuntu_18.04_CIS-harden.sh lvl1_server"
]
},
{
"type": "Shell",
"name": "UDFworkaroundForAzureVMbooting - UDF is required for Azure image provisioning",
"inline": [
"sudo rm -f /etc/modprobe.d/Canonical_Ubuntu_CIS_rule-1.1.1.7.conf"
]
},
{
"type": "Shell",
"name": "Placeholder for custom commands required in each Ubuntu VM",
"inline": [
"echo 'Replace me!'"
]
},
{
"type": "Shell",
"name": "DetachUA -- images created from this will auto attach themselves with new credentials",
"inline": [
"sudo ua detach --assume-yes && sudo rm -rf /var/log/ubuntu-advantage.log"
]
},
{
"type": "Shell",
"name": "Replace /etc/machine-id with empty file to ensure UA client does not see clones as duplicates",
"inline": [
"sudo rm -f /etc/machine-id && sudo touch /etc/machine-id"
]
}
],
"distribute":
[
{
"type": "SharedImage",
"galleryImageId": "/subscriptions/<subscriptionID>/resourceGroups/<rgName>/providers/Microsoft.Compute/galleries/<sharedImageGalName>/images/<imageDefName>",
"runOutputName": "<runOutputName>",
"artifactTags": {
"source": "azureVmImageBuilder",
"baseosimg": "ubuntupro1804"
},
"replicationRegions": [
"<region1>",
"<region2>"
]
}
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment