In this article by Ryan Boud, author of Hyper-V Network Virtualization Cookbook, we will learn to lock down a VM for security access.
(For more resources related to this topic, see here.)
This article will show you how to apply ACLs to VMs to protect them from unauthorized access.
You will need to start two VMs in the Tenant A VM Network: in this case, Tenant A – VM 10, to test the gateway and as such should have IIS installed) and Tenant A – VM 11.
Perform the following steps to lock down a VM:
$VMNetworkName = "Tenant A" $VMNetwork = Get-SCVMNetwork | Where-Object -Property Name
-EQ $VMNetworkName Get-SCVMSubnet -VMNetwork $VMNetwork | Select-Object
VMNetwork,Name,SubnetVlans,VMSubnetID
Your VMSubnet ID value may be different to the one obtained here; this is normal behavior.
$VMs = @() $VMs += Get-SCVirtualMachine -Name "Tenant A - VM 10" $VMs += Get-SCVirtualMachine -Name "Tenant A - VM 11" ForEach($VM in $VMs){ Write-Output "$($VM.Name): $($VM.VirtualNetworkAdapters.IPv4Addresses)" Write-Output "Host name: $($VM.HostName)" }
Please leave this PowerShell console open.
Your IP addresses and host names may differ from those shown here; this is normal behavior.
Ping 10.0.0.14 –t
Invoke-Command -ComputerName HYPVCH1.ad.demo.com -
ScriptBlock{ Add-VMNetworkAdapterExtendedAcl -Action Deny -Direction
Inbound -VMName "Tenant A - VM 10" -Weight 1 -
IsolationID 4490741 }
Here, HYPVCH1.ad.demo.com is the name of the host where Tenant A – VM 10 is running, as obtained in step 4 and the Isolation ID needs to be VMSubnetID as obtained in step 2.
Please leave this PowerShell console open.
When adding base rules such as a Deny All, it is suggested to apply a weight of 1 to allow other rules to override it if appropriate.
This has created a Hyper-V Port ACL that will deny all inbound traffic to Tenant A – VM10.
Test-NetConnection -CommonTCPPort HTTP -ComputerName
10.0.0.14 -InformationLevel Detailed
Invoke-Command -ComputerName HYPVCH1.ad.demo.com -
ScriptBlock{ Add-VMNetworkAdapterExtendedAcl -Action Allow -
Direction Inbound -VMName "Tenant A - VM 10" -Weight
10 -IsolationID 4490741 -LocalPort 80 }
Here, HYPVCH1.ad.demo.com is the name of the host where Tenant A – VM 10 is running, as obtained in step 4, and the Isolation ID needs to be set to VMSubnetID as obtained in step 2.
Please leave this PowerShell console open.
When adding rules it is suggested to use weight increments of 10 to allow other rules to be inserted between rules if necessary.
Invoke-Command -ComputerName HYPVCH1.ad.demo.com -
ScriptBlock{ Add-VMNetworkAdapterExtendedAcl -Action Deny -Direction
Outbound -VMName "Tenant A - VM 10" -Weight 1 -
IsolationID 4490741 }
Here, HYPVCH1.ad.demo.com is the name of the host where Tenant A – VM 10 is running, as obtained in step 4, and the Isolation ID needs to be set to VMSubnetID as obtained in step 2.
Please leave this PowerShell console open.
When adding base rules such as a Deny All, it is suggested to apply a weight of 1 to allow other rules to override it if appropriate.
Invoke-Command -ComputerName HYPVCH1.ad.demo.com -
ScriptBlock{ Remove-VMNetworkAdapterExtendedAcl -Direction Inbound -
VMName "Tenant A - VM 10" -Weight 10 }
This removes the inbound rule for port 80. In the same PowerShell console enter the following cmdlets:
Invoke-Command -ComputerName HYPVCH1.ad.demo.com -
ScriptBlock{ Add-VMNetworkAdapterExtendedAcl -Action Allow -
Direction Inbound -VMName "Tenant A - VM 10" -Weight
10 -IsolationID 4490741 -LocalPort 80 -Stateful
$True -Protocol TCP }
This adds a stateful ACL rule; this ensures that the switch dynamically creates an outbound rule to allow the traffic to return to the requestor.
Extended ACLs are applied as traffic ingresses and egresses the VM into and out of the Hyper-V switch. As the ACLs are VM-specific, they are stored in the VM's configuration file. This ensures that the ACLs are moved with the VM ensuring continuity of ACL.
For the complete range of options, it is advisable to review the TechNet article at http://technet.microsoft.com/en-us/library/dn464289.aspx.
In this article we learned how to lock down a VM for security access.
Further resources on this subject: