Prefabricated Microsoft Fabric workspace provisioning via REST API. Batch-create Lakehouses, Notebooks, Warehouses, Pipelines, and Dataflows in a single notebook run using Service Principal authentication. Additional notebook specifically for Fabric Warehouse SPN ownership takeover.
| Notebook | Purpose |
|---|---|
000_spn_create_fabric_items.py |
Batch-create Fabric items (Lakehouses, Notebooks, Warehouses, Pipelines, Dataflows) with SPN ownership |
000_spn_warehouse_ownership_transfer.py |
Inventory warehouses with owner info and transfer ownership from users to SPN |
Standing up a new Fabric environment typically means clicking through the UI dozens of times... create a Lakehouse, create another Lakehouse, create a Notebook, create a Pipeline, repeat. With Fabric Prefab, you define all items in code and create them in one execution. Need 3 Lakehouses, 10 Notebooks, a Warehouse, and 5 Pipelines? Easy. Drop the notebook into your favorite AI for context, tell it the names you want for your objects, and it uses the functions to give you a copy-paste ready script. Boom, done.
This is the bigger reason to use this tool.
When a user creates Fabric items, that user becomes the owner. Fabric items use the owner's identity to access OneLake and other resources. This creates serious problems:
| Scenario | What happens |
|---|---|
| Owner leaves the organization | Items stop working immediately |
| Owner doesn't sign in for 90 days | Items can stop working |
| Owner of a Warehouse doesn't sign in for 30 days | Warehouse stops working (Fabric requires owner sign-in every 30 days for security token refresh) |
Ownership transfer exists but is painful:
- Must be done item-by-item in most cases
- Some items (mirrored databases) don't support ownership transfer at all
- Pipeline child items (notebooks, etc.) must be transferred separately
- Connections using the previous owner's credentials break and must be manually reconfigured
Items created by a Service Principal are owned by the SPN. The SPN doesn't go on vacation, doesn't leave the company, and doesn't forget to sign in. The 30-day token refresh can be automated via API calls. Your production environment stays stable.
What is a Service Principal?
A non-interactive identity for applications/automation. Unlike user accounts, SPNs don't require MFA, don't have expiring passwords (secrets do, but you control when), and can be scoped precisely.
Video explainer: Service Principals in Microsoft Fabric
📋 New to Service Principals?
Instructions for creating an SPN, setting up the required security group, and configuring tenant settings are at the bottom of this document. See:
Before using this notebook, ensure the following are in place:
A registered application in Microsoft Entra ID. See Creating a Service Principal below.
Required. Fabric tenant settings restrict SPN access to members of specified security groups—you cannot enable the tenant setting for "the entire organization" and expect individual SPNs to work. The SPN must be in a security group that is explicitly allowed. See Creating a Security Group below.
A Fabric Administrator must enable "Service principals can use Fabric APIs" in Developer settings and add your security group. See Configuring Tenant Settings below.
The SPN must have Contributor (minimum), Member, or Admin role on the target workspace:
- Open the workspace in Fabric
- Click Manage access
- Click + Add people or groups
- Search for the SPN by name (it appears like a user)
- Select Contributor role
- Click Add
Have the following ready (stored in Azure Key Vault recommended):
- Tenant ID
- Application (Client) ID
- Client Secret
Batch-create Fabric items with SPN ownership.
- Lakehouse (standard or schema-enabled)
- Notebook
- Warehouse
- Data Pipeline
- Dataflow Gen2
import notebookutils.credentials as cred
KEY_VAULT_NAME = "your-keyvault-name"
KEY_VAULT_URL = f"https://{KEY_VAULT_NAME}.vault.azure.net/"
TENANT_ID = cred.getSecret(KEY_VAULT_URL, "aad-tenant-id")
SP_CLIENT_ID = cred.getSecret(KEY_VAULT_URL, "fabric-spn-client-id")
SP_CLIENT_SECRET = cred.getSecret(KEY_VAULT_URL, "fabric-spn-client-secret")TENANT_ID = "your-tenant-id"
SP_CLIENT_ID = "your-client-id"
SP_CLIENT_SECRET = "your-client-secret"Uncomment the desired lines in the Execution section. Create as many items as you need in a single run:
# Lakehouses (set enable_schemas=True for schema-enabled)
create_lakehouse(access_token, "lh_bronze", enable_schemas=True)
create_lakehouse(access_token, "lh_silver", enable_schemas=True)
create_lakehouse(access_token, "lh_gold", enable_schemas=True)
# Notebooks
create_notebook(access_token, "nb_100_ingest_raw")
create_notebook(access_token, "nb_200_transform")
create_notebook(access_token, "nb_300_load_warehouse")
create_notebook(access_token, "nb_900_run_all")
# Warehouses
create_warehouse(access_token, "wh_reporting")
# Pipelines
create_pipeline(access_token, "pl_100_orchestration")
create_pipeline(access_token, "pl_200_daily_refresh")
# Dataflows
create_dataflow_gen2(access_token, "df_transform_customers")
create_dataflow_gen2(access_token, "df_transform_orders")All items are created in the current workspace (auto-detected from runtime context).
Inventory warehouses and transfer ownership from users to the Service Principal.
User-owned warehouses break when:
- Owner's account is deactivated (immediate failure)
- Owner doesn't sign in for 30 days (token expiry—Fabric requirement)
- Owner leaves the organization
SPN ownership eliminates these risks.
This notebook uses the Admin API to retrieve owner information. This requires an additional tenant setting beyond the Developer settings:
Admin Portal → Tenant Settings → Admin API settings:
- Locate "Service principals can access read-only admin APIs"
- Set to Enabled
- Select Specific security groups
- Add the same security group containing your SPN
- Click Apply
Without this setting, the inventory call returns HTTP 403.
df_inventory = get_warehouse_inventory_dataframe(access_token)
display(df_inventory)Returns a DataFrame with:
workspace_nameworkspace_idwarehouse_namewarehouse_idowner_upnowner_display_name
# Take over ALL warehouses in the current workspace
results = takeover_warehouses_batch(access_token)
# Or take over specific warehouses by ID
warehouse_ids_to_takeover = [
"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy",
]
results = takeover_warehouses_batch(access_token, warehouse_ids=warehouse_ids_to_takeover)The takeover API transfers ownership to the calling identity. When authenticated as the SPN, the SPN becomes the new owner.
| Error | Cause | Solution |
|---|---|---|
401 Unauthorized |
Invalid or expired token | Verify credentials; regenerate client secret if expired |
403 Forbidden |
SPN lacks workspace access | Add SPN as Contributor to workspace |
403 Forbidden on Admin API |
Admin API tenant setting not enabled | Enable "Service principals can access read-only admin APIs" in Admin API settings |
PrincipalTypeNotSupported |
Tenant setting not enabled for SPNs | Enable "Service principals can use Fabric APIs" and add SPN's security group |
ItemDisplayNameAlreadyInUse |
Duplicate item name | Use a unique name |
spn-global-fabric
You must hold Application Administrator or Owner rights in the Azure tenant. If blocked, use the Admin Request Template below.
- Browse to https://portal.azure.com
- Select Microsoft Entra ID
- Navigate to Manage → App registrations → + New registration
- Name:
spn-global-fabric - Supported account types: Single tenant
- Click Register
- In the app blade, locate Managed application in local directory
- If blank, click Create service principal
- Navigate to Certificates & secrets → + New client secret
- Description:
fabric-access-key - Expiration: 6–12 months
- Click Add
- Secret Value
- Secret ID
- Application (Client) ID
- Directory (Tenant) ID
- Secret Expiration Date
- SPN Name
Store all items securely in Azure Key Vault.
- In Azure Portal, navigate to Microsoft Entra ID → Groups
- Click + New group
- Group type: Security
- Group name:
sg-fabric-spn-access(or similar) - Click Create
- Open the security group you created
- Navigate to Members → + Add members
- Search for your SPN by name (
spn-global-fabric) - Select it and click Select
A Fabric Administrator must complete these steps in the Fabric Admin Portal.
- Navigate to Admin Portal → Tenant Settings → Developer settings
- Locate "Service principals can use Fabric APIs"
- Set to Enabled
- Select Specific security groups
- Add the security group containing your SPN (e.g.,
sg-fabric-spn-access) - Click Apply
- Navigate to Admin Portal → Tenant Settings → Admin API settings
- Locate "Service principals can access read-only admin APIs"
- Set to Enabled
- Select Specific security groups
- Add the same security group containing your SPN
- Click Apply
Note: As of mid-2025, Microsoft is splitting the Developer setting into two:
- Service principal access to global APIs — For creating workspaces, connections, deployment pipelines (disabled by default)
- Service principal access to permission-based APIs — For CRUD operations on existing workspace items (enabled by default)
Check your tenant settings if you encounter
PrincipalTypeNotSupportederrors.
If you lack permissions to create the SPN yourself, send this to your Azure admin:
Subject: Request to Create SPN for Microsoft Fabric Integration
Hi [Azure Admin Team],
Please create a service principal named spn-global-fabric.
After creation, either:
1. Assign me Owner on the app registration, OR
2. Provide:
• Application (Client) ID
• Directory (Tenant) ID
• Secret Value (only shown once)
• Secret ID
• Secret Expiration Date
• SPN Name
Additionally, please:
3. Create a security group (e.g., sg-fabric-spn-access) and add the SPN as a member
4. Provide the security group name so it can be added to Fabric tenant settings
Purpose: Secure automation for Microsoft Fabric workloads.
- SPNs cannot log into the Fabric portal interactively
- SPNs are not supported for GIT APIs
- SPNs cannot perform DCL operations (GRANT, REVOKE, DENY) in warehouses
- Some APIs still require user principal authentication—check the API reference for "Microsoft Entra supported identities"
- SPN tokens require renewal every 30 days (automate via OAuth 2.0 client-credentials flow or scheduled API calls)