Create an Azure AD app and service principal in the portal - Microsoft Entra (2024)

  • Article
  • 8 minutes to read

This article shows you how to create a new Azure Active Directory (Azure AD) application and service principal that can be used with the role-based access control. When you have applications, hosted services, or automated tools that need to access or modify resources, you can create an identity for the app. This identity is known as a service principal. Access to resources is restricted by the roles assigned to the service principal, giving you control over which resources can be accessed and at which level. For security reasons, it's always recommended to use service principals with automated tools rather than allowing them to log in with a user identity.

This article shows you how to use the portal to create the service principal in the Azure portal. It focuses on a single-tenant application where the application is intended to run within only one organization. You typically use single-tenant applications for line-of-business applications that run within your organization. You can also use Azure PowerShell or the Azure CLI to create a service principal.

Important

Instead of creating a service principal, consider using managed identities for Azure resources for your application identity. If your code runs on a service that supports managed identities and accesses resources that support Azure AD authentication, managed identities are a better option for you. To learn more about managed identities for Azure resources, including which services currently support it, see What is managed identities for Azure resources?.

App registration, app objects, and service principals

There is no way to directly create a service principal using the Azure portal. When you register an application through the Azure portal, an application object and service principal are automatically created in your home directory or tenant. For more information on the relationship between app registration, application objects, and service principals, read Application and service principal objects in Azure Active Directory.

Permissions required for registering an app

You must have sufficient permissions to register an application with your Azure AD tenant, and assign to the application a role in your Azure subscription.

Check Azure AD permissions

  1. Select Azure Active Directory.

  2. Find your role under Overview->My feed. If you have the User role, you must make sure that non-administrators can register applications.

    Create an Azure AD app and service principal in the portal - Microsoft Entra (1)

  3. In the left pane, select Users and then User settings.

  4. Check the App registrations setting. This value can only be set by an administrator. If set to Yes, any user in the Azure AD tenant can register an app.

If the app registrations setting is set to No, only users with an administrator role may register these types of applications. See Azure AD built-in roles to learn about available administrator roles and the specific permissions in Azure AD that are given to each role. If your account is assigned the User role, but the app registration setting is limited to admin users, ask your administrator to either assign you one of the administrator roles that can create and manage all aspects of app registrations, or to enable users to register apps.

Check Azure subscription permissions

In your Azure subscription, your account must have Microsoft.Authorization/*/Write access to assign a role to an AD app. This action is granted through the Owner role or User Access Administrator role. If your account is assigned the Contributor role, you don't have adequate permission. You will receive an error when attempting to assign the service principal a role.

To check your subscription permissions:

  1. Search for and select Subscriptions, or select Subscriptions on the Home page.

    Create an Azure AD app and service principal in the portal - Microsoft Entra (2)

  2. Select the subscription you want to create the service principal in.

    Create an Azure AD app and service principal in the portal - Microsoft Entra (3)

    If you don't see the subscription you're looking for, select global subscriptions filter. Make sure the subscription you want is selected for the portal.

  3. Select My permissions. Then, select Click here to view complete access details for this subscription.

    Create an Azure AD app and service principal in the portal - Microsoft Entra (4)

  4. Select Role assignments to view your assigned roles, and determine if you have adequate permissions to assign a role to an AD app. If not, ask your subscription administrator to add you to User Access Administrator role. In the following image, the user is assigned the Owner role, which means that user has adequate permissions.

    Create an Azure AD app and service principal in the portal - Microsoft Entra (5)

Register an application with Azure AD and create a service principal

Let's jump straight into creating the identity. If you run into a problem, check the required permissions to make sure your account can create the identity.

  1. Sign in to your Azure Account through the Azure portal.

  2. Select Azure Active Directory.

  3. Select App registrations.

  4. Select New registration.

  5. Name the application, for example "example-app". Select a supported account type, which determines who can use the application. Under Redirect URI, select Web for the type of application you want to create. Enter the URI where the access token is sent to. You can't create credentials for a Native application. You can't use that type for an automated application. After setting the values, select Register.

    Create an Azure AD app and service principal in the portal - Microsoft Entra (6)

You've created your Azure AD application and service principal.

Note

You can register multiple applications with the same name in Azure AD, but the applications must have different Application (client) IDs.

Assign a role to the application

To access resources in your subscription, you must assign a role to the application. Decide which role offers the right permissions for the application. To learn about the available roles, see Azure built-in roles.

You can set the scope at the level of the subscription, resource group, or resource. Permissions are inherited to lower levels of scope. For example, adding an application to the Reader role for a resource group means it can read the resource group and any resources it contains.

  1. In the Azure portal, select the level of scope you wish to assign the application to. For example, to assign a role at the subscription scope, search for and select Subscriptions, or select Subscriptions on the Home page.

    Create an Azure AD app and service principal in the portal - Microsoft Entra (7)

  2. Select the particular subscription to assign the application to.

    Create an Azure AD app and service principal in the portal - Microsoft Entra (8)

    If you don't see the subscription you're looking for, select global subscriptions filter. Make sure the subscription you want is selected for the portal.

  3. Select Access control (IAM).

  4. Select Add > Add role assignment to open the Add role assignment page.

  5. In the Role tab, select the role you wish to assign to the application in the list. For example, to allow the application to execute actions like reboot, start and stop instances, select the Contributor role. Read more about the available roles.

    Select the Next button to move to the Members tab. Select Assign access to-> User, group, or service principal and then select Select members. By default, Azure AD applications aren't displayed in the available options. To find your application, search by name (for example, "example-app") and select it from the returned list. Click the Select button. Then click the Review + assign button.

    Create an Azure AD app and service principal in the portal - Microsoft Entra (9)

Your service principal is set up. You can start using it to run your scripts or apps. To manage your service principal (permissions, user consented permissions, see which users have consented, review permissions, see sign in information, and more), go to Enterprise applications.

The next section shows how to get values that are needed when signing in programmatically.

Get tenant and app ID values for signing in

When programmatically signing in, pass the tenant ID with your authentication request and the application ID. You also need a certificate or an authentication key (described in the following section). To get those values, use the following steps:

  1. Select Azure Active Directory.

  2. From App registrations in Azure AD, select your application.

  3. Copy the Directory (tenant) ID and store it in your application code.

    Create an Azure AD app and service principal in the portal - Microsoft Entra (10)

    The directory (tenant) ID can also be found in the default directory overview page.

  4. Copy the Application ID and store it in your application code.

    Create an Azure AD app and service principal in the portal - Microsoft Entra (11)

Authentication: Two options

There are two types of authentication available for service principals: password-based authentication (application secret) and certificate-based authentication. We recommend using a certificate, but you can also create an application secret.

Option 1: Upload a certificate

You can use an existing certificate if you have one. Optionally, you can create a self-signed certificate for testing purposes only. To create a self-signed certificate, open PowerShell and run New-SelfSignedCertificate with the following parameters to create the cert in the user certificate store on your computer:

$cert=New-SelfSignedCertificate -Subject "CN=DaemonConsoleCert" -CertStoreLocation "Cert:\CurrentUser\My" -KeyExportPolicy Exportable -KeySpec Signature

Export this certificate to a file using the Manage User Certificate MMC snap-in accessible from the Windows Control Panel.

  1. Select Run from the Start menu, and then enter certmgr.msc.

    The Certificate Manager tool for the current user appears.

  2. To view your certificates, under Certificates - Current User in the left pane, expand the Personal directory.

  3. Right-click on the cert you created, select All tasks->Export.

  4. Follow the Certificate Export wizard. Do not export the private key, and export to a .CER file.

To upload the certificate:

  1. Select Azure Active Directory.

  2. From App registrations in Azure AD, select your application.

  3. Select Certificates & secrets.

  4. Select Certificates > Upload certificate and select the certificate (an existing certificate or the self-signed certificate you exported).

    Create an Azure AD app and service principal in the portal - Microsoft Entra (12)

  5. Select Add.

After registering the certificate with your application in the application registration portal, enable the client application code to use the certificate.

Option 2: Create a new application secret

If you choose not to use a certificate, you can create a new application secret.

  1. Select Azure Active Directory.

  2. From App registrations in Azure AD, select your application.

  3. Select Certificates & secrets.

  4. Select Client secrets -> New client secret.

  5. Provide a description of the secret, and a duration. When done, select Add.

    After saving the client secret, the value of the client secret is displayed. Copy this value because you won't be able to retrieve the key later. You will provide the key value with the application ID to sign in as the application. Store the key value where your application can retrieve it.

    Create an Azure AD app and service principal in the portal - Microsoft Entra (13)

Configure access policies on resources

Keep in mind, you might need to configure additional permissions on resources that your application needs to access. For example, you must also update a key vault's access policies to give your application access to keys, secrets, or certificates.

  1. In the Azure portal, navigate to your key vault and select Access policies.
  2. Select Add access policy, then select the key, secret, and certificate permissions you want to grant your application. Select the service principal you created previously.
  3. Select Add to add the access policy, then Save to commit your changes.Create an Azure AD app and service principal in the portal - Microsoft Entra (14)

Next steps

  • Learn how to use Azure PowerShell or Azure CLI to create a service principal.
  • To learn about specifying security policies, see Azure role-based access control (Azure RBAC).
  • For a list of available actions that can be granted or denied to users, see Azure Resource Manager Resource Provider operations.
  • For information about working with app registrations by using Microsoft Graph, see the Applications API reference.
Create an Azure AD app and service principal in the portal - Microsoft Entra (2024)

FAQs

How do I create an Azure service principal in Azure portal? ›

There is no way to directly create a service principal using the Azure portal. When you register an application through the Azure portal, an application object and service principal are automatically created in your home directory or tenant.

What is Azure AD application and service principal? ›

An Azure Active Directory (Azure AD) service principal 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.

Where is the service principal in Azure portal? ›

View the service principal

Select Azure Active Directory and then select Enterprise applications. Under Application Type, choose All Applications and then select Apply. In the search filter box, type the name of the Azure resource that has managed identities enabled or choose it from the list.

Is service principal same as App registration? ›

The Enterprise Application (Service Principal) object is the instance of an app registration (application). The “service principal” naming is an identity within a directory that can only obtain rights from within that same directory.

How do I create a SPN? ›

SPNs are registered for built-in accounts automatically. However, when you run a service under a domain user account, you must manually register the SPN for the account you want to use. To create an SPN, you can use the SetSPN command line utility.

What is the key difference between an application and a service principal? ›

One notable difference is that an App Registration can reside in any directory, but an Enterprise application (Service Principal) must be present in the same directory for every tenant where the application is running. (See Configure an OpenID/OAuth application from the Azure AD app gallery.)

How do I Connect to Azure app Service on premise database? ›

You log into your Azure subscription in the Hybrid Connection manager and select the logical connection in your app service. The Hybrid Connection Manager will initiate a secure tunnel out (TCP 80/443) to your app service in Azure.

Is service principal same as App registration Azure? ›

When you register an application using the Azure portal, a service principal is created automatically. You can also create service principal objects in a tenant using Azure PowerShell, Azure CLI, Microsoft Graph, and other tools. Managed identity - This type of service principal is used to represent a managed identity.

How does Azure AD app registration work? ›

In the Azure portal, select Azure Active Directory in the left pane and select App registrations and click on New registration. In the Register an application page, enter your application's registration information: In the Name section, enter a meaningful application name that will be displayed to the users.

What is the minimum number of app service plans that should be created in Azure? ›

Recommendation. Consider using an App Service Plan with at least two (2) instances.

How do I create an Azure app registration in PowerShell? ›

The AzureAD Powershell module is used to create a new Azure App registration. The New-AzureADApplication function creates a new Azure App registration with a secret on the defined tenant from the authentication flow. This Azure App registration is created for an Application client, ie no user.

What is the difference between app service and app service plan in Azure? ›

An App Service Environment is a single-tenant deployment of Azure App Service that runs on your virtual network. Applications are hosted in App Service plans, which are created in an App Service Environment. An App Service plan is essentially a provisioning profile for an application host.

Which PowerShell cmdlet creates an Azure service principal? ›

Create a service principal. Create a service principal with the New-AzADServicePrincipal cmdlet.

Who can create a service principal? ›

Admins create a service principal in each tenant -- or dedicated Azure AD instance -- in which an application is used. A single-tenant application requires one service principal.

How do I register a service principal name SPN for the user account? ›

To register the SPN, the Database Engine must be running under a built-in account, such as Local System (not recommended), or NETWORK SERVICE, or an account that has permission to register an SPN. You can register an SPN using a domain administrator account, but this is not recommended in a production environment.

Which role is required to create service principal in Azure? ›

Kubernetes Cluster requires one of the following: Owner, Contributor, Azure Kubernetes Service Cluster Admin Role. Cosmos DB requires one of the following: Owner, Contributor, DocumentDB Account Contributor.

What is service principal name example? ›

A Service Principal Name is a concept from Kerberos . It's an identifier for a particular service offered by a particular host within an authentication domain. The common form for SPNs is service class / fqdn @ REALM (e.g. IMAP/mail.example.com@EXAMPLE.COM ).

What are service principal names? ›

A service principal name (SPN) is a unique identifier of a service instance. SPNs are used by Kerberos authentication to associate a service instance with a service logon account. This allows a client application to request that the service authenticate an account even if the client does not have the account name.

What is the difference between app registration and enterprise application in Azure? ›

In some cases, people even use both terms interchangeably. But, App registration is simply the actual application object where you configure application settings. Whereas Enterprise Application is a representation of the application within a directory.

Is service principal same as service account? ›

What is a service principal? Azure has a notion of a Service Principal which, in simple terms, is a service account. On Windows and Linux, this is equivalent to a service account. These accounts are frequently used to run a specific scheduled task, web application pool or even SQL Server service.

Top Articles
Latest Posts
Article information

Author: Jeremiah Abshire

Last Updated:

Views: 5602

Rating: 4.3 / 5 (54 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Jeremiah Abshire

Birthday: 1993-09-14

Address: Apt. 425 92748 Jannie Centers, Port Nikitaville, VT 82110

Phone: +8096210939894

Job: Lead Healthcare Manager

Hobby: Watching movies, Watching movies, Knapping, LARPing, Coffee roasting, Lacemaking, Gaming

Introduction: My name is Jeremiah Abshire, I am a outstanding, kind, clever, hilarious, curious, hilarious, outstanding person who loves writing and wants to share my knowledge and understanding with you.