为应用程序管理自定义安全属性

Microsoft Entra ID 中的自定义安全属性是特定于业务的属性(键值对),你可以定义这些属性并将其分配给 Microsoft Entra 对象。 例如,可分配自定义安全属性以筛选应用程序或帮助确定访问者。 本文介绍如何为 Microsoft Entra 企业应用程序分配、更新、列出或删除自定义安全属性。

先决条件

若要为 Microsoft Entra 租户中的应用程序分配或删除自定义安全属性,需要:

重要

默认情况下,全局管理员和其他管理员角色无权读取、定义或分配自定义安全属性。

为应用程序分配、更新、列出或移除自定义属性

了解如何在 Microsoft Entra ID 中处理应用程序的自定义属性。

向应用程序分配自定义安全属性

提示

本文中的步骤可能因开始使用的门户而略有不同。

执行以下步骤,通过 Microsoft Entra 管理门户分配自定义安全属性。

  1. 属性分配管理员身份登录到 Microsoft Entra 管理中心

  2. 浏览到“标识”>“应用程序”>“企业应用程序”。

  3. 查找并选择要向其添加自定义安全属性的应用程序。

  4. 在“管理”部分,选择“自定义安全属性”。

  5. 选择“添加分配”。

  6. 在“属性集”中,从列表中选择一个属性集。

  7. 在“属性名称”中,从列表中选择一个自定义安全属性。

  8. 根据所选自定义安全属性的属性,可以输入单个值、从预定义列表中选择一个值或添加多个值。

    • 对于自由格式的单值自定义安全属性,请在“分配的值”框中输入一个值。
    • 对于预定义的自定义安全属性值,请从“分配的值”列表中选择一个值。
    • 对于多值自定义安全属性,请选择“添加值”以打开“属性值”窗格并添加值。 完成添加值后,选择“完成”。

    Screenshot shows how to assign a custom security attribute to an application.

  9. 完成后,选择“保存”,将自定义安全属性分配给应用程序。

更新应用程序的自定义安全属性分配值

  1. 属性分配管理员身份登录到 Microsoft Entra 管理中心

  2. 浏览到“标识”>“应用程序”>“企业应用程序”。

  3. 找到并选择具有要更新的自定义安全属性分配值的应用程序。

  4. 在“管理”部分,选择“自定义安全属性”。

  5. 找到要更新的自定义安全属性分配值。

    向应用程序分配自定义安全属性后,只能更改自定义安全属性的值。 不能更改自定义安全属性的其他属性,如属性集或自定义安全特性名称。

  6. 根据所选自定义安全属性的属性,可以更新单个值、从预定义列表中选择一个值或更新多个值。

  7. 完成后,选择“保存”。

基于自定义安全属性筛选应用程序

可在“所有应用程序”页面上筛选分配给应用程序的自定义安全属性列表。

  1. 至少以属性分配读者的身份登录到 Microsoft Entra 管理中心

  2. 浏览到“标识”>“应用程序”>“企业应用程序”。

  3. 选择“添加筛选器”,打开“选取字段”窗格。

    如果看不到“添加筛选器”,请选择横幅以启用企业应用程序搜索预览。

  4. 对于“筛选器”,请选择“自定义安全属性”。

  5. 选择属性集和属性名称。

  6. 对于“运算符”,可选择等于 (==)、不等于 (!=) 或开头内容。

  7. 对于“值”,请输入或选择一个值。

    Screenshot showing a custom security attribute filter for applications.

  8. 选择“应用”以应用筛选器。

从应用程序中删除自定义安全属性分配

  1. 属性分配管理员身份登录到 Microsoft Entra 管理中心

  2. 浏览到“标识”>“应用程序”>“企业应用程序”。

  3. 找到并选择具有要删除的自定义安全属性分配的应用程序。

  4. 在“管理”部分,选择“自定义安全属性(预览版)”。

  5. 在要删除的所有自定义安全属性分配旁边添加复选标记。

  6. 选择“删除分配”。

Azure AD PowerShell

若要为 Microsoft Entra 组织中的应用程序管理自定义安全属性分配,可使用 PowerShell。 以下命令可用于管理分配。

使用 Azure AD PowerShell 将具有多个字符串值的自定义安全属性分配给应用程序(服务主体)

使用 Set-AzureADMSServicePrincipal 命令将包含多个字符串值的自定义安全属性分配给应用程序(服务主体)。

  • 属性集:Engineering
  • 属性:Project
  • 属性数据类型:字符串集合
  • 属性值:("Baker","Cascade")
$attributes = @{
    Engineering = @{
        "@odata.type" = "#Microsoft.DirectoryServices.CustomSecurityAttributeValue"
        "Project@odata.type" = "#Collection(String)"
        Project = @("Baker","Cascade")
    }
}
Set-AzureADMSServicePrincipal -Id 7d194b0c-bf17-40ff-9f7f-4b671de8dc20 -CustomSecurityAttributes $attributes

使用 Azure AD PowerShell 为应用程序(服务主体)更新具有多个字符串值的自定义安全属性

提供希望在应用程序上反映的新属性值集。 在此示例中,我们将为项目属性再添加一个值。

  • 属性集:Engineering
  • 属性:Project
  • 属性数据类型:字符串集合
  • 属性值:("Alpine","Baker")
$attributesUpdate = @{
    Engineering = @{
        "@odata.type" = "#Microsoft.DirectoryServices.CustomSecurityAttributeValue"
        "Project@odata.type" = "#Collection(String)"
        Project = @("Alpine","Baker")
    }
}
Set-AzureADMSServicePrincipal -Id 7d194b0c-bf17-40ff-9f7f-4b671de8dc20 -CustomSecurityAttributes $attributesUpdate 

使用 Azure AD PowerShell 为应用程序(服务主体)获取自定义安全属性分配

使用 Get-AzureADMSServicePrincipal 命令可获取应用程序(服务主体)的自定义安全属性分配。

Get-AzureADMSServicePrincipal -Select CustomSecurityAttributes
Get-AzureADMSServicePrincipal -Id 7d194b0c-bf17-40ff-9f7f-4b671de8dc20  -Select "CustomSecurityAttributes, Id"

Microsoft Graph PowerShell

若要为 Microsoft Entra 组织中的应用程序管理自定义安全属性分配,可使用 Microsoft Graph PowerShell。 以下命令可用于管理分配。

使用 Microsoft Graph PowerShell 将具有多个字符串值的自定义安全属性分配给应用程序(服务主体)

使用 Update-MgServicePrincipal 命令将包含多个字符串值的自定义安全属性分配给应用程序(服务主体)。

给定值

  • 属性集:Engineering
  • 属性:ProjectDate
  • 属性数据类型:字符串
  • 属性值:"2024-11-15"
#Retrieve the servicePrincipal

$ServicePrincipal = (Get-MgServicePrincipal -Filter "displayName eq 'TestApp'").Id

$customSecurityAttributes = @{
    Engineering = @{
        "@odata.type" = "#Microsoft.DirectoryServices.CustomSecurityAttributeValue"
        "ProjectDate" ="2024-11-15"
    }
}
Update-MgServicePrincipal -ServicePrincipalId $ServicePrincipal -CustomSecurityAttributes $customSecurityAttributes

使用 Microsoft Graph PowerShell 为应用程序(服务主体)更新具有多个字符串值的自定义安全属性

提供希望在应用程序上反映的新属性值集。 在此示例中,我们将为项目属性再添加一个值。

给定值

  • 属性集:Engineering
  • 属性:Project
  • 属性数据类型:字符串集合
  • 属性值:["Baker","Cascade"]
$customSecurityAttributes = @{
    Engineering = @{
        "@odata.type" = "#Microsoft.DirectoryServices.CustomSecurityAttributeValue"
        "Project@odata.type" = "#Collection(String)"
        "Project" = @(
            "Baker"
            "Cascade"
        )
    }
}
Update-MgServicePrincipal -ServicePrincipalId $ServicePrincipal -CustomSecurityAttributes $customSecurityAttributes

使用 Microsoft Graph PowerShell 根据自定义安全属性筛选应用程序

此示例筛选了具有等于指定值的自定义安全属性分配的应用程序列表。

$appAttributes = Get-MgServicePrincipal -CountVariable CountVar -Property "id,displayName,customSecurityAttributes" -Filter "customSecurityAttributes/Engineering/Project eq 'Baker'" -ConsistencyLevel eventual
$appAttributes | select Id,DisplayName,CustomSecurityAttributes  | Format-List
$appAttributes.CustomSecurityAttributes.AdditionalProperties | Format-List
Id                       : 7d194b0c-bf17-40ff-9f7f-4b671de8dc20
DisplayName              : TestApp
CustomSecurityAttributes : Microsoft.Graph.PowerShell.Models.MicrosoftGraphCustomSecurityAttributeValue

Key   : Engineering
Value : {[@odata.type, #microsoft.graph.customSecurityAttributeValue], [ProjectDate, 2024-11-15], [Project@odata.type, #Collection(String)], [Project, System.Object[]]}

使用 Microsoft Graph PowerShell 从应用程序中删除自定义安全属性分配

在此示例中,我们删除了支持单个值的自定义安全属性分配。


$params = @{
    "customSecurityAttributes" = @{
        "Engineering" = @{
            "@odata.type" = "#Microsoft.DirectoryServices.CustomSecurityAttributeValue"
            "ProjectDate" = $null
        }
    }
}
Invoke-MgGraphRequest -Method PATCH -Uri "https://graph.microsoft.com/v1.0/servicePrincipals/$ServicePrincipal" -Body $params

在此示例中,我们删除了支持多个值的自定义安全属性分配。

$customSecurityAttributes = @{
    Engineering = @{
        "@odata.type" = "#Microsoft.DirectoryServices.CustomSecurityAttributeValue"
        "Project" = @()
    }
}
Update-MgServicePrincipal -ServicePrincipalId $ServicePrincipal -CustomSecurityAttributes $customSecurityAttributes

Microsoft Graph API

若要为 Microsoft Entra 组织中的应用程序管理自定义安全属性分配,可使用 Microsoft Graph API。 执行以下 API 调用来管理分配。

有关用户的其他类似 Microsoft Graph API 示例,请参阅为用户分配、更新、列出或删除自定义安全属性示例:使用 Microsoft Graph API 分配、更新、列出或删除自定义安全属性

使用 Microsoft Graph API 将包含多个字符串值的自定义安全属性分配给应用程序(服务主体)

使用 Update servicePrincipal API 向应用程序分配具有字符串值的自定义安全属性。

给定值

  • 属性集:Engineering
  • 属性:Project
  • 属性数据类型:字符串
  • 属性值:"Baker"
PATCH https://graph.microsoft.com/v1.0/servicePrincipals/{id}
Content-type: application/json

{
    "customSecurityAttributes":
    {
        "Engineering":
        {
            "@odata.type":"#Microsoft.DirectoryServices.CustomSecurityAttributeValue",
            "Project@odata.type":"#Collection(String)",
            "Project": "Baker"
        }
    }
}

使用 Microsoft Graph API 为应用程序(服务主体)更新具有多个字符串值的自定义安全属性

提供希望在应用程序上反映的新属性值集。 在此示例中,我们将为项目属性再添加一个值。

PATCH https://graph.microsoft.com/v1.0/servicePrincipals/{id}
Content-type: application/json

{
    "customSecurityAttributes":
    {
        "Engineering":
        {
            "@odata.type":"#Microsoft.DirectoryServices.CustomSecurityAttributeValue",
            "Project@odata.type":"#Collection(String)",
            "Project":["Baker","Cascade"]
        }
    }
}

使用 Microsoft Graph API 根据自定义安全属性筛选应用程序

此示例筛选了具有等于指定值的自定义安全属性分配的应用程序列表。 筛选器值区分大小写。 必须在请求或标头中添加 ConsistencyLevel=eventual。 还必须包括 $count=true 以确保正确地路由请求。

GET https://graph.microsoft.com/v1.0/servicePrincipals?$count=true&$select=id,displayName,customSecurityAttributes&$filter=customSecurityAttributes/Engineering/Project eq 'Baker'
ConsistencyLevel: eventual

使用 Microsoft Graph API 从应用程序中删除自定义安全属性分配

在此示例中,我们删除了支持多个值的自定义安全属性分配。

PATCH https://graph.microsoft.com/v1.0/servicePrincipals/{id}
Content-type: application/json

{
    "customSecurityAttributes":
    {
        "Engineering":
        {
            "@odata.type":"#Microsoft.DirectoryServices.CustomSecurityAttributeValue",
            "Project":[]
        }
    }
}

后续步骤