Skip to the stories
Microsoft 365 & SharePoint

Secure Fabric Gen2 Dataflow API Keys with Azure Key Vault

  • John Kerski
  • 803 views

Use a Fabric workspace identity and pipeline to retrieve API secrets from Key Vault and pass them to Gen2 dataflows at runtime.

Secure Fabric Gen2 Dataflow API Keys with Azure Key Vault

Keeping an API key out of Power Query takes more than moving it to a different field. In Microsoft Fabric, a Gen2 dataflow can receive a credential at runtime from a pipeline, which retrieves it from Azure Key Vault. That gives administrators a way to keep the key out of the dataflow’s code and default parameter value while still using it to authenticate an API request.

The pattern has several parts to configure: a Key Vault secret, a workspace identity with permission to read it, an exposed Gen2 dataflow parameter, and a pipeline that passes the retrieved value to the dataflow. Secure input and output settings help keep the value out of pipeline activity logs. The credential still needs careful handling inside the dataflow, where it exists as a string during execution.

Where this pattern fits

This setup is useful when a dataflow must call an authenticated endpoint that needs an API key or bearer token, or a custom service without an OAuth connection supported by Fabric. It can also help teams run the same dataflow in different environments while supplying each environment’s own credential.

Use a native OAuth connection when Fabric provides a suitable secure connector for the source. The Key Vault and pipeline approach fills gaps where a first-class connection isn’t available; it doesn’t replace one.

Gen1 dataflows don’t support the runtime parameter injection this pattern depends on. With Gen1, a key referenced in Power Query may be stored as plain text in the dataflow. Gen2 supports parameters that a pipeline can override when it runs the dataflow.

Requirements and information to collect

You’ll need a Fabric workspace with Gen2 dataflow and pipeline authoring enabled, workspace administrator rights, and Fabric capacity that supports pipelines and dataflows. Some AI features in Gen2 require paid capacity, but public parameters don’t depend on Copilot licensing.

You’ll also need an Azure Key Vault that the workspace can reach, and permission to grant the workspace identity access to that vault. Before wiring up the pipeline, collect the Key Vault URI and secret name, plus the workspace identity’s client ID, tenant ID, and client secret. Store these details securely while you configure the connection.

Store the API credential in Key Vault

Create a Key Vault secret for the API key or token. This step takes place outside Fabric. The Key Vault creation walkthrough is available in Microsoft’s Azure Key Vault documentation; instructions for adding a secret are available here.

Use a predictable vault name. A prefix such as kv- followed by a purpose, for example kv-fabric-key-storage or kv-dataflow-keys, makes the resource easier to identify. After creating the secret, copy its identifier and record the vault name and secret name. You’ll also need the vault URI, shown on the Key Vault Overview page.

Secret identifier copied from a newly created Key Vault secret
Secret identifier copied from the newly created Key Vault secret
Vault URI on the Key Vault Overview page
The Vault URI shown on the Key Vault Overview page

Give the workspace identity access

The pipeline needs permission to read the secret. Use the Fabric workspace identity for this access. In the workspace, open Workspace Settings, go to Workspace Identity, and select + Workspace Identity to create it.

Workspace Identity section in Workspace Settings
The Workspace Settings page showing the Workspace Identity section
Button to create a workspace identity
The + Workspace Identity button
New workspace identity while its Name field is temporarily blank
The newly created identity may briefly show a blank Name field

The identity can take a few seconds to appear, and its Name field may initially be blank. Refresh the browser and return to the identity settings; the name should then match the workspace.

Workspace identity showing its name after refreshing
Workspace identity showing its name after refreshing the browser

Next, open the vault in the Azure portal and go to Access control (IAM). Choose Add, then Add Role Assignment. Select the Key Vault Secrets User role. In Members, select User, group, or service principal, then use Select members to find the workspace identity by its workspace name. Finish with Review + assign.

Access control (IAM) page for the Key Vault
The Access control (IAM) page for the Key Vault
Add Role Assignment option in Access control (IAM)
Add Role Assignment option
Key Vault Secrets User role selected
The Key Vault Secrets User role selected
Members tab with User, group, or service principal selected
Members tab with the required member type selected
Select members button on the role assignment screen
Select members on the role assignment screen
Workspace identity selected as a role assignment member
The workspace identity selected as a member
Review and assign screen for the role assignment
Review the role assignment before applying it

Record the identity details

A workspace identity is a service principal in Microsoft Entra. To find its application details, open App registrations from the Manage section in Microsoft Entra. Under All Applications, search for the workspace name and select the matching entry.

Copy the Client ID and Tenant ID from the application overview. Then open Certificates and Secrets, select Client secrets, and choose + New Client Secret. Give the secret a descriptive name, such as Fabric Pipeline Use, and set its expiration period.

Copy the new client secret value while it’s displayed. It can’t be retrieved from this page after you navigate away. Keep it with the client ID and tenant ID in a secure location for the connection setup. Set a calendar reminder before the expiry date; if the credential expires without being replaced, the pipeline can stop retrieving the Key Vault value.

App registrations option under Manage in Microsoft Entra
App registrations under Manage
App registration search results filtered by workspace name
Search for the application matching the workspace identity
Application overview with Client ID and Tenant ID fields
Copy the Client ID and Tenant ID from the application overview
Certificates and Secrets area for the app registration
Certificates and Secrets for the app registration
New client secret button in the Client secrets tab
Create a client secret from the Client secrets tab
Client secret setup panel with name and expiration fields
Set a name and expiration for the client secret
Newly generated client secret value
Copy the client secret while it is visible

Create the Gen2 dataflow parameter

In the Fabric workspace, create a Dataflow Gen2. In Power Query, select Home > Manage parameters > New parameter. Name the parameter API_SECRET, set its type to Text, and use a non-sensitive default such as placeholder. The parameter can be optional while you build the dataflow; mark it required when you connect it to the pipeline so a missing runtime value causes the run to fail.

Manage parameters menu path for creating a parameter
Create a parameter from Manage parameters
New parameter dialog
Enter the parameter name
Text parameter with a placeholder default value
Use Text type and a non-sensitive placeholder

For the pipeline to discover and override the parameter, open Home > Options, go to Parameters, and enable Enable parameters to be discovered and override for execution. Save the dataflow after changing this setting. The pipeline won’t surface the parameter until this feature is enabled and the dataflow is saved.

Options menu from the Home tab
Open Options from the Home tab
Setting to enable parameter discovery and execution overrides
Enable parameter discovery and execution overrides

Use Save to store the dataflow configuration. The parameter can then be referenced in Power Query wherever the API call needs authentication. For an endpoint that expects a key in a request header, the query can follow this pattern:

let
    Source = Web.Contents(
        "https://api.example.com/v1/data",
        [
            Headers = [#"x-api-key" = API_SECRET]
        ]
    ),
    Json = Json.Document(Source)
in
    Json

API_SECRET is a parameter reference here, not a literal credential. The pipeline supplies its value when the dataflow runs.

Build the pipeline to retrieve and pass the secret

Create a pipeline in the same workspace. Its sequence is straightforward: a Web Activity reads the secret from Key Vault, a Set Variable activity captures the returned value, and a Dataflow activity passes that variable into the Gen2 parameter.

Add a Web Activity and give it a descriptive name. In Advanced, enable Secure Output so the retrieved value is hidden from the activity output. In Settings, open the connection menu, choose Browse all, and select Web v2 under New Sources.

Web Activity added to a pipeline
Add a Web Activity to the pipeline
Web Activity with a descriptive name
Give the activity a descriptive name
Secure Output enabled in the Advanced section
Enable Secure Output
Browse all connections option in Web Activity settings
Browse available connections
Web v2 connection selected under New Sources
Select the Web v2 connection

Configure the connection with the vault and identity details you recorded:

PropertyValue
Base URLThe Key Vault URI
Token Audience URLhttps://vault.azure.net
Authentication KindService Principal
Tenant IDThe saved Tenant ID
Service principal client IDThe saved Client ID
Service Principal KeyThe saved Client Secret
Privacy LevelOrganizational

Select Connect. Back in the Web Activity settings, set Relative URL to /secrets/{Secret Name}?api-version=7.4, replacing {Secret Name} with the Key Vault secret’s name. For example, if the secret is named ApiKey, use that name in the path.

Connect button for creating the Web v2 connection
Connect to finish setting up Web v2
Relative URL field with the Key Vault secret path and API version
Set the secret path and API version in Relative URL

Add a Set Variable activity and connect it after the Web Activity. Give it a clear name, enable Secure Output, then use Settings > + New to create a variable. Keep the variable type as string. Set its value to the Web Activity’s returned secret:

@activity('WebActivityName').output.value

Replace WebActivityName with the actual activity name. For an activity named Get API Key from Key Vault, the expression is @activity('Get API Key from Key Vault').output.value.

Set Variable activity on the pipeline canvas
Add a Set Variable activity
Web Activity connected to Set Variable
Connect the Web Activity to Set Variable
Set Variable activity with Secure Output enabled
Enable Secure Output on Set Variable
New variable button in Set Variable settings
Create a variable in the activity settings
New variable dialog with string type selected
Set the variable type to string
Variable value referencing the Web Activity output
Reference the Web Activity output as the variable value

Finally, add a Dataflow activity and connect it after Set Variable. Give the activity a descriptive name and enable Secure Input. In Settings, select the Gen2 dataflow, expand Dataflow parameters, and map the API_SECRET parameter to the pipeline variable. If the variable is named str-api-key, enter:

@variables('str-api-key')

Check that the expression uses the variable’s name, not the Set Variable activity’s name.

Dataflow activity added to the pipeline
Add the Dataflow activity
Set Variable connected to the Dataflow activity
Connect Set Variable to the Dataflow activity
Dataflow activity with Secure Input enabled
Enable Secure Input on the Dataflow activity
Dataflow activity settings pointing to a Gen2 dataflow
Select the Gen2 dataflow in the activity settings
Dataflow parameter mapped to a pipeline variable
Map the dataflow parameter to the pipeline variable

Run checks and handle the credential carefully

Run the pipeline and inspect its activity status. A successful run should retrieve the Key Vault value and allow the dataflow to authenticate. If the run fails, check that the workspace identity has the Key Vault Secrets User role, that the dataflow parameter is enabled for external discovery and override, and that the dataflow was saved after that setting was enabled. Confirm the relative URL includes ?api-version=7.4 and that the token audience is set to https://vault.azure.net.

Pipeline run history showing a successful execution
Check the pipeline run history after execution

Required parameters are a useful safeguard for API credentials: the run fails when the pipeline doesn’t supply a value. Optional parameters use their default value instead, which can hide a broken Key Vault step or cause an authentication failure later in the dataflow.

Secure Output on the Web and Set Variable activities, along with Secure Input on the Dataflow activity, helps mask the value in pipeline logs and activity details. It doesn’t prevent the dataflow from exposing the credential if a query writes it to a table or returns it as a result. Treat the parameter as a runtime credential throughout the query.

During development, entering a secret directly into the parameter can make it easier to test a query without running the pipeline each time. If you do this, use a separate development secret, replace the parameter default with a placeholder before using the pipeline, and expire the development secret when finished.

Before syncing a dataflow through Fabric Git Integration, check that its parameter default contains only a placeholder. A real key in the default value can be stored as plain text in the repository. The same check belongs in a deployment review: confirm the pipeline supplies the runtime value and the dataflow doesn’t save or return it.

The pattern adds configuration steps, but it gives administrators a clear path from Key Vault to an API request: grant the workspace identity read access, retrieve the secret in a pipeline, and inject it into a Gen2 parameter at execution time. The key operational checks are identity permissions, parameter exposure, secure activity settings, and a placeholder default value.

Source: John Kerski · www.red-gate.com

Neighbouring cells