spaelling / azure-security-review

GNU General Public License v3.0
5 stars 2 forks source link

Azure Security Review

A notebook (using Polyglot) that codifies the Azure Security Review Checklist and other general security recommendations, like Microsoft Security Benchmarks. It will also include best practices and well architected recommendations.

The notebook approach allows for use of many different languages and frameworks. We can use Microsoft Graph to gain insights into Entra ID (Azure AD), and we can use Azure Resource Graph combined with Azure Powershell or Az cli. But C#, Python, Javascript, etc. is also viable options.

Combined with Markdown, this allows for verbosity to a level that is hard to beat with any other tooling, and insights gained literally with the click of a button.

News

All code regarding Entra ID has been converted to a Powershell module, published to PSAzureSecurityAssessment.

Also added Write-EntraIdAssessment which will output a Markdown file (and optionally upload to an Azure Storage Account). This even supports multi tenant assessments, supported by New-MultiTenantApplication which can create a multi-tenant application to be used for these types of assessments (or just a single tenant).

Notes

These are the controls/checks that are implemented, planned, or work in progress.

Check out the Demo section for examples.

Prerequisites

# Install Anaconda 3 using ex. Chocolatey

# from an elevated command prompt
choco install anaconda3
# go drink a coffee - this takes a while

We need to make sure a few prequisite modules are installed

Note that Microsoft.Graph is a collection of many modules.

If there are multiple of the same modules listed using below code, then you have Microsoft.Graph modules installed in multiple places and possibly multiple different versions.

I would suggest completely uninstalling and then install the necessary modules. Also beware if you are installing to PowerShell Desktop or Core, check $PSVersionTable.

$MGModuleNames = 'Microsoft.Graph.Identity.DirectoryManagement', 'Microsoft.Graph.Authentication', 'Microsoft.Graph.Identity.SignIns', 'Microsoft.Graph.Groups', 'Microsoft.Graph.DirectoryObjects', 'Microsoft.Graph.Users', 'Microsoft.Graph.Applications'
$MGModuleNames | % {Install-Module -Name $_ -Scope AllUsers -Force -Verbose}
# beta modules
$MGModuleNames = 'Microsoft.Graph.Beta.Identity.SignIns', 'Microsoft.Graph.Beta.Identity.Governance', 'Microsoft.Graph.Beta.Applications', 'Microsoft.Graph.Beta.Identity.DirectoryManagement', 'Microsoft.Graph.Beta.DirectoryObjects', 'Microsoft.Graph.Beta.Reports'
$MGModuleNames | % {Install-Module -Name $_ -Scope AllUsers -Force -Verbose -AllowClobber}

Note that this installation takes a while to complete.

You can list the modules, versions and their install location using

Get-Module -ListAvailable | Where-Object {$_.Name -like "Microsoft.Graph*"}

Beware of having multiple versions or differing versions installed. You can encounter this error Assembly with same name is already loaded if two different modules are loading two different assemblies with the same name but different versions. Avoid this by always using the latest version.

Update all MG modules using

Get-Module -ListAvailable | Where-Object {$_.Name -like "*Microsoft.Graph.*"} | Update-Module -Force

And then use MicrosoftGraphPS to remove old versions.

Install-Module -Name MicrosoftGraphPS
# and run
Manage-Version-Microsoft.Graph -CleanupOldMicrosoftGraphVersions

We will also be using a community module:

Install-Module -Name AzResourceGraphPS

and for PS Core only users we need Out-GridView (Windows GUI elements not available in PS Core)

Install-Module Microsoft.PowerShell.ConsoleGuiTools
# And set the alias - note this is just for the session.
Set-Alias -Name Out-GridView -Value Out-ConsoleGridview

Azure Policies

This notebook is not a replacement for Azure Policies. Many of the checks done here is much better to do using Azure Policies (if possible), as these continously evaluate, and can also enforce specific settings.

Demo

Limit the number of Global Administrators to less than 5

https://github.com/spaelling/azure-security-review/assets/871412/41c6ea70-57cd-44c9-b0a2-61d8e3107fed

PIM Alerts

https://github.com/spaelling/azure-security-review/assets/871412/12db37a9-18aa-4f7e-ad4a-9732f1959761

User consent for apps

https://github.com/spaelling/azure-security-review/assets/871412/6433875c-df6c-4d66-9086-daf0a3b7607f

Application owners

https://github.com/spaelling/azure-security-review/assets/871412/cc9db762-f164-4945-8732-ff9e9193a350

Block Legacy Protocols

https://github.com/spaelling/azure-security-review/assets/871412/69ff9d19-edc0-4b58-951d-a565da418ae3

Subnets should have an NSG associated

https://github.com/spaelling/azure-security-review/assets/871412/e4261ba9-7f7b-4e3f-9d5c-2de49033a2b5

Open Management Ports

https://github.com/spaelling/azure-security-review/assets/871412/036c614e-bfe1-4b32-a84c-a69d2f517c09

Feedback