【Azure 环境】Microsoft Graph API实现对Entra ID中应用生成密码的时间天数

问题描述

如何使用 Azure Policy 限制用户创建 AAD 应用程序(App Registration)中的 Client Secret 的有效期,例如只允许创建最长 90 天的 Secret?

image

 

问题解答

Azure Entra ID(原 Azure AD)支持通过 App Management Policy 来限制应用程序凭据(Credential)的创建行为,包括密码(Client Secret)和密钥(Key Credential)的添加及其生命周期。
要实现“只允许用户创建最长90天的 Client Secret”的目标,可以通过 Microsoft Graph API 设置 defaultAppManagementPolicy,具体步骤如下:

1. 设置策略内容

使用 Microsoft Graph API 的 PATCH 方法更新默认策略:

PATCH https://microsoftgraph.chinacloudapi.cn/v1.0/policies/defaultAppManagementPolicy

Content-Type: application/json { "isEnabled": true, "applicationRestrictions": { "passwordCredentials": [ { "restrictionType": "passwordLifetime", "state": "enabled", "maxLifetime": "P90D", "restrictForAppsCreatedAfterDateTime": "2014-10-19T10:37:00Z" } ] } }
  • restrictionType: passwordLifetime 表示限制密码凭据的生命周期。
  • maxLifetime: P90D 表示最大有效期为 90 天。
  • restrictForAppsCreatedAfterDateTime 可设置策略生效的应用创建时间门槛。

 

2. 验证策略效果

部署策略后,若用户尝试创建超过90天有效期的 Secret,将会被系统阻止。

  

3. 限制其他类型凭据(可选)

除了 passwordLifetime,还可以设置以下限制:

限制类型描述
passwordAddition 控制是否允许添加新的密码凭据
symmetricKeyAddition 控制是否允许添加对称密钥凭据
symmetricKeyLifetime 设置对称密钥的最大有效期
customPasswordAddition 禁止使用 PowerShell 或 API 添加自定义密码凭据

 

 

参考资料

posted @ 2025-09-02 21:17  路边两盏灯  阅读(17)  评论(0)    收藏  举报