- Create a key vault
- Generate a self signed certificate in the key vault - ensure that the private key is marked as exportable
- Export the certificate as a
.cerfile - Upload the certificate to the Azure DevOps SPN
- Create a new variable group
| Param($TenantId, $LogicAppName) | |
| # Microsoft Graph App ID (DON'T CHANGE) | |
| $GraphAppId = "00000003-0000-0000-c000-000000000000" | |
| # Check the Microsoft Graph documentation for the permission you need for the operation | |
| switch -Regex ($LogicAppName) { | |
| "group" { $PermissionNames = @("User.Read.All", "GroupMember.ReadWrite.All") } | |
| "licence" { $PermissionNames = @("User.ReadWrite.All") } | |
| } |
| { | |
| "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", | |
| "contentVersion": "1.0.0.0", | |
| "parameters": { | |
| "input": { | |
| "value": { | |
| "Name": "Deploy-VNET-HubConnection", | |
| "ResourceType": "Microsoft.Authorization/policyDefinitions", | |
| "Properties": { | |
| "Description": "This policy deploys a virtual wan hub network connection", |
| { | |
| "mode": "All", | |
| "policyRule": { | |
| "if": { | |
| "allOf": [ | |
| { | |
| "field": "type", | |
| "equals": "Microsoft.Resources/subscriptions" | |
| } | |
| ] |
| { | |
| "mode": "All", | |
| "policyRule": { | |
| "if": { | |
| "allOf": [ | |
| { | |
| "field": "type", | |
| "equals": "Microsoft.Compute/virtualMachines" | |
| }, | |
| { |
| $app_id = "" | |
| $tenant_id = "" | |
| $app_key = "" | |
| function Get-GraphToken { | |
| Param([string]$ApplicationId, $TenantName, $AppPassword) | |
| $Url = "https://login.microsoftonline.com/$TenantName/oauth2/v2.0/token" | |
| $Body = @{ |
| Connect-MgGraph -ClientId $app_id -TenantId $tenant_id -CertificateThumbprint $cert.Thumbprint | |
| Select-MgProfile -Name beta | |
| $roleDefinitionHash = @{} | |
| Get-MgRoleManagementDirectoryRoleDefinition | ForEach-Object { | |
| $roleDefinitionHash.Add($_.Id, $_.DisplayName) | |
| } |
| enum Ensure { | |
| Absent | |
| Present | |
| } | |
| [DscResource()] | |
| class classFeature { | |
| [DscProperty(Key)] |
| { | |
| "version": "Notebook/1.0", | |
| "items": [ | |
| { | |
| "type": 1, | |
| "content": { | |
| "json": "# Security assessment recommendations workbook\r\n\r\n\r\n\r\nFor more information visit [Microsoft Azure Well-Architected Framework](https://docs.microsoft.com/en-us/azure/architecture/framework/security/)" | |
| }, | |
| "name": "text - 9" | |
| }, |
| function Get-GraphTokenWithCertificate { | |
| Param([string]$ApplicationId, $TenantName, $CertificatePath) | |
| # Create base64 hash of certificate | |
| $Certificate = Get-Item $CertificatePath | |
| $CertificateBase64Hash = [System.Convert]::ToBase64String($Certificate.GetCertHash()) | |
| # Create JWT timestamp for expiration | |
| $StartDate = (Get-Date "1970-01-01T00:00:00Z" ).ToUniversalTime() | |
| $JWTExpirationTimeSpan = (New-TimeSpan -Start $StartDate -End (Get-Date).ToUniversalTime().AddMinutes(2)).TotalSeconds |