Azure - Service Principals v/s Managed Identities
Akhil Pathirippilly mana
Data Engineering / Data Warehousing / Azure / AWS /CDP/Databricks
Any data engineer who works on azure would have come across the terminology "Service Principal" aka "Active Directory App" and at least some of data engineer would have come across the terminology "Managed Identity".
?
Managed identities and service principals are mechanisms to provide programmatic access to Azure resources. Both uses OAuth 2.0 standard for authorization
?
OAuth 2.0 is an open standard for authorization that provides a secure and flexible way for client applications to access protected resources, such as those in Azure, without having to reveal their credentials. Instead, the client application requests an access token from an authorization server (in this case, Azure AD), and uses the token to access the protected resources.
?
This includes a authentication and authorization phase. Whenever we write a program which needs to access an azure resource , you need to talk to the "Head of Department" - The "Active Directory" aka "AD" . If Active Directory authenticate your application , it will provide a time bounded token aka 'credential' for accessing a scope. This scope can be a subscription or a resource group or an individual resource. And within the time limit , the application can access the scope and perform operations that are permissible based on the RBAC (Role Based Access Control) policy.
?
Below are some key differences between a service principal and a managed identity :
Managed identities:
Service principals:
领英推荐
Time bounded credentials:
The default lifetime for access tokens from Azure AD for a service principal or managed identity is 1 hour (60 minutes). This lifetime is defined by the token's "expiry" or "not-before" time, which is set when the token is issued.
It's worth noting that you can also configure the token lifetime using Azure AD's token configuration settings. You can configure the lifetime for access tokens, ID tokens, and refresh tokens, as well as specify different lifetimes for different applications or users. Additionally, you can use token refresh to obtain new access tokens without requiring the user to sign in again.
For a service principal , while getting the token from AD , you can optionally configure the life span of the token as well
For example , let's say I need to write a function in python for accessing secrets from a key vault. I can access key vault in two ways .
?
For getting the secret from key vault we can utilize azure-keyvault package.
The sample function with both the above method implemented can be seen in below screen shot.
Packages:
Functions:
Infrastructure Solution Architect with expertise in Cybersecurity, Cloud and Virtualization.
1 年Very Nice Article
Databricks & Microsoft Azure Certified Professional | Data Engineering & Analytics | Big Data | Spark | Datawarehouse
1 年Very informative