<# .SYNOPSIS Bölüm 02 · Adım 2.1 — Break-Glass Grubu, Named Location ve 12 Politikalık Zero Trust CA Serisi .DESCRIPTION Entra ID üzerinde SG-CA-BreakGlass-Exclude dışlama grubunu, NL-Blocked-HighRisk-Countries coğrafi konumunu ve CA01..CA12 Zero Trust Conditional Access serisini (CA01..CA09 Aktif, CA10..CA12 Report-Only) Microsoft Graph üzerinden dağıtır. ÖN KOŞUL: Entra ID Properties -> Manage security defaults -> Disabled yapılmalıdır. .EXAMPLE pwsh -ExecutionPolicy Bypass -File "D:\Lab\Scripts\01-Deploy-BreakGlass-And-CA-Matrix.ps1" #> param( [string]$ExcludeGroupName = "SG-CA-BreakGlass-Exclude" ) $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/4] Break-Glass dışlama grubu kontrol ediliyor: $ExcludeGroupName" -ForegroundColor Cyan $grp = (Invoke-RestMethod -Method GET -Uri "https://graph.microsoft.com/v1.0/groups?`$filter=displayName eq '$ExcludeGroupName'" -Headers $headers).value | Select-Object -First 1 if (-not $grp) { $grpBody = @{ displayName = $ExcludeGroupName mailEnabled = $false mailNickname = 'sg-ca-breakglass-exclude' securityEnabled = $true description = 'Conditional Access politikalarından hariç tutulan Break-Glass acil durum hesapları' } | ConvertTo-Json $grp = Invoke-RestMethod -Method POST -Uri 'https://graph.microsoft.com/v1.0/groups' -Headers $headers -Body $grpBody Write-Host " [+] Oluşturuldu: $($grp.displayName) ($($grp.id)) — Break-Glass hesabınızı bu gruba eklemeyi unutmayın!" -ForegroundColor Yellow } $bgGroupId = $grp.id $adminRoles = @( '62e90394-69f5-4237-9190-012177145e10', # Global Administrator 'e8611ab8-c189-46e8-94e1-60213ab1f814', # Privileged Role Administrator '194ae4cb-b126-40b2-bd5b-6091b380977d', # Security Administrator 'b1be1c3e-b65d-4f19-8427-f6fa0d97feb9', # Conditional Access Administrator '29232cdf-9323-42fd-ade2-1d097af3e4de', # Exchange Administrator 'f28a1f50-f6e7-4571-818b-6a12f2af6b6c', # SharePoint Administrator '3a2c62db-5318-420d-8d74-23affee5d9d5', # Intune Administrator '17315797-102d-40b4-93e0-432062caca18', # Compliance Administrator 'fe930be7-5e62-47db-91af-98c3a49a38b1', # User Administrator '7be44c8a-adaf-4e2a-84d6-ab2649e08a13', # Privileged Authentication Administrator '9b895d92-2cd3-44c7-9d02-a6ac2d5ea5c3', # Application Administrator '158c047a-c907-4556-b7ef-446551a6b5f7' # Cloud Application Administrator ) Write-Host "[2/4] Named Location oluşturuluyor: NL-Blocked-HighRisk-Countries" -ForegroundColor Cyan $nl = (Invoke-RestMethod -Method GET -Uri 'https://graph.microsoft.com/v1.0/identity/conditionalAccess/namedLocations' -Headers $headers).value | Where-Object { $_.displayName -eq 'NL-Blocked-HighRisk-Countries' } | Select-Object -First 1 if (-not $nl) { $nlBody = @{ '@odata.type' = '#microsoft.graph.countryNamedLocation' displayName = 'NL-Blocked-HighRisk-Countries' countriesAndRegions = @('KP', 'IR', 'SY', 'CU', 'RU', 'BY') includeUnknownCountriesAndRegions = $false } | ConvertTo-Json -Depth 5 $nl = Invoke-RestMethod -Method POST -Uri 'https://graph.microsoft.com/v1.0/identity/conditionalAccess/namedLocations' -Headers $headers -Body $nlBody } $nlBlockedId = $nl.id Write-Host "[3/4] 12 Politikalık Zero Trust Conditional Access serisi dağıtılıyor..." -ForegroundColor Cyan $policies = @( @{ displayName = 'CA01-Global-Block-LegacyAuth'; state = 'enabled'; conditions = @{ clientAppTypes = @('exchangeActiveSync','other'); applications = @{ includeApplications = @('All') }; users = @{ includeUsers = @('All'); excludeGroups = @($bgGroupId) } }; grantControls = @{ operator = 'OR'; builtInControls = @('block') } }, @{ displayName = 'CA02-Global-Require-MFA-AllUsers'; state = 'enabled'; conditions = @{ clientAppTypes = @('browser','mobileAppsAndDesktopClients'); applications = @{ includeApplications = @('All') }; users = @{ includeUsers = @('All'); excludeGroups = @($bgGroupId) } }; grantControls = @{ operator = 'OR'; builtInControls = @('mfa') } }, @{ displayName = 'CA03-IdentityProtection-HighUserRisk-Remediate'; state = 'enabled'; conditions = @{ userRiskLevels = @('high'); clientAppTypes = @('all'); applications = @{ includeApplications = @('All') }; users = @{ includeUsers = @('All'); excludeGroups = @($bgGroupId) } }; grantControls = @{ operator = 'AND'; builtInControls = @('mfa','passwordChange') }; sessionControls = @{ signInFrequency = @{ isEnabled = $true; frequencyInterval = 'everyTime' } } }, @{ displayName = 'CA04-IdentityProtection-SignInRisk-RequireMFA'; state = 'enabled'; conditions = @{ signInRiskLevels = @('medium','high'); clientAppTypes = @('all'); applications = @{ includeApplications = @('All') }; users = @{ includeUsers = @('All'); excludeGroups = @($bgGroupId) } }; grantControls = @{ operator = 'OR'; builtInControls = @('mfa') }; sessionControls = @{ signInFrequency = @{ isEnabled = $true; frequencyInterval = 'everyTime' } } }, @{ displayName = 'CA05-Geo-Block-HighRisk-Countries'; state = 'enabled'; conditions = @{ clientAppTypes = @('all'); applications = @{ includeApplications = @('All') }; locations = @{ includeLocations = @($nlBlockedId) }; users = @{ includeUsers = @('All'); excludeGroups = @($bgGroupId) } }; grantControls = @{ operator = 'OR'; builtInControls = @('block') } }, @{ displayName = 'CA06-Global-Protect-SecurityInfo-Registration'; state = 'enabled'; conditions = @{ clientAppTypes = @('all'); applications = @{ includeUserActions = @('urn:user:registersecurityinfo') }; users = @{ includeUsers = @('All'); excludeGroups = @($bgGroupId) } }; grantControls = @{ operator = 'OR'; builtInControls = @('mfa') } }, @{ displayName = 'CA07-Admin-Session-4h-NoPersistentBrowser'; state = 'enabled'; conditions = @{ clientAppTypes = @('all'); applications = @{ includeApplications = @('All') }; users = @{ includeRoles = $adminRoles; excludeGroups = @($bgGroupId) } }; grantControls = @{ operator = 'OR'; builtInControls = @('mfa') }; sessionControls = @{ signInFrequency = @{ value = 4; type = 'hours'; isEnabled = $true }; persistentBrowser = @{ mode = 'never'; isEnabled = $true } } }, @{ displayName = 'CA08-Guest-Require-MFA-SessionLimit'; state = 'enabled'; conditions = @{ clientAppTypes = @('all'); applications = @{ includeApplications = @('All') }; users = @{ includeGuestsOrExternalUsers = @{ guestOrExternalUserTypes = 'internalGuest,b2bCollaborationGuest,b2bCollaborationMember,b2bDirectConnectUser,otherExternalUser,serviceProvider'; externalTenants = @{ '@odata.type' = '#microsoft.graph.conditionalAccessAllExternalTenants'; membershipKind = 'all' } }; excludeGroups = @($bgGroupId) } }; grantControls = @{ operator = 'OR'; builtInControls = @('mfa') }; sessionControls = @{ signInFrequency = @{ value = 1; type = 'days'; isEnabled = $true } } }, @{ displayName = 'CA09-Global-Block-DeviceCodeFlow-Phishing'; state = 'enabled'; conditions = @{ clientAppTypes = @('all'); applications = @{ includeApplications = @('All') }; authenticationFlows = @{ transferMethods = 'deviceCodeFlow' }; users = @{ includeUsers = @('All'); excludeGroups = @($bgGroupId) } }; grantControls = @{ operator = 'OR'; builtInControls = @('block') } }, @{ displayName = 'CA10-Admin-Require-PhishingResistant-MFA'; state = 'enabledForReportingButNotEnforced'; conditions = @{ clientAppTypes = @('all'); applications = @{ includeApplications = @('All') }; users = @{ includeRoles = $adminRoles; excludeGroups = @($bgGroupId) } }; grantControls = @{ operator = 'OR'; authenticationStrength = @{ id = '00000000-0000-0000-0000-000000000004' } } }, @{ displayName = 'CA11-Device-Require-Compliant-Or-HybridJoin'; state = 'enabledForReportingButNotEnforced'; conditions = @{ clientAppTypes = @('browser','mobileAppsAndDesktopClients'); platforms = @{ includePlatforms = @('windows','macOS') }; applications = @{ includeApplications = @('Office365') }; users = @{ includeUsers = @('All'); excludeGroups = @($bgGroupId) } }; grantControls = @{ operator = 'OR'; builtInControls = @('compliantDevice','domainJoinedDevice') } }, @{ displayName = 'CA12-Session-AppEnforcedRestrictions-Unmanaged'; state = 'enabledForReportingButNotEnforced'; conditions = @{ clientAppTypes = @('browser'); applications = @{ includeApplications = @('Office365') }; devices = @{ deviceFilter = @{ mode = 'exclude'; rule = 'device.isCompliant -eq True -or device.trustType -eq "ServerAD"' } }; users = @{ includeUsers = @('All'); excludeGroups = @($bgGroupId) } }; sessionControls = @{ applicationEnforcedRestrictions = @{ isEnabled = $true } } } ) $existing = (Invoke-RestMethod -Method GET -Uri 'https://graph.microsoft.com/v1.0/identity/conditionalAccess/policies' -Headers $headers).value foreach ($pol in $policies) { $match = $existing | Where-Object { $_.displayName -eq $pol.displayName } | Select-Object -First 1 $json = $pol | ConvertTo-Json -Depth 10 if ($match) { Invoke-RestMethod -Method PATCH -Uri "https://graph.microsoft.com/v1.0/identity/conditionalAccess/policies/$($match.id)" -Headers $headers -Body $json | Out-Null } else { Invoke-RestMethod -Method POST -Uri 'https://graph.microsoft.com/v1.0/identity/conditionalAccess/policies' -Headers $headers -Body $json | Out-Null } } Write-Host "[4/4] Doğrulama:" -ForegroundColor Green (Invoke-RestMethod -Method GET -Uri 'https://graph.microsoft.com/v1.0/identity/conditionalAccess/policies' -Headers $headers).value | Sort-Object displayName | Select-Object displayName, state | Format-Table -AutoSize