Skip to content
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

Update Linux templates for disk encryption GA #2526

Merged
86 commits merged into from
Sep 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
aebcc00
Change publisher name for ADE on Linux
Sep 17, 2016
0e085e0
Update deployment link
Sep 17, 2016
f3016ce
Use test extension
Sep 17, 2016
0aedcad
Revert test extension name
Sep 17, 2016
a571a61
Merge remote-tracking branch 'upstream/master'
Sep 19, 2016
9f14fe9
Change parameter name to useKek
Sep 19, 2016
dfedb6b
Clarify description of diskFormatQuery
Sep 19, 2016
c6f7472
Add reference to the prereq PS script
Sep 19, 2016
49d51db
Add template skeleton
Sep 19, 2016
56a3e0c
Specify vmName in parameters
Sep 19, 2016
9162f85
Point to create VM template
Sep 19, 2016
0b4d831
Pass through vmName
Sep 19, 2016
317396f
Add default value for vmName
Sep 19, 2016
bcb7281
Update API version
Sep 19, 2016
7f8cf03
Use VM level unique strings for resource names
Sep 19, 2016
b5ecdd2
Use unique deployment name
Sep 19, 2016
dd6bf59
Add encrypt VM deployment
Sep 19, 2016
0bc93b5
Add setup_raid.sh
Sep 19, 2016
ee9a52c
sudofy commands
Sep 20, 2016
ee2387f
Use CustomScript extension to setup RAID
Sep 20, 2016
fd74f40
Add a data disk to RHEL VM
Sep 20, 2016
5f56878
Use vmname in name of nested resource
Sep 20, 2016
f6b50e5
Add slash to setupRaid name
Sep 20, 2016
9714b8c
Encryption should happen after RAID setup
Sep 20, 2016
0cc9bf0
Use older API version
Sep 20, 2016
f975311
Fix extension reference in resourceId
Sep 20, 2016
1aa1dcf
use different API version for extension resource
Sep 20, 2016
16f00cd
Execute shell script directly
Sep 20, 2016
4b23b45
Remove sudo, requires interactive terminal
Sep 20, 2016
5dd4291
Format data drive during encryption
Sep 20, 2016
f134e0b
Use variables to workaround escaping errors
Sep 20, 2016
d09941c
Prepend VM name to updateVM deployment name
Sep 20, 2016
118b945
Double brackets aren't needed if using variables for escaping
Sep 20, 2016
693faf8
Revert "Double brackets aren't needed if using variables for escaping"
Sep 20, 2016
0aa8136
Use escaped JS for opening bracket
Sep 20, 2016
2bb25e6
Specify diskFormatQuery without brackets
Sep 20, 2016
08b819a
Use old extension for CustomScript
Sep 20, 2016
f7d5cde
Update handler version for OSTC extension
Sep 20, 2016
3482e64
Add volumeType for Linux encryption
Sep 20, 2016
4d99292
Add vmSize parameter for RHEL vm creation
Sep 20, 2016
5a13b12
Update description for volumeType
Sep 20, 2016
dd732e4
Use just a single deployment for encrypting the VM
Sep 20, 2016
c262f65
Update heading for template README
Sep 21, 2016
3912f28
Add volumeType to parameters.json
Sep 21, 2016
c9d1b3e
Update deployment links to point to fde-rhel branch
Sep 21, 2016
4e98c39
Add decryption template for Linux
Sep 21, 2016
bcc70dc
Only Data volumeType is supported for decryption on Linux
Sep 22, 2016
10243d8
Use sequence version parameter
Sep 22, 2016
b05a6ab
Update metadatas for Linux encryption templates
Sep 22, 2016
eec3dab
Merge remote-tracking branch 'upstream/master' into fde-rhel
Sep 22, 2016
33a8d08
Update URLs to point to Azure repo
Sep 22, 2016
a696f89
Revert "Update URLs to point to Azure repo"
Sep 22, 2016
aeb876b
Update branch name to cnedemo
Sep 22, 2016
392bc15
Move setup_raid.sh to separate folder and allow use of SAS
Sep 22, 2016
29d2133
Nullify username and password parameters
Sep 22, 2016
8e4c7be
Move vmSize to variables insted of params
Sep 22, 2016
3648cef
Move setup_raid.sh script
Sep 22, 2016
96e7499
Merge fde-rhel
Sep 22, 2016
e95ae51
vmSize is not a param anymore, do not pass
Sep 22, 2016
f2d4ee2
vmSize is not a param anymore, do not pass
Sep 22, 2016
818ce6e
Merge branch 'fde-rhel' into cnedemo
Sep 23, 2016
6277487
Fix github username
Sep 23, 2016
2a189f2
Merge branch 'fde-rhel' into cnedemo
Sep 23, 2016
ecffe3d
Merge remote-tracking branch 'upstream/master' into fde-rhel
Sep 23, 2016
b88b49d
Merge branch 'fde-rhel' into cnedemo
Sep 23, 2016
b3d7061
Fix the URLs that were mistakenly updated
Sep 23, 2016
f2e839c
Update README for fde-rhel template
Sep 23, 2016
c43b170
Update fde-rhel README with detailed instructions
Sep 23, 2016
9fcdff1
Merge branch 'fde-rhel' into cnedemo
Sep 23, 2016
faae499
Minor prettification
Sep 23, 2016
1863c7b
Merge branch 'fde-rhel' into cnedemo
Sep 23, 2016
3bc4170
Fix typo
Sep 23, 2016
5120a46
KeyVault ResourceId is not needed
Sep 23, 2016
a14d610
Fix API verisons
Sep 23, 2016
b86cf1c
Remove RHEL version as parameter
Sep 23, 2016
48afb03
Do not use apiVersion as variable
Sep 23, 2016
55fee3f
Clarify resource group location
Sep 23, 2016
5950ff5
Fix volumeType for decrypt params
Sep 23, 2016
8d745ce
Reword comment for diskFormatQuery
Sep 23, 2016
2f9e982
Use artifacts URL pattern for other templates
Sep 23, 2016
b292464
Use null parameters
Sep 23, 2016
abe4a0a
Merge branch 'fde-rhel' into cnedemo
Sep 23, 2016
2f6383d
Fix repo name
Sep 23, 2016
0cab343
rhelOSVersion is not a param anymore
Sep 23, 2016
7576d50
Use hardcoded apiVersions
Sep 23, 2016
072925c
Fix title
Sep 23, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions 101-vm-full-disk-encrypted-rhel/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Deployment of RHEL 7.2 with full disk encryption

<a href="https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.luolix.top%2Fkrkhan%2Fazure-quickstart-templates%2Fcnedemo%2F101-vm-full-disk-encrypted-rhel%2Fazuredeploy.json" target="_blank">
<img src="http://azuredeploy.net/deploybutton.png"/>
</a>
<a href="http://armviz.io/#/?load=https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.luolix.top%2Fkrkhan%2Fazure-quickstart-templates%2Fcnedemo%2F101-vm-full-disk-encrypted-rhel%2Fazuredeploy.json" target="_blank">
<img src="http://armviz.io/visualizebutton.png"/>
</a>

This template creates a fully-encrypted RHEL 7.2 VM in Azure. The VM consists of:

- 30 GB encrypted OS drive.
- A 200 GB RAID-0 array mounted at `/mnt/raidencrypted`.

## Prerequisites:

Azure Disk Encryption securely stores the encryption secrets in a specified Azure Key Vault. You will need client ID and client secret of an AAD application to enable key vault authentication.

The [AzureDiskEncryptionPreRequisiteSetup.ps1](https://github.com/Azure/azure-powershell/blob/dev/src/ResourceManager/Compute/Commands.Compute/Extension/AzureDiskEncryption/Scripts/AzureDiskEncryptionPreRequisiteSetup.ps1) script can be used to create the Key Vault and assign appropriate access policies.

## Monitoring progress

It will take roughly one hour to encrypt the OS drive. You can monitor the encryption progress by calling `Get-AzureRmVmDiskEncryptionStatus` PowerShell cmdlet as shown below.

C:\> Get-AzureRmVmDiskEncryptionStatus -ResourceGroupName $ResourceGroupName -VMName $VMName
-ExtensionName $ExtensionName

OsVolumeEncrypted : EncryptionInProgress
DataVolumesEncrypted : EncryptionInProgress
OsVolumeEncryptionSettings : Microsoft.Azure.Management.Compute.Models.DiskEncryptionSettings
ProgressMessage : OS disk encryption started

Once the cmdlet shows the message `VMRestartPending`, like the one show below, reboot the VM.

C:\> Get-AzureRmVmDiskEncryptionStatus -ResourceGroupName $ResourceGroupName -VMName $VMName
-ExtensionName $ExtensionName

OsVolumeEncrypted : VMRestartPending
DataVolumesEncrypted : Encrypted
OsVolumeEncryptionSettings : Microsoft.Azure.Management.Compute.Models.DiskEncryptionSettings
ProgressMessage : OS disk successfully encrypted, please reboot the VM

After you reboot the VM, this will be the final layout:

# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
fd0 2:0 1 4K 0 disk
sda 8:0 0 30G 0 disk
├─sda1 8:1 0 500M 0 part
└─sda2 8:2 0 29.5G 0 part
└─osencrypt 253:0 0 29.5G 0 crypt /
sdb 8:16 0 14G 0 disk
└─sdb1 8:17 0 14G 0 part /mnt/resource
sdc 8:32 0 48M 0 disk
└─sdc1 8:33 0 47M 0 part
sdd 8:48 0 100G 0 disk
└─md0 9:0 0 199.9G 0 raid0
└─a717a295-61e2-4de9-9b27-689f3f6d5831 253:1 0 199.9G 0 crypt /mnt/encryptedraid
sde 8:64 0 100G 0 disk
└─md0 9:0 0 199.9G 0 raid0
└─a717a295-61e2-4de9-9b27-689f3f6d5831 253:1 0 199.9G 0 crypt /mnt/encryptedraid

`/` will be mounted mounted from a AES-256 bit encrypted drive:

# cryptsetup status osencrypt
/dev/mapper/osencrypt is active and is in use.
type: n/a
cipher: aes-xts-plain64
keysize: 256 bits
device: /dev/sda2
offset: 0 sectors
size: 61888512 sectors
mode: read/write

While `/mnt/encryptedraid` will point to the 200 GB RAID array:

# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/osencrypt 30G 1.8G 28G 6% /
devtmpfs 3.4G 0 3.4G 0% /dev
tmpfs 3.5G 0 3.5G 0% /dev/shm
tmpfs 3.5G 8.3M 3.4G 1% /run
tmpfs 3.5G 0 3.5G 0% /sys/fs/cgroup
/dev/sdb1 14G 2.1G 11G 16% /mnt/resource
tmpfs 697M 0 697M 0% /run/user/1000
/dev/dm-1 197G 61M 187G 1% /mnt/encryptedraid

If you run the `Get-AzureRmVmDiskEncryptionStatus` cmdlet again, you will see updated encryption status:

C:\> Get-AzureRmVmDiskEncryptionStatus -ResourceGroupName $ResourceGroupName -VMName $VMName
-ExtensionName $ExtensionName

OsVolumeEncrypted : Encrypted
DataVolumesEncrypted : Encrypted
OsVolumeEncryptionSettings : Microsoft.Azure.Management.Compute.Models.DiskEncryptionSettings
ProgressMessage : [KeyVault URL of LUKS passphrase secret]

## References:

- [White paper](https://azure.microsoft.com/en-us/documentation/articles/azure-security-disk-encryption/)
- [Explore Azure Disk Encryption with Azure Powershell](https://blogs.msdn.microsoft.com/azuresecurity/2015/11/16/explore-azure-disk-encryption-with-azure-powershell/)
- [Explore Azure Disk Encryption with Azure PowerShell – Part 2](http://blogs.msdn.com/b/azuresecurity/archive/2015/11/21/explore-azure-disk-encryption-with-azure-powershell-part-2.aspx)
162 changes: 162 additions & 0 deletions 101-vm-full-disk-encrypted-rhel/azuredeploy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"adminUsername": {
"type": "string",
"metadata": {
"description": "User name for the Virtual Machine."
}
},
"adminPassword": {
"type": "securestring",
"metadata": {
"description": "Password for the Virtual Machine."
}
},
"aadClientID": {
"metadata": {
"description": "Client ID of AAD app which has permissions to KeyVault"
},
"type": "string"
},
"aadClientSecret": {
"metadata": {
"description": "Client Secret of AAD app which has permissions to KeyVault"
},
"type": "securestring"
},
"keyVaultName": {
"type": "string",
"metadata": {
"description": "Name of the KeyVault to place the volume encryption key"
}
},
"keyVaultResourceGroup": {
"type": "string",
"metadata": {
"description": "Resource group of the KeyVault"
}
},
"vmName": {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a "vmName" parameter really necessary? It should be fine to inline "[concat('rhelVM', uniqueString(resourceGroup().id))]" in the nested deployment resource below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vmName is necessary because we want the user to be able to create multiple VMs with the same template. Otherwise subsequent invocations will fail.

Copy link

@ghost ghost Sep 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense.

"type": "string",
"metadata": {
"description": "Name of the VM that will be created"
}
},
"_artifactsLocation": {
"type": "string",
"defaultValue": "https://raw.githubusercontent.com/krkhan/azure-quickstart-templates/cnedemo",
"metadata": {
"description": "The base URI where artifacts required by this template are located. When the template is deployed using the accompanying scripts, a private location in the subscription will be used and this value will be automatically generated."
}
},
"_artifactsLocationSasToken": {
"type": "string",
"defaultValue": "",
"metadata": {
"description": "The sasToken required to access _artifactsLocation. When the template is deployed using the accompanying scripts, a sasToken will be automatically generated."
}
}
},
"variables": {
"templateName": "101-vm-full-disk-encrypted-rhel",
"createVmUrl": "[concat(parameters('_artifactsLocation'), '/', '101-vm-simple-rhel', '/', 'azuredeploy.json', parameters('_artifactsLocationSasToken'))]",
"createVmDeploymentName": "[concat(uniquestring(parameters('vmName')), 'createVm')]",
"encryptVmUrl": "[concat(parameters('_artifactsLocation'), '/', '201-encrypt-running-linux-vm', '/', 'azuredeploy.json', parameters('_artifactsLocationSasToken'))]",
"encryptVmDeploymentName": "[concat(uniquestring(parameters('vmName')), 'encryptVm')]",
"scriptsFolder": "scripts",
"scriptFileName": "setup_raid.sh",
"setupRaidUrl": "[concat(parameters('_artifactsLocation'), '/', variables('templateName'), '/', variables('scriptsFolder'), '/', variables('scriptFileName'), parameters('_artifactsLocationSasToken'))]",
"setupRaidExtensionName": "setupRaidCustomScript",
"diskFormatQuery": "{\"dev_path\":\"/dev/md0\",\"name\":\"encryptedraid\",\"file_system\":\"ext4\"}"
},
"resources": [
{
"apiVersion": "2016-02-01",
"name": "[variables('createVmDeploymentName')]",
"type": "Microsoft.Resources/deployments",
"properties": {
"mode": "Incremental",
"parameters": {
"adminUsername": {
"value": "[parameters('adminUsername')]"
},
"adminPassword": {
"value": "[parameters('adminPassword')]"
},
"vmName": {
"value": "[parameters('vmName')]"
}
},
"templateLink": {
"contentVersion": "1.0.0.0",
"uri": "[variables('createVmUrl')]"
}
}
},
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"name": "[concat(parameters('vmName'), '/', variables('setupRaidExtensionName'))]",
"apiVersion": "2015-06-15",
"location": "[resourceGroup().location]",
"dependsOn": [
"[resourceId('Microsoft.Resources/deployments', variables('createVmDeploymentName'))]"
],
"properties": {
"publisher": "Microsoft.OSTCExtensions",
"type": "CustomScriptForLinux",
"typeHandlerVersion": "1.5",
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": [
"[variables('setupRaidUrl')]"
],
"commandToExecute": "./setup_raid.sh"
},
"protectedSettings": {}
}
},
{
"apiVersion": "2016-02-01",
"dependsOn": [
"[resourceId('Microsoft.Compute/virtualMachines/extensions', parameters('vmName'), variables('setupRaidExtensionName'))]"
],
"name": "[variables('encryptVmDeploymentName')]",
"type": "Microsoft.Resources/deployments",
"properties": {
"mode": "Incremental",
"parameters": {
"encryptionOperation": {
"value": "EnableEncryptionFormat"
},
"volumeType": {
"value": "All"
},
"diskFormatQuery": {
"value": "[variables('diskFormatQuery')]"
},
"aadClientID": {
"value": "[parameters('aadClientID')]"
},
"aadClientSecret": {
"value": "[parameters('aadClientSecret')]"
},
"keyVaultName": {
"value": "[parameters('keyVaultName')]"
},
"keyVaultResourceGroup": {
"value": "[parameters('keyVaultResourceGroup')]"
},
"vmName": {
"value": "[parameters('vmName')]"
}
},
"templateLink": {
"contentVersion": "1.0.0.0",
"uri": "[variables('encryptVmUrl')]"
}
}
}
]
}
27 changes: 27 additions & 0 deletions 101-vm-full-disk-encrypted-rhel/azuredeploy.parameters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"adminUsername": {
"value": ""
},
"adminPassword": {
"value": ""
},
"aadClientID": {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null the param values since CI won't handle this and user must supply something specific

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

"value": ""
},
"aadClientSecret": {
"value": ""
},
"keyVaultResourceGroup": {
"value": ""
},
"keyVaultName": {
"value": ""
},
"vmName": {
"value": ""
}
}
}
6 changes: 6 additions & 0 deletions 101-vm-full-disk-encrypted-rhel/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"itemDisplayName": "Red Hat Enterprise Linux 7.2 VM (Fully Encrypted)",
"description": "This template will deploy a Red Hat Enterprise Linux 7.2 VM and encrypt both OS and data drives.",
"githubUsername": "krkhan",
"dateUpdated": "2016-09-19"
}
8 changes: 8 additions & 0 deletions 101-vm-full-disk-encrypted-rhel/scripts/setup_raid.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

set -e

yum install -y mdadm
mdadm --create --verbose /dev/md0 --level=0 --raid-devices=2 /dev/sdc /dev/sdd
mkdir -p /etc/mdadm
mdadm --detail --scan > /etc/mdadm/mdadm.conf
6 changes: 2 additions & 4 deletions 101-vm-simple-rhel/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# Deployment of Red Hat Enterprise Linux VM (RHEL 7.2 or RHEL 6.7)

<a href="https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.luolix.top%2FAzure%2Fazure-quickstart-templates%2Fmaster%2F101-vm-simple-rhel%2Fazuredeploy.json" target="_blank">
<a href="https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.luolix.top%2Fkrkhan%2Fazure-quickstart-templates%2Fcnedemo%2F101-vm-simple-rhel%2Fazuredeploy.json" target="_blank">
<img src="http://azuredeploy.net/deploybutton.png"/>
</a>
<a href="http://armviz.io/#/?load=https%3A%2F%2Fraw.luolix.top%2FAzure%2Fazure-quickstart-templates%2Fmaster%2F101-vm-simple-rhel%2Fazuredeploy.json" target="_blank">
<img src="http://armviz.io/visualizebutton.png"/>
</a>
<a href="http://armviz.io/#/?load=https%3A%2F%2Fraw.luolix.top%2Fkrkhan%2Fazure-quickstart-templates%2Fcnedemo%2F101-vm-simple-rhel%2Fazuredeploy.json" target="_blank">


This template allows deploying a Red Hat Enterprise Linux VM (RHEL 7.2 or RHEL 6.7), using the latest image for the selected RHEL version. This will deploy a Standard D1 VM in the location of your chosen resource group with an additional 100 GiB data disk attached to the VM.
Expand Down
Loading