> For the complete documentation index, see [llms.txt](https://docs.telm.ai/telmai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.telm.ai/telmai/connect-to-data/data-connections/sql-server-managed-identity.md).

# Azure Managed Identity Authentication

Authenticate MS SQL Server and Microsoft Fabric SQL connections with a Microsoft Entra managed identity.

**MS SQL Server** and **Microsoft Fabric SQL** connections can authenticate as a Microsoft Entra user-assigned managed identity that you create and register in Telmai. No password or secret is stored: each time the connection runs, Telmai requests a short-lived Entra token for the identity you selected on it. There is no shared or default identity, so you can register one identity per database or workspace, each with only the access it needs.

{% hint style="info" %}
Available only when Telmai runs on Azure. It doesn't depend on where your database runs. Hybrid deployments with an Azure-hosted agent also support it, but the setup differs; contact Telmai support.
{% endhint %}

## Before you connect

You need:

* a Telmai deployment on Azure;
* an Azure administrator who can create identities and federated credentials;
* the identity and the database or Fabric workspace in the **same Microsoft Entra tenant**. Subscription and resource group don't matter.

Telmai provides three values for step 3: the Kubernetes **ServiceAccount name**, its **namespace**, and the cluster **OIDC issuer URL**.

A managed identity has two IDs. The **Client ID** is what you register in Telmai (step 4). The **Object ID** (`principalId` in the CLI) is what you grant access to in SQL (step 2).

### 1. Create the managed identity

Create a user-assigned managed identity in the Azure portal's **Managed Identities** page, or with the CLI, and read its two IDs:

```bash
az identity create --resource-group <resource-group> --name <identity-name> --location <location>

az identity show --resource-group <resource-group> --name <identity-name> \
  --query "{clientId:clientId, objectId:principalId}" -o table
```

### 2. Grant the identity read access

**Azure SQL Database.** Connect to the target database with Microsoft Entra authentication as the server's Entra admin (or a `db_owner`), for example in SSMS, Azure Data Studio or the portal's Query editor. A SQL-authenticated login can't create Entra users. Then run:

```sql
-- <identity-name> is the name from step 1; <object-id> is its Object ID, not its Client ID
CREATE USER [<identity-name>] FROM EXTERNAL PROVIDER WITH OBJECT_ID = '<object-id>';
ALTER ROLE db_datareader ADD MEMBER [<identity-name>];
```

`db_datareader` is all a scan needs. If the statement returns *Principal … could not be resolved*, the identity isn't in the server's Entra tenant.

**Microsoft Fabric.** A managed identity is a service principal in Entra. Give it read access to the warehouse or lakehouse, and make sure **Service principals can use Fabric APIs** is on. See [Microsoft Fabric SQL](https://docs.telm.ai/telmai/connect-to-data/data-connections/microsoft-fabric.md#before-you-connect).

### 3. Federate the identity with Telmai

Add a federated credential on the identity that trusts Telmai's ServiceAccount:

```bash
az identity federated-credential create \
  --name federated-<identity-name> \
  --identity-name <identity-name> --resource-group <resource-group> \
  --issuer <cluster-oidc-issuer-url> \
  --subject system:serviceaccount:<namespace>:<serviceaccount-name> \
  --audience api://AzureADTokenExchange
```

The credential name is only a label. Trust comes from the issuer, subject and audience. Each identity adds its own federated credential for the same ServiceAccount.

### 4. Register the identity in Telmai

A Telmai administrator does this once per identity:

1. In **Administration**, under **Advanced settings**, select **Managed identities**.
2. Click **Add identity**.
3. Enter a **Managed identity name** (shown when creating a connection), the identity's **Client ID** from step 1, and an optional **Description**. The **Client ID** can't be changed later.
4. Click **Save**.

New identities are **Active**. Use the status toggle to revoke an identity, which stops connections from using it until you reactivate it, or click **Delete** to remove it. Deleting an identity that connections use stops them from working.

## Connection fields

Create an [MS SQL Server](https://docs.telm.ai/telmai/connect-to-data/data-connections/sql-server.md) or [Microsoft Fabric SQL](https://docs.telm.ai/telmai/connect-to-data/data-connections/microsoft-fabric.md) connection as usual. Set **Authentication Scheme** to **Managed Identity (connection)**, then pick the identity in **Managed Identity**. The list shows each identity's name and the end of its client ID. Only active identities registered for your tenant appear. For the other schemes, see [Authentication schemes](https://docs.telm.ai/telmai/connect-to-data/data-connections/sql-server.md#authentication-schemes).

A successful **Test connection** confirms the grant and the federation are in place.

The same registered identities can also authenticate the [Microsoft Fabric OneLake](https://docs.telm.ai/telmai/integrations/catalog-integration/microsoft-fabric-onelake.md) catalog integration.

## Limitations

* An identity in a different Entra tenant from the database or Fabric workspace isn't supported.
* A managed-identity token lasts about an hour, so a long-running or heavily queued scan can fail. Use a password or service principal scheme for those assets.
