To mount a datalake / blob storage in databricks using service principal, it needs the service principal through Azure app registration to get the client id, secret and tenant id.
If it's a blob storage within the same azure space, go to the blob storage -> Access control to assign a role / access to the service principal.
If it's a blob storage / onelake within powerbi / Fabric, as the storage is not in your Azure space but a public space, you will need to enable service principal (app registration) to access the Fabric / Power BI space, e.g. reading OneLake / lakehouse.
Go to the Power BI admin portal
1. Tenant settings -> Developer Setting, "Allow service principals to use Power BI APIs" set to enabled
2. Tenant settings -> OneLake Setting, "Users can access data stored in OneLake with apps external to Fabric"
Once that is done, just go to "Manage Access" in you powerbi workspaces, add the service principal as a memeber and, to give read/write/execute access to workspaces or specifix resources. Now you can use the service principals keys to access the power bi / fabric resources.
# The format of abfss is: abfss://file_system@account_name.dfs.core.windows.net/<path>/<path>
url = 'abfss://11111-22222-33333-44444-55555@onelake.dfs.fabric.microsoft.com/xxxx-yyyy/'
client_id = '11111-22222-33333-44444-55555'
client_secret = 'xyz'
tenant_id = '123'
configs = {
"fs.azure.account.auth.type": "OAuth",
"fs.azure.account.oauth.provider.type": "org.apache.hadoop.fs.azurebfs.oauth2.ClientCredsTokenProvider",
"fs.azure.account.oauth2.client.id": client_id,
"fs.azure.account.oauth2.client.secret": client_secret,
"fs.azure.account.oauth2.client.endpoint": f"https://login.microsoftonline.com/{tenant_id}/oauth2/token"
}
dbutils.fs.mount(
source = url,
mount_point = "/mnt/lakehouse",
extra_configs = configs)
To unmount the storage:
dbutils.fs.unmount("/mnt/lakehouse")
To lis files in the storage:
dbutils.fs.ls('dbfs:/mnt/lakehouse/')