|
2 | 2 | title: Securing service principals in Azure Active Directory
|
3 | 3 | description: Find, assess, and secure service principals.
|
4 | 4 | services: active-directory
|
5 |
| -author: janicericketts |
| 5 | +author: jricketts |
6 | 6 | manager: martinco
|
7 | 7 | ms.service: active-directory
|
8 | 8 | ms.workload: identity
|
9 | 9 | ms.subservice: fundamentals
|
10 | 10 | ms.topic: conceptual
|
11 |
| -ms.date: 11/28/2022 |
| 11 | +ms.date: 02/08/2023 |
12 | 12 | ms.author: jricketts
|
13 | 13 | ms.reviewer: ajburnle
|
14 | 14 | ms.custom: "it-pro, seodec18"
|
15 | 15 | ms.collection: M365-identity-device-management
|
16 | 16 | ---
|
17 | 17 |
|
18 |
| -# Securing service principals |
| 18 | +# Securing service principals in Azure Active Directory |
19 | 19 |
|
20 |
| -An Azure Active Directory (Azure AD) [service principal](../develop/app-objects-and-service-principals.md) is the local representation of an application object in a single tenant or directory. It functions as the identity of the application instance. Service principals define who can access the application, and what resources the application can access. A service principal is created in each tenant where the application is used, and references the globally unique application object. The tenant secures the service principal sign-in and access to resources. |
| 20 | +An Azure Active Directory (Azure AD) service principals are the local representation of an application object in a tenant or directory. It's the identity of the application instance. Service principals define application access, and resources the application accesses. A service principal is created in each tenant where the application is used, and references the globally unique application object. The tenant secures the service principal sign-in and access to resources. |
| 21 | + |
| 22 | +Learn more: [Application and service principal objects in Azure AD](../develop/app-objects-and-service-principals.md) |
21 | 23 |
|
22 | 24 | ### Tenant-service principal relationships
|
23 | 25 |
|
24 | 26 | A single-tenant application has one service principal in its home tenant. A multi-tenant web application or API requires a service principal in each tenant. A service principal is created when a user from that tenant consents to use of the application or API. This consent creates a one-to-many relationship between the multi-tenant application and its associated service principals.
|
25 | 27 |
|
26 |
| -A multi-tenant application is homed in a single tenant and has instances in other tenants. Most software-as-a-service (SaaS) applications accommodate multi-tenancy. Use service principals to ensure the needed security posture for the application and its users in single-tenant and multi-tenant scenarios. |
| 28 | +A multi-tenant application is homed in a tenant and has instances in other tenants. Most software-as-a-service (SaaS) applications accommodate multi-tenancy. Use service principals to ensure the needed security posture for the application, and its users, in single- and multi-tenant scenarios. |
27 | 29 |
|
28 | 30 | ## ApplicationID and ObjectID
|
29 | 31 |
|
30 |
| -An application instance has two properties: the ApplicationID (also known as ClientID) and the ObjectID. |
| 32 | +An application instance has two properties: the ApplicationID (or ClientID) and the ObjectID. |
31 | 33 |
|
32 | 34 | > [!NOTE]
|
33 |
| -> It's possible the terms application and service principal are used interchangeably when referring to an application in the context of authentication-related tasks. However, they are two representations of applications in Azure AD. |
| 35 | +> The terms **application** and **service principal** are used interchangeably, when referring to an application in authentication tasks. However, they are two representations of applications in Azure AD. |
34 | 36 |
|
35 |
| -The ApplicationID represents the global application and is the same for application instances across tenants. The ObjectID is a unique value for an application object. As with users, groups, and other resources, the ObjectID helps to identify an application instance in Azure AD. |
| 37 | +The ApplicationID represents the global application and is the same for application instances, across tenants. The ObjectID is a unique value for an application object. As with users, groups, and other resources, the ObjectID helps to identify an application instance in Azure AD. |
| 38 | + |
| 39 | +To learn more, see [Application and service principal relationship](../develop/app-objects-and-service-principals.md) |
| 40 | + |
| 41 | +### Create an application and its service principal object |
36 | 42 |
|
37 |
| -To learn more, see [Application and service principal relationship](../develop/app-objects-and-service-principals.md). |
| 43 | +You can create an application and its service principal object (ObjectID) in a tenant using: |
38 | 44 |
|
39 |
| -You can create an application and its service principal object (ObjectID) in a tenant using Azure PowerShell, Azure CLI, Microsoft Graph, the Azure portal, and other tools. |
| 45 | +* Azure PowerShell |
| 46 | +* Azure command-line interface (CLI) |
| 47 | +* Microsoft Graph |
| 48 | +* The Azure portal |
| 49 | +* Other tools |
40 | 50 |
|
41 |
| - |
| 51 | + |
42 | 52 |
|
43 | 53 | ## Service principal authentication
|
44 | 54 |
|
45 |
| -When using service principals—client certificates and client secrets, there are two mechanisms for authentication. |
| 55 | +There are two mechanisms for authentication, when using service principals—client certificates and client secrets. |
46 | 56 |
|
47 |
| - |
| 57 | + |
48 | 58 |
|
49 |
| -Certificates are more secure, therefore use them, if possible. Unlike client secrets, client certificates can't be embedded in code, accidentally. When possible, use Azure Key Vault for certificate and secrets management to encrypt the following assets with keys protected by hardware security modules: |
| 59 | +Because certificates are more secure, it's recommended you use them, when possible. Unlike client secrets, client certificates can't be embedded in code, accidentally. When possible, use Azure Key Vault for certificate and secrets management to encrypt assets with keys protected by hardware security modules: |
50 | 60 |
|
51 | 61 | * Authentication keys
|
52 |
| - |
53 | 62 | * Storage account keys
|
54 |
| - |
55 | 63 | * Data encryption keys
|
56 |
| - |
57 | 64 | * .pfx files
|
58 |
| - |
59 | 65 | * Passwords
|
60 | 66 |
|
61 |
| -For more information on Azure Key Vault and how to use it for certificate and secret management, see |
62 |
| -[About Azure Key Vault](../../key-vault/general/overview.md) and [Assign a Key Vault access policy using the Azure portal](../../key-vault/general/assign-access-policy-portal.md). |
| 67 | +For more information on Azure Key Vault and how to use it for certificate and secret management, see: |
| 68 | + |
| 69 | +* [About Azure Key Vault](../../key-vault/general/overview.md) |
| 70 | +* [Assign a Key Vault access policy](../../key-vault/general/assign-access-policy.md) |
63 | 71 |
|
64 | 72 | ### Challenges and mitigations
|
65 | 73 |
|
66 |
| -Use the following table to match challenges and mitigations, when using service principals. |
| 74 | +When using service principals, use the following table to match challenges and mitigations. |
67 | 75 |
|
68 |
| -| Challenges| Mitigations | |
| 76 | +| Challenge| Mitigation| |
69 | 77 | | - | - |
|
70 |
| -| Access reviews for service principals assigned to privileged roles| This functionality is in preview, and not widely available | |
71 |
| -| Reviews service principal access| Manual check of resource access control list using the Azure portal | |
72 |
| -| Over-permissioned service principals| When you create automation service accounts or or service principals, provide permissions required for the task. Evaluate service principals to reduce privileges | |
73 |
| -|Identify modifications to service principal credentials or authentication methods |Use the Sensitive Operations Report workbook to mitigate. See also the Tech Community blog post [Azure AD workbook to help you assess Solorigate risk](https://techcommunity.microsoft.com/t5/azure-active-directory-identity/azure-ad-workbook-to-help-you-assess-solorigate-risk/ba-p/2010718).| |
| 78 | +| Access reviews for service principals assigned to privileged roles| This functionality is in preview | |
| 79 | +| Service principal access reviews| Manual check of resource access control list using the Azure portal | |
| 80 | +| Over-permissioned service principals| When you create automation service accounts, or service principals, grant permissions for the task. Evaluate service principals to reduce privileges. | |
| 81 | +|Identify modifications to service principal credentials or authentication methods | - See, [Sensitive operations report workbook](../reports-monitoring/workbook-sensitive-operations-report.md) </br> - See the Tech Community blog post, [Azure AD workbook to help you assess Solorigate risk](https://techcommunity.microsoft.com/t5/azure-active-directory-identity/azure-ad-workbook-to-help-you-assess-solorigate-risk/ba-p/2010718)| |
74 | 82 |
|
75 | 83 | ## Find accounts using service principals
|
76 | 84 |
|
77 |
| -Run the following commands to find accounts using service principals with Azure CLI or PowerShell. |
78 |
| - |
79 |
| -Azure CLI: |
| 85 | +To find accounts, run the following commands using service principals with Azure CLI or PowerShell. |
80 | 86 |
|
81 |
| -`az ad sp list` |
| 87 | +* Azure CLI - `az ad sp list` |
| 88 | +* PowerShell - `Get-AzureADServicePrincipal -All:$true` |
82 | 89 |
|
83 |
| -PowerShell: |
84 |
| - |
85 |
| -`Get-AzureADServicePrincipal -All:$true` |
86 |
| - |
87 |
| -For more information see [Get-AzureADServicePrincipal](/powershell/module/azuread/get-azureadserviceprincipal). |
| 90 | +For more information, see [Get-AzureADServicePrincipal](/powershell/module/azuread/get-azureadserviceprincipal) |
88 | 91 |
|
89 | 92 | ## Assess service principal security
|
90 | 93 |
|
91 |
| -To assess the security of your service principals, ensure you evaluate privileges and credential storage. |
92 |
| - |
93 |
| -Mitigate potential challenges using the following information. |
| 94 | +To assess the security, evaluate privileges and credential storage. Use the following table to help mitigate challenges: |
94 | 95 |
|
95 |
| -|Challenges | Mitigations| |
| 96 | +|Challenge | Mitigation| |
96 | 97 | | - | - |
|
97 |
| -| Detect the user who consented to a multi-tenant app, and detect illicit consent grants to a multi-tenant app | Run the following PowerShell to find multi-tenant apps.<br>`Get-AzureADServicePrincipal -All:$true ? {$_.Tags -eq WindowsAzureActiveDirectoryIntegratedApp"}`<br>Disable user consent. <br>Allow user consent from verified publishers, for selected permissions (recommended) <br> Configure them in the user context. Use their tokens to trigger the service principal.| |
| 98 | +| Detect the user who consented to a multi-tenant app, and detect illicit consent grants to a multi-tenant app | - Run the following PowerShell to find multi-tenant apps <br>`Get-AzureADServicePrincipal -All:$true ? {$_.Tags -eq WindowsAzureActiveDirectoryIntegratedApp"}`</br> - Disable user consent </br> - Allow user consent from verified publishers, for selected permissions (recommended) </br> - Configure them in the user context </br> - Use their tokens to trigger the service principal| |
98 | 99 | |Use of a hard-coded shared secret in a script using a service principal|Use a certificate|
|
99 |
| -|Tracking who uses the certificate or the secret| Monitor the service principal sign-ins using the Azure AD sign-in logs| |
100 |
| -Can't manage service principal sign-in with Conditional Access| Monitor the sign-ins using the Azure AD sign-in logs |
101 |
| -| Contributor is the default Azure role-based access control (RBAC) role|Evaluate needs and apply the role with the least possible permissions| |
| 100 | +|Tracking who uses the certificate or the secret| Monitor the service principal sign-ins using the Azure AD sign-in logs| |
| 101 | +|Can't manage service principal sign-in with Conditional Access| Monitor the sign-ins using the Azure AD sign-in logs |
| 102 | +| Contributor is the default Azure role-based access control (Azure RBAC) role|Evaluate needs and apply the least possible permissions| |
102 | 103 |
|
103 |
| -## Move from a user account to a service principal |
| 104 | +Learn more: [What is Conditional Access?](../conditional-access/overview.md) |
104 | 105 |
|
105 |
| -If you're using an Azure user account as a service principal, evaluate if you can move to a [Managed Identity](../../app-service/overview-managed-identity.md?tabs=dotnet) or a service principal. If you can't use a managed identity, provision a service principal with enough permissions and scope to run the required tasks. You can create a service principal by [registering an application](../develop/howto-create-service-principal-portal.md), or with [PowerShell](../develop/howto-authenticate-service-principal-powershell.md). |
| 106 | +## Move from a user account to a service principal |
106 | 107 |
|
107 |
| -When using Microsoft Graph, check the API documentation. See, [Create an Azure service principal](/powershell/azure/create-azure-service-principal-azureps). Ensure the permission type for application is supported. |
| 108 | +If you're using an Azure user account as a service principal, evaluate if you can move to a managed identity or a service principal. If you can't use a managed identity, grant a service principal enough permissions and scope to run the required tasks. You can create a service principal by registering an application, or with PowerShell. |
108 | 109 |
|
109 |
| -## Next steps |
| 110 | +When using Microsoft Graph, check the API documentation. Ensure the permission type for application is supported. </br>See, [Create servicePrincipal](/graph/api/serviceprincipal-post-serviceprincipals?view=graph-rest-1.0&tabs=http&preserve-view=true) |
110 | 111 |
|
111 |
| -Learn more about service principals: |
| 112 | +Learn more: |
112 | 113 |
|
113 |
| -[Create a service principal](../develop/howto-create-service-principal-portal.md) |
| 114 | +* [How to use managed identities for App Service and Azure Functions](../../app-service/overview-managed-identity.md?tabs=dotnet) |
| 115 | +* [Create an Azure AD application and service principal that can access resources](../develop/howto-create-service-principal-portal.md) |
| 116 | +* [Use Azure PowerShell to create a service principal with a certificate](../develop/howto-authenticate-service-principal-powershell.md) |
114 | 117 |
|
115 |
| -[Monitor service principal sign-ins](../reports-monitoring/concept-sign-ins.md) |
116 |
| - |
117 |
| -Learn more about securing service accounts: |
| 118 | +## Next steps |
118 | 119 |
|
119 |
| -[Introduction to Azure service accounts](service-accounts-introduction-azure.md) |
| 120 | +Learn more about service principals: |
120 | 121 |
|
121 |
| -[Securing managed identities](service-accounts-managed-identities.md) |
| 122 | +* [Create an Azure AD application and service principal that can access resources](../develop/howto-create-service-principal-portal.md) |
| 123 | +* [Sign-in logs in Azure AD](../reports-monitoring/concept-sign-ins.md) |
122 | 124 |
|
123 |
| -[Governing Azure service accounts](service-accounts-governing-azure.md) |
| 125 | +Secure service accounts: |
124 | 126 |
|
125 |
| -[Introduction to on-premises service accounts](service-accounts-on-premises.md) |
| 127 | +* [Securing cloud-based service accounts](service-accounts-introduction-azure.md) |
| 128 | +* [Securing managed identities in Azure AD](service-accounts-managed-identities.md) |
| 129 | +* [Governing Azure AD service accounts](service-accounts-governing-azure.md) |
| 130 | +* [Securing on-premises service accounts](service-accounts-on-premises.md) |
126 | 131 |
|
127 | 132 | Conditional Access:
|
128 | 133 |
|
129 |
| -Use Conditional Access to block service principals from untrusted locations. See, [Create a location-based Conditional Access policy](../conditional-access/workload-identity.md#create-a-location-based-conditional-access-policy). |
| 134 | +Use Conditional Access to block service principals from untrusted locations. |
| 135 | + |
| 136 | +See, [Conditional Access for workload identities](../conditional-access/workload-identity.md#create-a-location-based-conditional-access-policy) |
0 commit comments