ค้นหาเว็บไซต์

วิธีสร้างนโยบายการเข้าถึงแบบมีเงื่อนไขด้วย Microsoft Graph PowerShell


นโยบายการเข้าถึงแบบมีเงื่อนไขช่วยให้ผู้ดูแลระบบสามารถกำหนดค่าและบังคับใช้ระดับความปลอดภัยพื้นฐานสำหรับผู้เช่าของเรา ผู้ดูแลระบบอาจจำเป็นต้องกำหนดค่านโยบายมาตรฐานหลายรายการให้กับผู้เช่าที่แตกต่างกันหรือเพียงโดยทางโปรแกรมด้วย PowerShell

ในบทช่วยสอนนี้ ฉันจะแสดงวิธีกำหนดค่านโยบายการเข้าถึงแบบมีเงื่อนไขโดยใช้ Microsoft Graph PowerShell

เกี่ยวกับ cmdlet MgIdentityConditionalAccessPolicy ใหม่

พบคำสั่ง New-MgIdentityConditionalAccessPolicy ภายในโมดูล Microsoft.Graph.Identity.SignIns และใช้เพื่อสร้างนโยบายการเข้าถึงแบบมีเงื่อนไขใหม่ใน Microsoft Entra

มีพารามิเตอร์ที่จำกัดสำหรับ cmdlet นี้ ซึ่งหมายความว่าไม่สามารถกำหนดการตั้งค่าทั้งหมดด้วยพารามิเตอร์ของตัวเองได้ แต่การตั้งค่าทั้งหมดจะต้องถูกกำหนดไว้ในตารางแฮชซึ่งจะถูกแยกวิเคราะห์เป็นพารามิเตอร์ -BodyParameter

หากคุณยังไม่ได้ติดตั้งโมดูล Microsoft Graph PowerShell โปรดดูบทช่วยสอนทั้งหมดของฉันสำหรับการติดตั้ง Microsoft Graph PowerShell: https://ourcloudnetwork.com/how-to-install-the-microsoft-graph-powershell-sdk/

สิทธิ์ที่จำเป็นในการสร้างนโยบายการเข้าถึงแบบมีเงื่อนไขใหม่

สิทธิ์หลักที่จำเป็นในการสร้างนโยบายคือสิทธิ์ Policy.ReadWrite.ConditionalAccess API อย่างไรก็ตาม มันไม่ได้เป็นไปตามที่คาดหวัง… แม้ว่าคุณสามารถใช้การอนุญาตนี้เพื่อสร้างนโยบายใหม่ได้ แต่จะไม่อนุญาตให้คุณอ่านนโยบายทั้งหมดเมื่อสร้างขึ้นแล้ว

นโยบายอื่นอีกสองนโยบายให้ระดับการเข้าถึงเพิ่มเติม ช่วยให้คุณสามารถอ่านนโยบายหรือการตั้งค่านโยบายได้ ได้แก่:

  • นโยบาย อ่านทั้งหมด
  • แอปพลิเคชั่น อ่านทั้งหมด

คุณสามารถดูรายละเอียดการอนุญาตและการตั้งค่าทั้งหมดสำหรับ New-MgIdentityConditionalAccessPolicy cmdlet ได้โดยใช้คำสั่งต่อไปนี้:

Find-MgGraphCommand New-MgIdentityConditionalAccessPolicy | fl

ผลลัพธ์ของคุณจะมีลักษณะดังนี้:

Command     : New-MgIdentityConditionalAccessPolicy
Module      : Identity.SignIns
APIVersion  : v1.0
Method      : POST
URI         : /identity/conditionalAccess/policies
OutputType  : IMicrosoftGraphConditionalAccessPolicy
Variants    : {Create, CreateExpanded}
Permissions : {Application.Read.All, Policy.Read.All, Policy.ReadWrite.ConditionalAccess}

สำหรับข้อมูลเพิ่มเติมเกี่ยวกับการค้นหาสิทธิ์การใช้งานกับ Microsoft Graph PowerShell โปรดดูบทช่วยสอนโดยละเอียดของฉันที่นี่: https://ourcloudnetwork.com/how-to-find-permissions-for-microsoft-graph-powershell/

ตัวอย่างนโยบายการเข้าถึงแบบมีเงื่อนไข MgIdentityConditionalAccessPolicy ใหม่

เริ่มต้นด้วยการเชื่อมต่อกับ Microsoft Graph PowerShell โดยใช้ขอบเขตสิทธิ์ที่จำเป็นเพื่อให้คุณสามารถสร้างนโยบายใหม่และอ่านข้อมูลนโยบายทั้งหมด:

Connect-MgGraph -scopes Policy.Read.All, Policy.ReadWrite.ConditionalAccess

จากนั้นคุณสามารถใช้โค้ดตัวอย่างต่อไปนี้เพื่อสร้างนโยบายใหม่ชื่อ 'MFA สำหรับผู้ใช้ทั้งหมด' โดยมีการตั้งค่าพื้นฐานบางอย่าง:

  • กำหนดเป้าหมายผู้ใช้ทั้งหมด
  • กำหนดเป้าหมายแอปคลาวด์ทั้งหมด
  • ต้องมีกระทรวงการคลัง
  • เปิดใช้งานสำหรับการรายงานเท่านั้น
$body = @{
  displayName = "MFA for all users "
  state = "enabledForReportingButNotEnforced"
  conditions = @{
    applications = @{
      includeApplications = @(
        "All"
      )
    }
    users = @{
      includeUsers = @(
        "All"
      )
    }
    clientAppTypes = @(
      "all"
    )
  }
    grantControls = @{
    operator = "AND"
    builtInControls = @(
      "mfa"
    )
  }
}

New-MgIdentityConditionalAccessPolicy -BodyParameter $body

การตั้งค่าทั้งหมดสำหรับ New-MgIdentityConditionalAccessPolicy

มีการตั้งค่าต่างๆ มากมายที่คุณสามารถใช้กับนโยบายการเข้าถึงแบบมีเงื่อนไขได้ เช่น โค้ดด้านล่างนี้แสดงถึงการตั้งค่าที่มีอยู่ทั้งหมดที่คุณสามารถกำหนดได้ในพารามิเตอร์การเข้าถึงแบบมีเงื่อนไขของคุณ:

เงื่อนไข

เงื่อนไขทั้งหมดจะต้องรวมอยู่ในตารางแฮชเงื่อนไข:

Conditions = {
    #Conditions here
}

ผู้ใช้

การตั้งค่าทั้งหมดสำหรับเงื่อนไขผู้ใช้อยู่ด้านล่าง:

users = @{
			includeUsers = @(
				"All Users" #use "All user" or define mulitple user IDs
			)
			excludeUsers = @(
				"UserID" #Define the excluded users IDs
			)
			includeGroups = @(
			    "GroupID" #Define the included groups IDs
			)
			excludeGroups = @(
			    "GroupID" #Define the excluded groups IDs
			)
			includeRoles = @(
				"9b895d92-2cd3-44c7-9d02-a6ac2d5ea5c3" #Define the role IDs
			)
			excludeRoles = @(
				"b0f54661-2d74-4c50-afa3-1ec803f12efe" #Define the role IDs
			)
            includeGuestsOrExternalUsers = @{
                guestOrExternalUserTypes = "B2bCollaborationGuest,B2bCollaborationMember,B2bDirectConnectUser,InternalGuest,ServiceProvider,OtherExternalUser"
                externalTenants = @{
                    membershipKind = "all"
                } 
            } #Define the enternal and guest user types
            excludeGuestsOrExternalUsers = @{
                guestOrExternalUserTypes = "B2bCollaborationGuest,B2bCollaborationMember,B2bDirectConnectUser,InternalGuest,ServiceProvider,OtherExternalUser"
                externalTenants = @{
                    membershipKind = "all"
                } #Define the enternal and guest user types
            } #Define the enternal and guest user types
		}

ทรัพยากรเป้าหมาย

การตั้งค่าทั้งหมดสำหรับเงื่อนไขทรัพยากรเป้าหมายมีดังต่อไปนี้:

	applications = @{
			includeApplications = @(
				"All" #Define all applications or the application IDs
			)
			applicationFilter = @{
                mode = "include"
                rule = "CustomSecurityAttribute.DanielWasHere_Test -eq \"Yes\""
            } #Use the web portal to create the rule syntax
			excludeApplications = @(
				"499b84ac-1321-427f-aa17-267ca6975798"
			) #Define applications by the application IDs
			includeUserActions = @(
			    "urn:user:registersecurityinfo"
			    "urn:user:registerdevice"
			) #Define either of both user actions
            includeAuthenticationContextClassReferences = @( 
                "c1"
                "c2"
            ) #Define authentication context by the ID
            globalSecureAccess = @{
                includeTrafficProfiles =  "M365"
            } #Define Global secure access profile by the profile name
		}

แพลตฟอร์ม

การตั้งค่าทั้งหมดสำหรับเงื่อนไขของแพลตฟอร์มมีดังต่อไปนี้:

platforms = @{
			includePlatforms = @(
				"all"
				"adroid"
				"iOS"
				"WindowsPhones"
				"Windows"
				"macOS"
				"linux"
			) #Define each platform or all platforms
			excludePlatforms = @(
				"all"
				"adroid"
				"iOS"
				"WindowsPhones"
				"Windows"
				"macOS"
				"linux"
			) #Define each platform or all platforms
		}

สถานที่

การตั้งค่าทั้งหมดสำหรับสภาพตำแหน่งมีดังต่อไปนี้:

locations = @{
			includeLocations = @(
			    "all"
				"AllTrusted"
				"3d46dbda-8382-466a-856d-eb00cbc6b910" #all compliant network locations
				"Custom network location ID"
			) #Define one of the above options
			excludeLocations = @(
                "AllTrusted"
				"Custom network location ID"
			) #Define one of the above options
		}

ความเสี่ยงของผู้ใช้และความเสี่ยงในการลงชื่อเข้าใช้

การตั้งค่าทั้งหมดสำหรับความเสี่ยงของผู้ใช้และเงื่อนไขความเสี่ยงในการลงชื่อเข้าใช้มีดังต่อไปนี้:

signInRiskLevels = @(
	"high"
	"medium"
	"low"
	"none"
) #Select one or all of the above options
UserRiskLevels = @(
	"high"
	"medium"
) #Select one or all of the above options
        signInRiskDetections = $null

แอปไคลเอ็นต์

การตั้งค่าทั้งหมดสำหรับเงื่อนไขแอปไคลเอ็นต์อยู่ด้านล่าง:

clientAppTypes = @(
	"browser"
	"mobileAppsAndDesktopClients"
	"exchangeActiveSync"
	"other"
) #Select on or all of the above app types

ให้การควบคุม

การตั้งค่าทั้งหมดสำหรับการควบคุมการให้สิทธิ์อยู่ด้านล่าง:

grantControls = @{
	operator = "OR" #Select the AND or OR operator
	builtInControls = @(
		"mfa"
		"compliantDevice"
		"domainJoinedDevice"
		"approvedApplication"
		"compliantApplication"
	) #Chose from the above options
	customAuthenticationFactors = @(
	)
	termsOfUse = @(
		"ce580154-086a-40fd-91df-8a60abac81a0"
		"7f29d675-caff-43e1-8a53-1b8516ed2075"
	) #Define ID of the terms of use policy
    authenticationStrength = @{
        id = "db443b3a-6c4e-45f5-aa9a-7819e56d2987"
    } #Define the ID of your authentication stenght (built-in or custom works)
}

การควบคุมเซสชัน

การตั้งค่าทั้งหมดสำหรับการควบคุมเซสชันอยู่ด้านล่าง:

sessionControls = @{
	applicationEnforcedRestrictions = $null
	persistentBrowser = @{
        mode = "always" # or "never"
        isEnabled = "true"
    } #Define persistent browser settings
	cloudAppSecurity = @{
		cloudAppSecurityType = "blockDownloads" # or "MonitorOnly"
		isEnabled = $true
	} #Define cloud app security policy
    continuousAccessEvaluation = @{
        mode = "strictLocation"
    } #remove is not needed
    secureSignInSession = @{
        isEnabled = $true
        secureAppSessionMode = "notEnforced"
    } #Define token protection settings
    disableResilienceDefaults = $true
	signInFrequency = @{
		value = 4
		type = "hours"
		isEnabled = $true
	} #Define sign-in frequency settings
    globalSecureAccessFilteringProfile = $null
}

สถานะ

ใช้ตัวเลือกต่อไปนี้เพื่อควบคุมสถานะของนโยบาย:

state = "enabled"
        "disabled"
        "enabledForReportingButNotEnforced"

บทความที่เกี่ยวข้อง