<# .SYNOPSIS Bölüm 02 · Adım 2.5 — Entra ID P2 Tam Güvenlik Sıkılaştırması (CIS + Password Protection) .DESCRIPTION Authorization Policy (7 CIS kontrolü: App/Group/Tenant oluşturma blok, Most Restricted Guest, MSOL PowerShell blok, AdminConsentRequired) ve Entra Password Protection + Smart Lockout uygular. .EXAMPLE pwsh -ExecutionPolicy Bypass -File "D:\Lab\Scripts\05-Deploy-EntraID-Full-Hardening.ps1" #> param( [string[]]$CustomBannedWords = @('Cetinkaya','CanerLab','Istanbul','Turkiye','Kurumsal','Sifre','Holding','EntraLab','Defender','Purview') ) $ErrorActionPreference = 'Stop' $token = (az account get-access-token --resource https://graph.microsoft.com --query accessToken -o tsv).Trim() if (-not $token) { throw "Azure CLI Graph token alınamadı. Önce 'az login' çalıştırın." } $headers = @{ Authorization = "Bearer $token"; 'Content-Type' = 'application/json' } Write-Host "[1/2] Authorization Policy CIS Zero Trust standardına sıkılaştırılıyor..." -ForegroundColor Cyan $authPatch = @{ allowInvitesFrom = 'adminsAndGuestInviters' guestUserRoleId = '2af84b1e-32c8-42b7-82bc-daa82404023b' allowedToUseSSPR = $true blockMsolPowerShell = $true defaultUserRolePermissions = @{ allowedToCreateApps = $false allowedToCreateSecurityGroups = $false allowedToCreateTenants = $false allowedToReadOtherUsers = $true permissionGrantPoliciesAssigned = @() } } | ConvertTo-Json -Depth 5 Invoke-RestMethod -Method PATCH -Uri 'https://graph.microsoft.com/v1.0/policies/authorizationPolicy' -Headers $headers -Body $authPatch | Out-Null Write-Host "[2/2] Entra Password Protection & Smart Lockout uygulanıyor..." -ForegroundColor Cyan $pwdTemplateId = '5cf42378-d67d-4f36-ba46-e8b86229381d' $pwdSetting = (Invoke-RestMethod -Method GET -Uri 'https://graph.microsoft.com/v1.0/groupSettings' -Headers $headers).value | Where-Object { $_.templateId -eq $pwdTemplateId } | Select-Object -First 1 $pwdValues = @( @{ name = 'EnableBannedPasswordCheck'; value = 'true' }, @{ name = 'BannedPasswordList'; value = ($CustomBannedWords -join "`t") }, @{ name = 'LockoutThreshold'; value = '10' }, @{ name = 'LockoutDurationInSeconds'; value = '60' }, @{ name = 'EnableBannedPasswordCheckOnPremises'; value = 'true' }, @{ name = 'BannedPasswordCheckOnPremisesMode'; value = 'Audit' } ) if ($pwdSetting) { Invoke-RestMethod -Method PATCH -Uri "https://graph.microsoft.com/v1.0/groupSettings/$($pwdSetting.id)" -Headers $headers -Body (@{ values = $pwdValues } | ConvertTo-Json -Depth 5) | Out-Null } else { Invoke-RestMethod -Method POST -Uri 'https://graph.microsoft.com/v1.0/groupSettings' -Headers $headers -Body (@{ displayName = 'Password Rule Settings'; templateId = $pwdTemplateId; values = $pwdValues } | ConvertTo-Json -Depth 5) | Out-Null } Write-Host "[+] Canlı doğrulama:" -ForegroundColor Green $v = Invoke-RestMethod -Method GET -Uri 'https://graph.microsoft.com/v1.0/policies/authorizationPolicy' -Headers $headers [PSCustomObject]@{ allowedToCreateApps = $v.defaultUserRolePermissions.allowedToCreateApps allowedToCreateSecurityGroups = $v.defaultUserRolePermissions.allowedToCreateSecurityGroups allowedToCreateTenants = $v.defaultUserRolePermissions.allowedToCreateTenants allowInvitesFrom = $v.allowInvitesFrom guestUserRoleId = $v.guestUserRoleId allowedToUseSSPR = $v.allowedToUseSSPR blockMsolPowerShell = $v.blockMsolPowerShell userConsentPolicies = if ($v.defaultUserRolePermissions.permissionGrantPoliciesAssigned.Count -eq 0) { 'AdminConsentRequired' } else { $v.defaultUserRolePermissions.permissionGrantPoliciesAssigned -join ', ' } } | Format-List