Azure 服务主体 - 故意强制过期?

Azure Service Principal - force expiration on purpose?

Azure Service Principals默认有到期日,需要轮换。

但是有没有办法使服务主体失效或强制到期?

服务主体进行身份验证时使用的凭据可以存储在服务主体本身或支持应用程序对象(即“应用程序注册”)上。

目前不支持更改现有凭据的到期日期。如果您希望禁用凭据,则应将其删除。 (如果你想 re-enable 它,你可以简单地将它作为授权凭据添加回去。)

从应用程序中删除凭据(应用程序注册)

使用 Azure 门户

  1. 导航到 Azure Active Directory > 应用注册 >(选择应用)> 证书和机密

  2. 在任何证书或客户端密码旁边,选择“删除”图标 (️)

使用 Azure AD PowerShell

remove a key credential(证书):

Remove-AzureADApplicationKeyCredential -ObjectId "{id}" -KeyId "{key-id}"

remove a password credential(客户端密码):

Remove-AzureADApplicationPasswordCredentia -ObjectId "{id}" -KeyId "{key-id}"

使用 Microsoft Graph

remove a key credential(证书):

POST https://graph.microsoft.com/v1.0/applications/{id}/removePassword
Content-type: application/json

{
    "keyId": "{key-id}"
}

remove a password credential(客户端密码):

POST https://graph.microsoft.com/v1.0/applications/{id}/removePassword
Content-type: application/json

{
    "keyId": "{key-id}"
}

从服务主体中删除凭据

使用 Azure 门户

目前无法使用 Azure 门户管理直接存储在服务主体上的凭据。

使用 Azure AD PowerShell

remove a key credential(证书):

Remove-AzureADServicePrincipalKeyCredential -ObjectId "{id}" -KeyId "{key-id}"

remove a password credential(客户端密码):

Remove-AzureADMSApplicationPassword -ObjectId "{id}" -KeyId "{key-id}"

使用 Microsoft Graph

remove a key credential(证书):

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

{
    "keyId": "{key-id}"
}

remove a password credential(客户端密码):

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

{
    "keyId": "{key-id}"
}