Using an Azure Policy to Deploy Azure VM Extension
Using an Azure Policy to Deploy Azure VM Extension
Before you begin
Before you begin with the steps on this page, complete the steps in the Getting started section on the Using an Azure Virtual Machine Extension to Install and Register a Tanium Client page. This article describes the steps to create a Microsoft Azure policy and deploy the Azure Virtual Machine (VM) Extension that will install a Tanium Client on your VM in the Azure cloud and register the Tanium Client with your Tanium Server automatically using a remediation task with the deployIfNotExists template.
Deploying the Azure VM extension using an Azure policy
Create a managed identity
-
From your Microsoft Azure portal, search for then click Managed Identities.
-
From the Managed Identities page, click + Create.
-
From the Create dialog box, select your Subscription and the Azure-VM-Extension-Test-Central Resource Group you created in the Getting started section of the Using an Azure Virtual Machine Extension to Install and Register a Tanium Client page. Name the new Managed Identity TaniumClient.
-
Click Review + Create.
-
Review the details to make sure that you selected the correct options.
-
Click Create.
Delegate permissions to your resource group
-
From your Azure portal, search for Azure-VM-Extension-Test-Central. to go to the Resource Group page for that Resource Group.
-
In the left column, click Access Control (IAM).
-
Click + Add. From the dropdown, click Add role assignment.
-
In the Role tab, search for the Virtual Machine Contributor role .
-
Click Next.
-
From the Members tab, for the Assign access to setting, select Managed identity.
-
Click + Select members. A menu appears on the right side of the screen.
-
Ensure that the correct subscription is selected and select TaniumClient identity that you created in the previous section for Managed Identity.
-
Click Review + assign two times.
Create the Azure Policy
-
From the Azure portal, search for and open Policy.
-
On the Policy page, click Authoring > Definitions.
-
Click + Policy definition to create a new Definition.
-
For the Definition location, click the context menu (three white dots) and select your Subscription.
-
For Name, enter Tanium Client Windows Install.
-
For Description, enter a short description for this Policy Definition.
-
For Category, ensure that Create new is selected then enter Azure VM TC in the Category box.
-
In the POLICY RULE box, delete all existing text.
-
Copy the following text and paste it into the empty POLICY RULE box:
{ "mode": "All", "policyRule": { "if": { "allOf": [ { "field": "type", "equals": "Microsoft.Compute/virtualMachines" }, { "field": "Microsoft.Compute/imagePublisher", "equals": "MicrosoftWindowsServer" }, { "field": "Microsoft.Compute/imageOffer", "equals": "WindowsServer" } ] }, "then": { "effect": "deployIfNotExists", "details": { "type": "Microsoft.Compute/virtualMachines/extensions", "evaluationDelay": "AfterProvisioningSuccess", "existenceCondition": { "allOf": [ { "field": "Microsoft.Compute/virtualMachines/extensions/type", "equals": "TaniumClientWindows" }, { "field": "Microsoft.Compute/virtualMachines/extensions/publisher", "equals": "Tanium.Client" } ] }, "roleDefinitionIds": [ ], "deployment": { "properties": { "mode": "incremental", "template": { "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "vmName": { "type": "string" }, "location": { "type": "string" }, "TaniumInitDat": { "type": "string" } }, "resources": [ { "name": "[concat(parameters('vmName'),'/TaniumClientWindows')]", "type": "Microsoft.Compute/virtualMachines/extensions", "location": "[parameters('location')]", "apiVersion": "2017-12-01", "properties": { "publisher": "Tanium.Client", "type": "TaniumClientWindows", "typeHandlerVersion": "1.0", "autoUpgradeMinorVersion": true, "settings": {}, "protectedSettings": { "TaniumInitDat": "[parameters('TaniumInitDat')]" } } } ] }, "parameters": { "vmName": { "value": "[field('name')]" }, "location": { "value": "[field('location')]" }, "TaniumInitDat": { "value": "[parameters('TaniumInitDat')]" } } } } } } }, "parameters": { "TaniumInitDat": { "type": "String", "metadata": { "displayName": "TaniumInitDat", "description": null } } } }
-
Click Save.
Assign the policy
After you create the policy definition, you must assign the policy.
-
From the Home > Policy | Definitions page, ensure that the policy you created in the previous step is selected.
-
Click Assign policy.
-
On the Basics tab, for Scope, select your subscription.
-
For Policy Definition, target the policy you created in the previous section.
-
Click Next.
-
Outside of the Azure portal, grab the base 64 String from the Integrations Gallery from the Tanium Console and skip steps 7-9 or if using the legacy option open a PowerShell terminal.
-
Navigate to the directory where you downloaded the
tanium-init.datfile in the Getting started section on the Using an Azure Virtual Machine Extension to Install and Register a Tanium Client page. -
Enter the following command:
[Convert]::ToBase64String([IO.File]::ReadAllBytes('.\tanium-init.dat')). The command will return a string. -
Copy the string returned by the command in the previous step.
-
Return to your Azure portal.
-
On the Parameters tab, in the TaniumInitDat box, paste the string you copied in Step 9.
-
Click Next.
-
On the Remediation tab, for the Type of Managed Identity setting, select User assigned managed identity.
-
In the Scope field, click the context menu (three dots) beside the box. A dialog box appears.
-
In the dialog box, set Subscription to your subscription and Resource Group to Azure-VM-Extension-Test-Central.
-
Click Select.
-
On the Assigned policy page, for Existing user assigned identities box, select TaniumClient.
-
Click Next until you reach the Review + create page.
-
Review the details on the page.
-
Click Create.
The Policy is now available for you to use to create new VMs. New VMs will be scanned by the Azure policy you created. The policy will install a Tanium Client on each VM in Azure cloud where you apply the policy and the Tanium Client is not yet installed and register the Tanium Client with your Tanium Server automatically.