In this post we will be looking at creating a report to show what Azure App registrations have expiring client secret / certificate in the specified amount of days.
There is currently no in built way to report on expiring App registrations in the Azure portal other than checking the app registration, so we will be using Microsoft Graph SDK to automate the reporting.
First to automate the report we need to create an app registration to use for the Microsoft Graph connection. I have gone through this in a previous post.
The specific Microsoft GraphApi application permission required is Application.Read.All, this needs to be added to the App Registration that we use for Microsoft Graph.
App Registration API Permission
Next we need to connect to Microsoft Graph using.
Connect-MgGraph
To list the app registration use
Get-MgApplication
Microsoft Graph Applications
Once we have the list of apps we can use PasswordCredentials to view client secret details
(Get-MgApplication).PasswordCredentials
Application Secrets Properties
and KeyCredentials to view the certificates details
Application Certificate Properties
Once we have the required properties, we can create the script to export the app registration details.
App Registration Report
There are two parameters Reportonly which returns just the result to PowerShell window and ReportExport which will export the report to the specific folder specified.
In this post we will be going through setting up and using stored access policy with Azure storage account. We can create SAS URL but each time we create one there is no way to revoke without rotating the storage keys.
A stored access policy can be used to control shared access signatures (SAS) on the server side. We can use a stored access policy to change the start time, expiry time, or permissions for a SAS URL that is generated from a storage account. We can also revoke access after it has been issued with out having to rotate the storage keys.
Below are the storage resources that support stored access policies:
Blob containers
File shares
Queues
Tables
First we will create a new storage account in Azure.
Logon to Azure and go to storage accounts. Click Create and add in the basic details and I left the rest as default.
Azure storage account wizard
Once the storage account is deployed, we will be creating a container in the below example its called files.
Blob Container
Go in to the container and create a policy under Access policy.
Blob Container
Give the policy a name, set the required permission and start / end date. Click ok and then save the policy.
Access Policy
Once the policy is create it will show under access policy.
Now that we have the access policy we will need to create a new SAS. There are two ways to create this.
First we can create it directly from Azure storage under Shared access tokens.
Select the Stored access policy. We can also restrict access down to a specific IP.
Next click on Generate SAS token and URL.
We can also use Azure Storage Explorer to create a new SAS.
Logon with an account that has access to the storage account.
Select the storage account that we want to create the SAS for.
Azure Storage Explorer
Select the Access policy, this will then grey out all the options as we are now using the access policy for the SAS.
shared access signature
Click create and this will generate the URL with the SAS key and will also reference the access policy
shared access signature
To test access to the blob we can connect using Storage Explorer.
Click on the connect to Azure Storage and select Blob container.
Azure Storage Explorer Resource Selection
Select SAS
Azure Storage Explorer Connection Method
Give the connection a name and add in the SAS URL generated earlier.
Azure Storage Explorer Connection Info
The last screen is a summary of details once all are confirmed, click connect.
Azure Storage Explorer Summery
We have now connected to the Files container we created with the storage policy and SAS.
To test the policy is working we can try delete the a file as I didn’t apply that permission in the policy I get access denied.
File Explorer Activity Monitor
Now we can update the policy and add the delete permission. Click save the policy can take 30 seconds to update.
Access Policy
Now when delete the file it completes without issue.
File Explorer Activity Monitor
Using a stored access policy allow granular access control and also means if we need to change a permission or start / expiry time for an application or user that is using the SAS URL, we no longer have to re-issue each time we can just update the storage policy used for the SAS.
When deploying VMs in Azure using template we need to be able to check the VM SKU and sizes to be able to update templates to deploy different OS version and VMs sizes.
There are a few different methods that can be used.
There is the Microsoft document, below is the link to the virtual machine size docs.
This is ok when deploying resources that require only a few values to be set, but this can become difficult to manage when there are a lot of parameter like when deploying virtual machines or web apps.
A parameter file for Bicep is a json file that has the specific parameter names and values set.
I used this Microsoft document as a reference to create the parameter file.
Next we will create a template to deploy a virtual machine and it network interface. To create base template in visual studio code type
res-nic to populate the network interface:
Use res-vm-windows to populate the virtual machine.
I will be creating parameters for each part that requires customization and anything that doesn’t I will leave with the hardcode values like. The @descirpiton is a Parameter decorators that allow use to add a description of what the parameter is used for.
I create two variables for the vnetId and subnetref that are used for the network interface
Below is what the updated virtual machine resource template looks like.
Once we have the Bicep template file ready the next step is to configure the parameter file. I copied the default template file code from the above Microsoft document and added in each of the required parameters.
To get the virtual network ID that will be used in the parameters file go to the virtual network and click on properties > Resource ID.
Once we have that we can fill out the reset of the parameter values.
After the template file has been configured, we can test the deployment same way as the storage account and use the whatif to confirm there are no errors.
As I have not set the admin password in the template or parameter file the deployment will prompt for the admin password to be set on the VM.
If the test deployment comes back without any issues we can check the results from the whaif deployment to confirm all the are correct.
Since the template and parameter files have returned no error we are ready to run and deploy the new VM resource.
If we check the resource group the new VM, OSDisk and network interface should be created.
Now that we have all the template and parameter file working we can just create a new parameter file for each VM resource. We can now create fully customized VM’s pretty quickly instead of having to deploy using the Azure market place and manually select the options we want to set.
In a previous post we went through deploying resource using ARM templates. I have been recently working on creating some new templates to be used for additional deployment and decided to use Bicep templates instead as it seem to an easier and more straight forward way of writing template files to deploy resources in Azure.
Bicep uses a simpler syntax than creating templates using JSON, the syntax is declarative and specifies which resources and resource properties you want to deploy.
Below is a comparison of a JSON and Bicep template file to create a storage account.
We can see that the bicep file is an easier format to read and create.
JSON TemplateBicep Template
To get started with Bicep we will first be installing the Bicep extension to Visual Studio Code so we can edit and modify Bicep templates.
The extension adds intellisense which makes it easier than looking up the full syntax for each resource.
To create a new template click on new file in VS code and select bicep as the language.
To create a template using intellisense either start typing the res-resource type or the resource type itself.
Click on the resource to pre populate the template.
The values can be hard code in the template file but this would require manual change each time the template is run.
We can add parameters to the template to make it more reusable. There are a few different types of parameters that can be used.
Below is a brief description of each type.
Parameter
Description
string
Single line value
array
Allow multiple values
int
Integer value
bool
Required true or false
objects
Allows property types
Microsoft have a more in depth document on the different data types.
The below is an example of a template with parameters set.
Once we have the template we need to install Azure PowerShell if not already installed and to install the Bicep tools, below is the document to install.
Once connected we can use the New-AzResourceGroupDeployment to deploy the template and specify the parameters values. To test the deployment for errors without running an actual deployment we can use the -whatif parameter.
Run the command and it should return any error if there is an issue or green if there is no issue.
Once the template comes back with no issues we can remove the -whatif and the storage account will be created.
To confirm the storage account has been created use the Get-AzStorageAccount
Using parameters in the Bicep template is fine when there are only a few that need to be called but for more complex deployment it will be better to use a parameters file and pre fill each value.
In the next post we will go through the process of using a template to create a VM and its network interface and will call a parameters files instead of call the parameters in PowerShell directly.
During a recent project I have been deploying new VM to Azure, when trying to configure the Azure VM backup I was getting a failure at taking snapshot.
The error that showed in the reason was UserErrorRequestDisallowedByPolicy.
This was being caused by a policy that one of the Azure Admins had setup to require tags be configure on resource groups. When a initial backup is run it creates a resource group to save the restore point collection to and it is this resource group that is getting blocked by the Azure tag policy.
To view the policy details we can go to Policy > assignments
Click on the policy to view the parameter’s.
There are two option to work around this issue, either changing the policy from a Deny effect to a Modify effect, or create the resource group manually.
I will be creating a manual resource group as I am not that familiar with creating custom policy yet and this was the quicker workaround.
Below is the link to the Microsoft document on creating a manual resource group for restore collection point.
Here are the steps that I did to get around this, by manually creating the resource group that will be used for the backup.
This needs to be RG name with 1 as this starting number in my case I used TheSleepyAdmin_Backup_RG1.
In the backup policy we specify the new resource group. Go to Azure Backup center > Backup policies.
Put in the name of the resource group we create manually without the number. In my case this was TheSleepyAdmin_Backup_RG
Wait for the policy update to complete.
Now try the backup again and it should complete.
If we check the resource group we can see that the restore point collection has been created.
Any addtional backup should now also be successfully, if the resource group becomes full it will try to create a new RG so there maybe a need to create another RG in the future. I will be having a look at creating or updating the tag policy to apply a modify instead of a deny but that will be in a different post as this seems like it would be a better longer term solution.
In this post we will go over the different methods to enabled accelerated networking in an existing Azure VM.
Accelerated networking improves performance as it allows the network interfaces of Azure VM to bypass the host.
Screen shot from Microsoft documentation
Below are some of the benefits of using accelerated network.
Lower Latency / Higher packets per second
Reduced jitter,
Decreased CPU utilization
Accelerated networking is only supported on VM that have 2 or more CPU’s. If the VM’s are in a availability set all VM’s in the set need to be powered off before updating.
There are three way’s to enabled accelerated networking on existing VMs use either AZ PowerShell Module or the AZ CLI and directly in the Azure portal.
To enable in the Azure portal go to Virtual machines > Networking and select the required network interface.
To enable first Power off the VM,
Select the network interface and click on the name. This will bring you to the network interface configuration page.
Click on enable accelerated networking
You will have to confirm you have validate that your operating system is supported.
Once completed the network interface should now show have accelerated networking enabled.
Enabling in the console is fine for one or two interfaces but if there are a few to update doing PowerShell or AZ CLI will be a quicker method.
To update using the AZ PowerShell Module, first we need to install the module.
Once the command completes, we can run the command to check the network interfaces again and one should now have enabledaccleratednetworking set to true.
If there were multiple network interfaces in the resource group to enable, we could get the list and loop through each, but each VM would need to be supported or they would error out.
With some of the recent critical vulnerability’s for both VMware and Log4j vulnerability this is has shown again that having vCenter open on the internet is not a good idea as it leave a big target for hackers to try exploit.
There are several ways to avoid having vCenter directly available on the internet, in this post we will be going through publishing using the Microsoft Azure Application Proxy. This will be using Azure AD as an authentication source and we can add addtional security like MFA.
First before we can use the Azure Application Proxy we need to make sure we have an Azure subscription and the appropriate license types. The application proxy is available for users that have either a Azure AD P1 or P2 license.
Once all the pre requisite are meet we can install the Azure Application Proxy, we will be using a Windows Server 2019 VM.
For Windows Server 2019 we need to disable http2 protocol, to disable run the below command from PowerShell.
To download the installer, logon to the Azure portal > Azure Active Directory > Application proxy.
Once downloaded run the installer on the server that will be used for the app proxy. To register the connector the minimum rights is to be part of the application administrator role in Azure.
During the install we will be prompted to enter details for an account that has the correct permissions.
The install can take a minute or two to finish.
Once the install has completed the Azure Application proxy connector should show in Azure.
Now that we have the proxy connected to Azure, we will need to register the enterprise application.
Go to Azure AD > Enterprise applications > create your own application
Give the application a name and click create.
Next
Give the app a name
Add in the internal URL for vCenter
Set external URL this can either be an msappproxy.net address or custom domain named
Set the pre authentication to either Azure AD or passthrough (to use MFA or conditional access policy set to Azure AD)
Set the connector group
I left the addtional settings as the defaults. If the internal and external URL are different (its recommend from Microsoft to use the same DNS address), then to allow the redirect set the translate URLs in > Application Body to yes so allow link translation from the external to internal URL.
Click create, the app can take a few minutes provision.
We can restrict access to the app by using security groups or induvial users access.
Once we have setup the access group we can now connect to the external URL.
If the internal application is using an self singed cert or un trusted certificate authority, then the cert will need to be add to the trusted root cert store on the application proxy server.
This is the TLS error:
There should also be event log 13001 log under Applications and Services Logs/Microsoft- AAD Application Proxy Connector/Admin.
Download the root CA cert from vCenter and install to the trusted root on the server that has the Azure Application Proxy connector installed.
The second option is to use a custom SSL cert for vCenter, I have done a previous post on how to install a custom cert.
After this has been completed the page should now load without issue using the external Azure msapproxy address.
If the application proxy is set to use pre authentication then users will be redirected to the sign in page for Azure and be subject to any conditional access policies.
When connecting from an account that has not been give access rights they will not be able to connect.
The VMware remote console does not work using the Azure Application proxy as it requires both port 443 and 902, the application proxy can’t connect on 902 so the connection fails.
I have recently been looking at using Azure Resource Manager templates (ARM) to deploy and redeploy resources in Azure. I haven’t really done a lot with ARM templates so I though it might be helpful to do a few test runs and try figure out how to deploy resource in Azure using ARM templates.
In this post we will be going to through creating a ARM template from an existing resource group and what we need to do to redeploy to a new resources group.
ARM Templates are JSON files that define the infrastructure and configuration that will be deploy.
First we are going to export the template from Azure resource group that we want to redeploy to another resource group.
Logon to the Azure portal and go to resource groups.
Select the resource group that we want to export the template from.
Go to Automation and select export template.
This will bring up the ARM template for the resource group. We can then download the template to modify, I will be using visual studio code with the Azure Resource Manager (ARM) Tools extension added to edit the template.
Once the zip file is download and extracted there will be two JSON files, parameters’ and template.
When we look at the template file itself there will be a set of parameters. There are default values for each parameters which are the names of each resource in the resource group. I remove the default values.
The parameters are what is used to define the name of the resources that are created.
When I first started to look at the ARM templates they did seem very confusing but if you break them up in to each part instead of looking at it as a whole it made a lot easier for me to understand how the template worked.
If we take the below as a example this part of the JSON defines the virtual network and subnet to be created. It sets the location, subnet prefixes and one subnet for 10.0.0.0/24.
If there are IP address assigned or the subnet need to be changed this can be updated in the JSON file.
Once the JSON file has been modified we can then use this to deploy to Azure. The two way we will be going through in this post is using Azure portal Deploy from a custom template and second we will be going through adding the parameters to the parameters JSON and deploy using PowerShell.
First we will go through the portal deployment.
Logon to the Azure portal and go to deploy from a custom template.
We could search for template using the quick start template if we don’t have a existing template
but we will be using build your own template so we will be selecting build your own template.
Once the blade opens click load file and select the JSON template file this will then load the template.
Click save this should then a view like the below that we can manually in put the details we want to use for the deployment.
Click next and the arm template will be validated.
Click create to start the deployment.
When I deployed the template I had some issues with the VM creation.
This was caused by a few different issue. The first was the managed disk which returned the below error.
“Parameter ‘osDisk.managedDisk.id’ is not allowed.”
The last issue was due to the admin password not being set. To fix this I added a new parameter at the start of the template
and set it under below under os profile
Once this was done I went back to deploy a custom template and readd the details which should now have the addtional admin password field.
The deployment now completed without issue.
The resources now be deployed to the resource group.
The second method we will be going through to deploy the ARM template is to use PowerShell.
We will be using the New-AzResourceGroupDeployment command to deploy the template.
We first will be modifying the parameters file to set the names that will be used.
For the adminpassword I will be adding the password to the parameter’s file but in production this should not be done and instead use something like Azure key vault to store the password.
First we need to install the Azure module
Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force
Next we run
Connect-AzAccount
Next we run the New-AzResourceGroupDeployment I used the verbose parameter to get more details on the deployment. We will be calling the template and parameter JSON files.
New-AzResourceGroupDeployment -ResourceGroupName "resource group" -TemplateFile "path to template json" -TemplateParameterFile "path to parameters json"
Below is the command running and provisioning the resources in the template.
Once the deployment completes all the resources will show under the resource group.
We can also use the ARM template to redeploy a resource that has been removed.
If we run the New-AzResourceGroupDeployment again after a resource has been deleted the deployment picks up that the missing resources and redeploys.
This was my first attempt at doing ARM and it not as complicated as I first thought I will probable do a few more post in the future after I have some more time working with ARM templates.
In this post we will be going through creating an automate report to list all assigned Azure roles and user/group assignments using Microsoft Graph SDK.
This can be useful for environments that haven’t implemented Microsoft privileged identity management for roles management. This can be used to keep track of roles assignments in Azure.
I will be using Microsoft Graph SDK, if you haven’t used this before I have done a previous post on installing and getting start with the Graph SDK.
I will be using a app registration in Azure AD with certificate authentication (I covered this in one of my previous posts) so I don’t have to use any username or password with the script. We will need to add the required API permission.
To find the specific commands that I needed to use, I generally search for them on the Graph module reference document link below as there are a lot of commands in the Graph SDK module.
Select the Graph registration that was previously created. Under the API permissions select add permissions and add the the required application permissions to run the command.
In this case we will be using the rolemanagment.read.all
Once the API permission is added we can start to create the script.
To get the list of directory roles that are currently in use use
Get-MgDirectoryRole
Then to get the assigned objects use the below command and copy the ID to view details.