Exported on 07-Oct-2021 22:09:51
Parameters
1 - Install Azure Az PowerShell Module
This step installs the Azure Az PowerShell Module
The Blueprint first gets the Execution Policy of the current PowerShell session.
Then, checks if the Execution Policy is set to Unrestricted.
If it's not, it then sets the Execution Policy to Unrestricted for the current session.
Next, it checks if the Az PowerShell module is installed.
If it's not installed, it then goes ahead to install the module.
Login as user {Attune Node Credential} on node {Attune Node}
#Region for ExecutionPolicy
# Get Execution Policy of the current process
$Script:ProcessEP = Get-ExecutionPolicy -Scope Process
#Get the value of the Execution Policy and save it in the Variable
$Script:ValueProcessEP = ($Script:ProcessEP).value__
# Check if the Execution Policy of the process is set to Unrestricted
if ($Script:ValueProcessEP -eq 0) {
# Write the message
Write-Output "Execution Policy is already set to Unrestricted for the Process"
# Check if the Execution Policy of the process is already set
}else{
# Set the ExecutionPolicy of the Process to Unrestricted
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Unrestricted -Force -Confirm:$false
# Checks if the Execution Policy has been set
if ((Get-ExecutionPolicy -Scope Process).value__ -eq 0) {
# Write the message
Write-Output "Execution Policy is now set to Unrestricted for the Process"
}
}
#EndRegion for ExecutionPolicy
#Region Check if Az Module is installed
#Region if module is installed, update module if version is not up to Version "4.1.13.0"
if($null -ne (Get-InstalledModule -Name Az -ErrorVariable +ErrorAzV -ErrorAction SilentlyContinue)) {
# Get the Az module installed and save it in a variable
$Script:GetAzModule = Get-InstalledModule -Name Az -ErrorVariable +ErrorAzV -ErrorAction SilentlyContinue
# Writes a message to the screen
Write-Output "Az PowerShell Module exists ... checking ..."
# Gets the build number for the Az Module
$Script:AzModuleBuild = ($Script:GetAzModule).Version
# Checks the build number to meet requirements
if($Script:AzModuleBuild -like "*6.3.0*") {
# Saves and converts Module version name to a variable
$Script:OutVersion = ((($Script:GetAzModule).Version)).tostring()
# Writes a message to the screen
Write-Output "Az Module Version $Script:OutVersion meets the minimum requirement."
# Check if the build version is on 13
}else{
# Writes a message to the screen
Write-Output "Updating the Az PowerShell Module..."
# Uppdates the AzPowerShell Module to the latest version
Update-Module -Name Az -Confirm:$false -Force
# Writes a message to the screen
Write-Output "Az PowerShell Module is updated :)"
}
#EndRegion if the module is installed, update module if the version is not up to Version "4.1.13.0"
#Region If the module is not installed, install it
}else{
# Writes a message to the screen
Write-Output "Az PowerShell Module is not installed"
# Writes a message to the screen
Write-Output "Az PowerShell Module is installing..."
# Install Az Powershell Module
Install-Module -Name Az -MaximumVersion "6.3.0" -Scope "CurrentUser" -AllowClobber:$true -Confirm:$false -Force
# Writes a message to the screen
Write-Output "Az PowerShell Module is installed :)"
}
#EndRegion If the module is not installed, install it
2 - Enable Secure Transfer
This step enables HTTPS traffic on Azure Storage Accounts
The Blueprint first gets the Execution Policy of the current PowerShell session.
Then checks if the Execution Policy is set to Unrestricted.
If it's not, it then sets the Execution Policy to Unrestricted for the current session.
Next, the AzPowerShell module is imported to the current session.
Then the values below are set:
- UserName: This is the Username of the Azure Administrator corresponding to the
AzureUserName
set in the Inputs Tab. - PasswordString: This is the Password of the Azure Administrator corresponding to the
AzurePassword
set in the Inputs Tab.
Next, a connection to Azure is made.
Then loops through all resource groups and checks for storage accounts.
Next, it enables HTTPS Traffic on those storage accounts
Finally, the Azure PowerShell session is disconnected.
Login as user {Attune Node Credential} on node {Attune Node}
#Region for ExecutionPolicy
# Get Execution Policy of the current process
$Script:ProcessEP = Get-ExecutionPolicy -Scope Process
#Get the value of the Execution Policy and save it in the Variable
$Script:ValueProcessEP = ($Script:ProcessEP).value__
# Check if the Execution Policy of the process is set to Unrestricted
if ($Script:ValueProcessEP -eq 0) {
# Write the message
Write-Output "Execution Policy is already set to Unrestricted for the Process"
# Check if the Execution Policy of the process is already set
}else{
# Set the ExecutionPolicy of the Process to Unrestricted
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Unrestricted -Force -Confirm:$false
# Checks if the Execution Policy has been set
if ((Get-ExecutionPolicy -Scope Process).value__ -eq 0) {
# Write the message
Write-Output "Execution Policy is now set to Unrestricted for the Process"
}
}
#EndRegion for ExecutionPolicy
#Region Enable Https for StorageAccounts
# Import Module for Az PowerShell
Import-Module -Name Az
#Region assign variables
# Save accesskey to this Variable
$Script:UserName = "{azureusername.value}"
# Save secretkey to this variable
$Script:PasswordString = "{azurepassword.value}"
#EndRegion assign variables
#Region for Connection to Azure
# Set the password and convert it to secure string to the variable
$Script:Password = ConvertTo-SecureString $Script:PasswordString -AsPlainText -Force
# set the credentials to the variable
$Script:UserCredential = New-Object System.Management.Automation.PSCredential ($Script:UserName,$Script:Password)
# Connect using set credentials to Azure
Connect-AzAccount -Credential $Script:UserCredential
#EndRegion for Connection to Azure
# Get all Resources Groups and saves them in the Variable ALlRGS
$Script:AllRGS = Get-AzResourceGroup
# loops through all resource groups
foreach ($AllRG in $Script:AllRGS ) {
# Set the variable for Rg name with no storage account
$Script:RGNameNS = ($AllRG).ResourceGroupName
# Writes a message to the screen
Write-Output "Checking if Resource Groups $Script:RGNameNS has Storage Accounts...... `n"
# Gets all resources of resource type 'Microsoft.Storage/storageAccounts' from each resource group and saves it in a variable
$Script:StorageAccounts = Get-AzResource -ResourceGroupName ($AllRG).ResourceGroupName | Where-Object { $_.ResourceType -like "Microsoft.Storage/storageAccounts" }
# Set the variable for Rg name with storage account
$Script:RGName = ($Script:StorageAccounts).ResourceGroupName
# checks if the variable is null
if (!($Script:StorageAccounts)) {
# Writes a message to the screen
Write-Output "Resource Group $Script:RGNameNS has no Storage Account `n"
}else{
# Writes a message to the screen
Write-Output "Resource Group $Script:RGName has Storage Account(s) `n"
# looping through all storage accounts
foreach ($StorageAccount in $Script:StorageAccounts) {
# Set storage account name
$Script:StorageName = ($StorageAccount).Name
# Set the variable for sub Rg name
$Script:RGNameSub = ($StorageAccount).ResourceGroupName
# Writes a message to the screen
Write-Output "Setting EnableHttpsTrafficeOnly property of Storage Account with Name '$Script:StorageName' - to True..... `n"
# Pause Script for 1 millisecond in case Microsoft has any throttling Policy on CMDLET "Set-AzStorageAccount"
Start-Sleep -Milliseconds 1
# Set storage account EnableHttpsTrafficeOnly to $True
Set-AzStorageAccount -ResourceGroupName $Script:RGNameSub -Name $Script:StorageName -EnableHttpsTrafficOnly $true -Force
# Writes a message to the screen
Write-Output "`n Done `n"
}
}
}
#EndRegion Enable Https for StorageAccounts
#Region Disconnect the Azure session
Disconnect-AzAccount
#EndRegion Disconnect the Azure session
Using Attune to enable HTTPS traffic on all Azure Storage Accounts
This Blueprint is used to enable only HTTPS traffic on all Azure Storage Accounts.
An Azure storage account is a container that holds a set of Azure storage services together.
It holds Storage data objects like blobs, file shares, queues, tables, and disks.
The data is accessible from anywhere in the world over HTTP or HTTPS.
Information security audit requires storage accounts to accept requests from only secure connections (HTTPS).
The use of HTTPS protects data in transit from network layer attacks such as man-in-the-middle, eavesdropping, and session-hijacking.
Pre-Blueprint Attune setup
Blueprint Steps