Edit

Passwordless connections for Azure services

Passwordless connections are a language-agnostic approach that works across many Azure services. This article describes the security challenges with passwords and introduces passwordless connections for Azure services.

Security challenges with passwords and secrets

Use caution when handling passwords and secret keys. Never place them in an unsecure location. Many apps connect to backend database, cache, messaging, and eventing services by using usernames, passwords, and access keys. If exposed, bad actors can use these credentials to gain unauthorized access to sensitive information such as a sales catalog that you built for an upcoming campaign, or customer data that must be private.

Embedding passwords in an application itself presents a huge security risk for many reasons, including discovery through a code repository. Many developers externalize such passwords by using environment variables so that applications can load them from different environments. However, this approach only shifts the risk from the code itself to an execution environment. Anyone who gains access to the environment can steal passwords, which in turn, increases your data exfiltration risk.

The following code example demonstrates how to connect to Azure Storage by using a storage account key. Many developers gravitate towards this solution because it feels familiar to options they've worked with in the past, even though it isn't an ideal solution. If your application currently uses access keys, consider migrating to passwordless connections.

// Connection using secret access keys
BlobServiceClient blobServiceClient = new(
    new Uri("https://<storage-account-name>.blob.core.windows.net"),
    new StorageSharedKeyCredential("<storage-account-name>", "<your-access-key>"));

Developers must be diligent to never expose these types of keys or secrets in an unsecure location. Many companies have strict security requirements to connect to Azure services without exposing passwords to developers, operators, or anyone else. They often use a vault to store and load passwords into applications, and further reduce the risk by adding password-rotation requirements and procedures. This approach, in turn, increases the operational complexity and, at times, leads to application connection outages.

Passwordless connections and Zero Trust

You can now use passwordless connections in your apps to connect to Azure-based services without any need to rotate passwords. In some cases, all you need is configuration—no new code is required. Zero Trust uses the principle of "never trust, always verify, and credential-free". This principle means securing all communications by trusting machines or users only after verifying identity and prior to granting them access to backend services.

The recommended authentication option for secure, passwordless connections is to use managed identities and Azure role-based access control (RBAC) in combination. By using this approach, you don't have to manually track and manage many different secrets for managed identities because Azure securely handles these tasks internally.

You can configure passwordless connections in two ways: set up the managed identity and its access explicitly, or let Service Connector do it for you. Both approaches result in a managed identity with Azure RBAC access to the target service.

Configure managed identity explicitly

Explicit setup works with every Azure hosting service that supports managed identities, and gives you full visibility into, and control over, each step:

  1. Enable a system-assigned or user-assigned managed identity on your app hosting service, such as Azure App Service, Azure Container Apps, Azure Functions, or Azure Kubernetes Service (AKS).
  2. Grant that identity only the access it needs on the target service. For most services, assign an Azure RBAC role, such as Storage Blob Data Contributor. For databases like Azure Database for PostgreSQL, configure a Microsoft Entra administrator and create a database role for the managed identity.
  3. Provide the app with the non-secret connection information it needs, such as the service endpoint, database name, and identity name, typically through app settings or environment variables.

You can script these steps with the Azure CLI or define them in infrastructure as code by using Bicep or Terraform, so that they're repeatable across environments. For an end-to-end example, see Tutorial: Access data with managed identity in Java on Azure Container Apps.

Use explicit configuration when:

  • Your app runs on a hosting service that Service Connector doesn't support, such as Azure Container Apps.
  • You define your infrastructure in Bicep, Terraform, or another infrastructure as code tool and want every identity and role assignment in source control.
  • You need to review, audit, or customize each role assignment or database permission.

Use Service Connector

Service Connector automates the same steps with a single Azure CLI command or a guided Azure portal experience. It enables the managed identity on the compute service, configures access on the target service, sets the connection information as app settings or environment variables, and lets you validate the connection's health.

Service Connector supports the following compute services:

For supported target services, such as Azure Database for PostgreSQL, Azure Storage, and Azure Service Bus, see What services are supported by Service Connector?.

Use Service Connector when:

  • Your app runs on one of the supported compute services, and the target service is also supported.
  • You want to set up a connection quickly, for example during development or prototyping, without writing role assignments or database permission scripts.
  • You want built-in connection validation and suggested fixes for broken connections.

Connection information at runtime

If you inspect the running environment of an application configured for passwordless connections, you can see the full connection string. The connection string carries, for example, a database server address, a database name, and an instruction to delegate authentication to an Azure authentication plugin, but it doesn't contain any passwords or secrets.

The following video illustrates passwordless connections from apps to Azure services, using Java applications as an example. The concepts apply to every language that the Azure SDK supports.


Introducing DefaultAzureCredential

You can use DefaultAzureCredential from the Azure Identity client libraries to implement passwordless connections to Azure services through Microsoft Entra ID and Role Based Access control (RBAC).

Important

Some languages require you to explicitly implement DefaultAzureCredential in your code, while others use DefaultAzureCredential internally through underlying plugins or drivers.

DefaultAzureCredential supports multiple authentication methods and automatically determines which method to use at runtime. This approach enables your app to use different authentication methods in different environments (local dev vs. production) without implementing environment-specific code.

The order and locations in which DefaultAzureCredential searches for credentials vary between languages:

For example, when you work locally with .NET, DefaultAzureCredential generally authenticates by using the account you used to sign in to Visual Studio, Azure CLI, or Azure PowerShell. When you deploy the app to Azure, DefaultAzureCredential automatically discovers and uses the managed identity of the associated hosting service, such as Azure App Service. You don't need to make any code changes for this transition.

Tip

DefaultAzureCredential is convenient for local development. In production, consider using a specific credential, such as ManagedIdentityCredential, to avoid unexpected credential selection, reduce startup latency, and make authentication behavior predictable. For more information, see Authentication best practices with the Azure Identity library for .NET.

Note

A managed identity provides a security identity to represent an app or service. The Azure platform manages the identity and you don't need to provision or rotate secrets. To learn more, see the overview documentation.

The following code example demonstrates how to connect to Service Bus by using passwordless connections. Other documentation describes how to migrate to this setup for a specific service in more detail. A .NET app can pass an instance of DefaultAzureCredential into the constructor of a service client class. DefaultAzureCredential automatically discovers the credentials that are available in that environment.

ServiceBusClient serviceBusClient = new(
    new Uri("https://<your-service-bus-namespace>.servicebus.windows.net"),
    new DefaultAzureCredential());

See also

For a more detailed explanation of passwordless connections, see the developer guide Configure passwordless connections between multiple Azure apps and services.