Overview:
Creating a Service Principal in Azure Portal involves registering a new application in your Azure Active Directory (AAD) Azure Active Directory is now Microsoft Entra ID, and configuring the necessary credentials. Follow these steps to set up a Service Principal for your Azure resources.
Step 1: Navigate to Azure Active Directory
- Log in to the Azure Portal.
- Search for Azure Active Directory is now Microsoft Entra ID and click on it.
Step 2: Access App Registrations
- Under “Manage,” click on App registrations.
Step 3: Register a New Application
- Click on New registration to create a new application.
Step 4: Fill in Application Details
- Enter a meaningful name for your application.
- Choose the appropriate account type (e.g., “Accounts in this organizational directory only”).
- Leave the “Redirect URI” blank for now.
- Click Register to create the application.
Step 5: Note Application (Client) ID and Directory (Tenant) ID
- After registration, note the Application (Client) ID and Directory (Tenant) ID from the overview page.
Step 6: Create a New Client Secret
- In the left-hand menu, go to Certificates & secrets.
- Click on New client secret.
- Provide a description, set an expiration, and click Add.
- Note the generated secret value immediately.
Granting Permissions:
- Go to the resource where you want to grant permissions (e.g., Subscription, Resource Group, or a specific Resource).
- Click on Access control (IAM) and grant permissions
Creating an Azure Service Principal and Secrets using az
- Open a terminal window and log in to your Azure account using the following command:
az login
- Create a new service principal using the following command:
az ad sp create-for-rbac --name "MyServicePrincipal" --role "Contributor" --scopes "/subscriptions/<subscription-id>"
- The output of the command will include the service principal ID and secret key. Copy these values to a safe location.
Creating an Azure Service Principal and Secrets using PowerShell
- Open a PowerShell window and log in to your Azure account using the following command:
Connect-AzAccount
- Create a new service principal using the following command:
New-AzADServicePrincipal -Name "MyServicePrincipal" -Role "Contributor" -Scopes "/subscriptions/<subscription-id>"
- The output of the command will include the service principal ID and secret key. Copy these values to a safe location.
Follow these steps to successfully create a Service Principal in the Azure Portal. Use the gathered information in your applications or scripts requiring authentication with Azure services through this Service Principal.