DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Low-Code Development: Leverage low and no code to streamline your workflow so that you can focus on higher priorities.

DZone Security Research: Tell us your top security strategies in 2024, influence our research, and enter for a chance to win $!

Launch your software development career: Dive head first into the SDLC and learn how to build high-quality software and teams.

Open Source Migration Practices and Patterns: Explore key traits of migrating open-source software and its impact on software development.

Related

  • From Novice to Expert: Building Robust Security With Kubernetes RBAC
  • Best Practices To Secure Stateless REST Applications
  • How To Use AzureSignTool to Sign Executables With Azure DevOps
  • Empowering Secure Access: Unleashing the Potential of Microsoft Entra ID Application Proxy

Trending

  • The Impact of AI and Platform Engineering on Cloud Native's Evolution: Automate Your Cloud Journey to Light Speed
  • A Java developer's guide to Quarkus
  • When Not To Use Apache Kafka (Lightboard Video)
  • Strategies for Building Self-Healing Software Systems
  1. DZone
  2. Software Design and Architecture
  3. Security
  4. Effortless Credential Management in Azure: The Power of Managed Identities

Effortless Credential Management in Azure: The Power of Managed Identities

Managed Identities simplify access to Azure resources, eliminating the need for connection strings and manual rotation of secrets.

By 
Siri Varma Vegiraju user avatar
Siri Varma Vegiraju
·
Jun. 13, 24 · Tutorial
Like (1)
Save
Tweet
Share
3.5K Views

Join the DZone community and get the full member experience.

Join For Free

Azure Entra Id, formerly Azure Active Directory is a comprehensive Identity and Access Management offering from Microsoft. While it encompasses many functionalities, the article will focus on Managed Identities.

Why Managed Identities?

Initially, Azure resources were accessed using connecting strings--keys tied to specific resources. For instance, for a storage account named "Foo", its connection string might be "Bar". This string would be stored in a Vault, and applications would retrieve it to access the resource. 

Some of the challenges with this approach were:

  • Key rotation: When a key rotation is performed, the new key must be updated in the Vault. Service using it had to be notified about the rotation.
  • Security risks: The Storage Key acts like a Master Key, allowing any operation, including deletion of the resource, to pose a risk in a production environment.

Then came Service Principal and Role Based Access Control (RBAC). With this, the principal is assigned to an Azure Resource, such as Storage, along with permissions like Blob Reader and Blob Writer, restricting operations the principal can perform.

  • While this method eased the management of multiple connection strings and Security Risks, the need for manual rotation of Service Principal client secrets/certificates failed to address the Key Rotation issue.

This is where Managed Identity emerges as the pivotal solution to address all these challenges. Here's how:

  • Automated key rotation: Azure takes charge of the Key Rotation process seamlessly in the background, eliminating the need for manual intervention. 
  • Credential concealment: Managed Identity shields actual credentials from end-users, significantly reducing the risk of inadvertent exposure. This means developers can confidently work without the fear of accidentally committing access keys to version control systems or unintentionally exposing them to the public domain

Types of Identities

Azure Entra has two offerings, System Managed and User Managed Identity.

User Managed Identity

  • This is a standalone instance, similar to an Azure VM or an App Service. It creates a Service Principal managed by Azure.
  • Like any other principal, the created principal can be attached to any resource and granted corresponding permissions. Azure resources requiring access to the assigned resource can utilize the client ID of the user-managed identity to gain access.

Azure AD tenant

Use Case

  • When resources and permissions need to be managed individually, for example, in the image above, the lifecycle of the VM should not impact the permissions to either of the databases.

How To Create a User Managed Identity

  1. Log in to Azure Portal.
  2. Go to Market Place -> Search for "User Assigned Managed Identity" -> "Create".
  3. create a user managed identitySelect Subscription, Resource Group, and Name. Click Review + Create.
  4. Select Subscription, Resource Group, and Name. Click Review + Create.Consider assigning this identity to a VM. Go to the VM -> Identity -> User assigned.
  5. Consider assigning this identity to a VM. Go to the VM -> Identity -> User assigned.Click Add and add the user-managed identity created previously.
  6. Click Add and add the user-managed identity created previously.Now, the VM has access permissions assigned to this identity.
  7. To assign permissions to the Managed Identity, go to a resource for example storage, select the appropriate role, and choose the managed identity in the members section.select the appropriate role, and choose the managed identity in the members section.

Using User Managed Identity in Your Code

C#
 
TokenCredential tokenCredential = new DefaultAzureCredential(new DefaultAzureCredentialOptions { ManagedIdentityClientId = <clientId of User MSI> });

// Using the identity in Queue
QueueClient queue = new QueueClient(new Uri($"https://{storageName}.queue.core.windows.net/processors"), tokenCredential);
// Using the identity in Blob
BlobContainerClient blobContainer = new BlobContainerClient(new Uri($"https://{storageName}.blob.core.windows.net/processors"), tokenCredential));


System Managed Identity

  • The identity is linked to Azure Resource. For example, creating a VM or an App Service creates the resource and the Principal.
  • Like any other principal, this can be associated with any azure instance.
  • However, deleting the resource also removes the corresponding principal.

system managed identity

Use Case

  • When both permissions and resources need to be deleted together.

How To Create a System-Managed Identity

  1. While creating a resource, enabling the System Managed Identity option creates the identity automatically. For example, when creating a VM choose "Enable system-assigned managed identity"

create a virtual machine

Using System Managed Identity in Your Code

C#
 
TokenCredential tokenCredential = new DefaultAzureCredential();

// Using the identity in Queue
QueueClient queue = new QueueClient(new Uri($"https://{storageName}.queue.core.windows.net/processors"), tokenCredential);
// Using the identity in Blob
BlobContainerClient blobContainer = new BlobContainerClient(new Uri($"https://{storageName}.blob.core.windows.net/processors"), tokenCredential));

azure Role-based access control security

Opinions expressed by DZone contributors are their own.

Related

  • From Novice to Expert: Building Robust Security With Kubernetes RBAC
  • Best Practices To Secure Stateless REST Applications
  • How To Use AzureSignTool to Sign Executables With Azure DevOps
  • Empowering Secure Access: Unleashing the Potential of Microsoft Entra ID Application Proxy

Partner Resources


Comments

ABOUT US

  • About DZone
  • Send feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: