|
| 1 | +# Authentication |
| 2 | + |
| 3 | +The dbt-fabric-samdebruyn adapter supports a variety of authentication methods so you can connect to Microsoft Fabric from any environment. This guide walks through each method, explains when to use it, and provides ready-to-use `profiles.yml` examples. |
| 4 | + |
| 5 | +!!! tip "Quick recommendation" |
| 6 | + |
| 7 | + | Scenario | Recommended method | |
| 8 | + | --- | --- | |
| 9 | + | Local development | [`CLI`](#azure-cli) or [`auto`](#automatic-defaultazurecredential) | |
| 10 | + | CI/CD pipelines | [`environment`](#environment-variables) or [`ActiveDirectoryServicePrincipal`](#service-principal) | |
| 11 | + | Fabric Notebook | [`environment`](#environment-variables) or [`ActiveDirectoryServicePrincipal`](#service-principal) | |
| 12 | + |
| 13 | +All examples below assume the following base profile structure. Only the authentication-related keys change per method. |
| 14 | + |
| 15 | +```yaml |
| 16 | +default: |
| 17 | + target: dev |
| 18 | + outputs: |
| 19 | + dev: |
| 20 | + type: fabric |
| 21 | + workspace: My Workspace |
| 22 | + database: my_data_warehouse |
| 23 | + schema: dbt |
| 24 | + # + authentication keys shown below |
| 25 | +``` |
| 26 | + |
| 27 | +??? tip "Use environment variables for secrets" |
| 28 | + |
| 29 | + Never hardcode secrets in your `profiles.yml`. Use Jinja to reference environment variables: |
| 30 | + |
| 31 | + ```yaml |
| 32 | + client_secret: "{{ env_var('AZURE_CLIENT_SECRET') }}" |
| 33 | + ``` |
| 34 | + |
| 35 | +--- |
| 36 | + |
| 37 | +## Local development |
| 38 | + |
| 39 | +### Azure CLI |
| 40 | + |
| 41 | +The simplest way to authenticate during local development. Log in once with the Azure CLI and dbt will reuse that session. |
| 42 | + |
| 43 | +**Step 1 — Log in** |
| 44 | + |
| 45 | +```bash |
| 46 | +az login |
| 47 | +``` |
| 48 | + |
| 49 | +Your account does not need access to any Azure subscription — it only needs access to your Fabric workspace. |
| 50 | + |
| 51 | +**Step 2 — Configure your profile** |
| 52 | + |
| 53 | +```yaml |
| 54 | +default: |
| 55 | + target: dev |
| 56 | + outputs: |
| 57 | + dev: |
| 58 | + type: fabric |
| 59 | + database: my_data_warehouse |
| 60 | + schema: dbt |
| 61 | + workspace: My Workspace # or use host |
| 62 | + authentication: CLI |
| 63 | +``` |
| 64 | +
|
| 65 | +!!! info "Keep your Azure CLI up to date" |
| 66 | +
|
| 67 | + There have been reports of issues when using an outdated version of the Azure CLI. Run `az upgrade` to make sure you are on the latest version. |
| 68 | + |
| 69 | +The Azure CLI itself supports [multiple login methods](https://learn.microsoft.com/cli/azure/authenticate-azure-cli?view=azure-cli-latest&WT.mc_id=MVP_310840) (browser, device code, service principal, managed identity, …), making this a flexible option that adapts to many scenarios. |
| 70 | + |
| 71 | +### Automatic (`DefaultAzureCredential`) |
| 72 | + |
| 73 | +Set `authentication` to `auto` (or omit it entirely — it's the default). The adapter uses the Azure Identity SDK's [`DefaultAzureCredential`](https://learn.microsoft.com/python/api/azure-identity/azure.identity.defaultazurecredential?view=azure-python&WT.mc_id=MVP_310840) which tries several credential sources in order: |
| 74 | + |
| 75 | +1. Environment variables |
| 76 | +2. Workload identity |
| 77 | +3. Managed identity |
| 78 | +4. Azure CLI |
| 79 | +5. Azure PowerShell |
| 80 | +6. Azure Developer CLI |
| 81 | +7. Interactive browser (if available) |
| 82 | + |
| 83 | +```yaml |
| 84 | +default: |
| 85 | + target: dev |
| 86 | + outputs: |
| 87 | + dev: |
| 88 | + type: fabric |
| 89 | + database: my_data_warehouse |
| 90 | + schema: dbt |
| 91 | + workspace: My Workspace |
| 92 | + # authentication: auto ← this is the default, can be omitted |
| 93 | +``` |
| 94 | + |
| 95 | +This means that if you are logged in with **Azure PowerShell** (`Connect-AzAccount`), it will automatically be picked up — no extra configuration needed. |
| 96 | + |
| 97 | +!!! tip "When to use `auto` vs `CLI`" |
| 98 | + |
| 99 | + `auto` tries multiple credential sources in a chain, which means it can be slightly slower on first connection. It can also pick up credentials you don't intend to use — for example, a managed identity or environment variables left over from another tool. If you know you will always use the Azure CLI, setting `authentication: CLI` explicitly skips the chain, connects faster, and ensures no unexpected credentials are used. |
| 100 | + |
| 101 | +--- |
| 102 | + |
| 103 | +## CI/CD & automated environments |
| 104 | + |
| 105 | +### Service Principal |
| 106 | + |
| 107 | +Use a Microsoft Entra ID app registration (service principal) with a client secret. This is ideal for unattended, automated runs. |
| 108 | + |
| 109 | +**Prerequisites:** |
| 110 | + |
| 111 | +- A registered application in Microsoft Entra ID |
| 112 | +- The application must have access to your Fabric workspace |
| 113 | +- You need the **client ID**, **client secret**, and **tenant ID** |
| 114 | + |
| 115 | +```yaml |
| 116 | +default: |
| 117 | + target: ci |
| 118 | + outputs: |
| 119 | + ci: |
| 120 | + type: fabric |
| 121 | + database: my_data_warehouse |
| 122 | + schema: dbt |
| 123 | + workspace: My Workspace |
| 124 | + authentication: ActiveDirectoryServicePrincipal |
| 125 | + tenant_id: "{{ env_var('AZURE_TENANT_ID') }}" |
| 126 | + client_id: "{{ env_var('AZURE_CLIENT_ID') }}" |
| 127 | + client_secret: "{{ env_var('AZURE_CLIENT_SECRET') }}" |
| 128 | +``` |
| 129 | + |
| 130 | +!!! warning "Tenant ID is required" |
| 131 | + |
| 132 | + When using `ActiveDirectoryServicePrincipal` together with [`workspace_name`](configuration.md#workspace_name) or [`workspace_id`](configuration.md#workspace_id) — or when running Python models — the `tenant_id` must be provided. |
| 133 | + |
| 134 | +### Environment variables |
| 135 | + |
| 136 | +Set `authentication` to `environment` and configure credentials through environment variables. The adapter uses Azure Identity's [`EnvironmentCredential`](https://learn.microsoft.com/python/api/azure-identity/azure.identity.environmentcredential?view=azure-python&WT.mc_id=MVP_310840), which supports the following variables: |
| 137 | + |
| 138 | +=== "Service principal with secret" |
| 139 | + |
| 140 | + | Variable | Description | |
| 141 | + | --- | --- | |
| 142 | + | `AZURE_TENANT_ID` | Microsoft Entra tenant ID | |
| 143 | + | `AZURE_CLIENT_ID` | Application (client) ID | |
| 144 | + | `AZURE_CLIENT_SECRET` | Client secret | |
| 145 | + |
| 146 | +=== "Service principal with certificate" |
| 147 | + |
| 148 | + | Variable | Description | |
| 149 | + | --- | --- | |
| 150 | + | `AZURE_TENANT_ID` | Microsoft Entra tenant ID | |
| 151 | + | `AZURE_CLIENT_ID` | Application (client) ID | |
| 152 | + | `AZURE_CLIENT_CERTIFICATE_PATH` | Path to a PEM or PKCS12 certificate | |
| 153 | + | `AZURE_CLIENT_CERTIFICATE_PASSWORD` | *(optional)* Certificate password | |
| 154 | + |
| 155 | +=== "Username & password" |
| 156 | + |
| 157 | + | Variable | Description | |
| 158 | + | --- | --- | |
| 159 | + | `AZURE_TENANT_ID` | Microsoft Entra tenant ID | |
| 160 | + | `AZURE_CLIENT_ID` | Application (client) ID | |
| 161 | + | `AZURE_USERNAME` | Username | |
| 162 | + | `AZURE_PASSWORD` | Password | |
| 163 | + |
| 164 | +```yaml |
| 165 | +default: |
| 166 | + target: ci |
| 167 | + outputs: |
| 168 | + ci: |
| 169 | + type: fabric |
| 170 | + database: my_data_warehouse |
| 171 | + schema: dbt |
| 172 | + workspace: My Workspace |
| 173 | + authentication: environment |
| 174 | +``` |
| 175 | + |
| 176 | +This method keeps your `profiles.yml` completely free of secrets, which is an advantage over the explicit `ActiveDirectoryServicePrincipal` method. |
| 177 | + |
| 178 | +--- |
| 179 | + |
| 180 | +## Fabric Notebook |
| 181 | + |
| 182 | +When running dbt inside a **Fabric Notebook**, the recommended approach is to use **environment variable** or **service principal** authentication. |
| 183 | + |
| 184 | +Configure your notebook to set the required environment variables (e.g. `AZURE_TENANT_ID`, `AZURE_CLIENT_ID`, `AZURE_CLIENT_SECRET`) and use the [`environment`](#environment-variables) or [`ActiveDirectoryServicePrincipal`](#service-principal) method. |
| 185 | + |
| 186 | +```yaml |
| 187 | +default: |
| 188 | + target: notebook |
| 189 | + outputs: |
| 190 | + notebook: |
| 191 | + type: fabric |
| 192 | + database: my_data_warehouse |
| 193 | + schema: dbt |
| 194 | + workspace: My Workspace |
| 195 | + authentication: environment |
| 196 | +``` |
| 197 | + |
| 198 | +Alternatively, with explicit service principal configuration: |
| 199 | + |
| 200 | +```yaml |
| 201 | +default: |
| 202 | + target: notebook |
| 203 | + outputs: |
| 204 | + notebook: |
| 205 | + type: fabric |
| 206 | + database: my_data_warehouse |
| 207 | + schema: dbt |
| 208 | + workspace: My Workspace |
| 209 | + authentication: ActiveDirectoryServicePrincipal |
| 210 | + tenant_id: "{{ env_var('AZURE_TENANT_ID') }}" |
| 211 | + client_id: "{{ env_var('AZURE_CLIENT_ID') }}" |
| 212 | + client_secret: "{{ env_var('AZURE_CLIENT_SECRET') }}" |
| 213 | +``` |
| 214 | + |
| 215 | +!!! warning "`FabricSpark` is currently broken" |
| 216 | + |
| 217 | + The adapter also has a `FabricSpark` (alias `SynapseSpark`) authentication method that uses [NotebookUtils](https://learn.microsoft.com/fabric/data-engineering/notebook-utilities?WT.mc_id=MVP_310840) to obtain an access token from the notebook session. However, this method is **not working** at the moment because Microsoft's Runtime in the Notebooks returns a credential with a scope that is not allowed to access Data Warehouses and SQL Endpoints. Use one of the alternatives above instead. |
| 218 | + |
| 219 | +--- |
| 220 | + |
| 221 | +## Other methods |
| 222 | + |
| 223 | +The adapter supports several additional authentication methods such as managed identity, interactive browser, and pre-acquired access tokens. For a complete list of all supported methods and their configuration options, see the [configuration documentation](configuration.md#authentication). |
| 224 | + |
| 225 | +--- |
| 226 | + |
| 227 | +## Troubleshooting |
| 228 | + |
| 229 | +### Which authentication method is being used? |
| 230 | + |
| 231 | +Run `dbt debug` to see the resolved connection information, including the active authentication method. |
| 232 | + |
| 233 | +```bash |
| 234 | +dbt debug |
| 235 | +``` |
| 236 | + |
| 237 | +### Common issues |
| 238 | + |
| 239 | +| Symptom | Likely cause | Fix | |
| 240 | +| --- | --- | --- | |
| 241 | +| `Login timeout expired` | Slow network or restrictive firewall | Increase [`login_timeout`](configuration.md#login_timeout) (e.g. `30`) | |
| 242 | +| `AADSTS700016: Application not found` | Wrong `client_id` or the app isn't registered in the correct tenant | Verify the app registration in Microsoft Entra ID | |
| 243 | +| `DefaultAzureCredential failed` | No valid credential source found | Make sure you are logged in (`az login` / `Connect-AzAccount`) or that environment variables are set | |
| 244 | +| `Token expired` when using `access_token` | The pre-acquired token has expired | Refresh the token before running dbt | |
| 245 | +| `notebookutils not found` | Using `FabricSpark` outside of a Fabric/Synapse notebook | Switch to a different authentication method | |
0 commit comments