Home / Databricks on Azure

Databricks on AzureRunbookAdvanced

Moving Azure Databricks off wasbs:// to abfss:// and Unity Catalog: inventory, rewrite and cutover runbook

WASB is deprecated on Azure Databricks. Find every wasbs:// path, key and mount, fix non-HNS accounts, move access to Unity Catalog, and switch tables and streams over without reprocessing data.

Deepak Bhardwaj6 min read

Applies toAzure Databricks (Premium) with Unity Catalog, Databricks Runtime 13.3 LTS and later, Azure Blob Storage and ADLS Gen2 accounts

Goal

Remove every wasbs://...blob.core.windows.net path, account key and mount from your Databricks estate. Access then runs through abfss://...dfs.core.windows.net, which Unity Catalog governs with storage credentials and external locations.

Databricks documents the Windows Azure Storage Blob driver (WASB) as deprecated in favour of the Azure Blob Filesystem driver (ABFS). WASB paths usually come with account keys or SAS tokens in cluster config, which gives anyone on the cluster full access to every container in the account. Unity Catalog can't govern those paths. The security gain is the main reason to do this work; the driver change is secondary.

Step 1: Inventory every WASB dependency

You need four lists: code, cluster config, mounts and table locations.

Code (Git repositories and workspace exports):

git grep -nE "wasbs?://|blob\.core\.windows\.net|fs\.azure\.(account\.key|sas)\." -- '*.py' '*.sql' '*.scala' '*.yml' '*.json'

databricks workspace export-dir /Workspace ./ws-export
grep -rnE "wasbs?://|blob\.core\.windows\.net" ./ws-export

Cluster and policy Spark config:

databricks clusters list -o json | jq -r '.[].cluster_id' | while read id; do
  databricks clusters get "$id" -o json |
    jq -r --arg id "$id" '.spark_conf // {} | to_entries[]
      | select(.key | test("blob.core.windows.net")) | "\($id)\t\(.key)"'
done

Look at job clusters too (databricks jobs list and then databricks jobs get <id>), and at cluster policies, which sometimes inject keys.

Mounts:

for m in dbutils.fs.mounts():
    if m.source.startswith("wasb"):
        print(m.mountPoint, m.source)

Table locations in the Hive metastore:

rows = []
for db in [d.databaseName for d in spark.sql("SHOW DATABASES IN hive_metastore").collect()]:
    for t in spark.sql(f"SHOW TABLES IN hive_metastore.{db}").collect():
        if t.isTemporary:
            continue
        loc = (spark.sql(f"DESCRIBE TABLE EXTENDED hive_metastore.{db}.{t.tableName}")
                    .filter("col_name = 'Location'").collect())
        if loc and loc[0].data_type.startswith("wasb"):
            rows.append((db, t.tableName, loc[0].data_type))
display(spark.createDataFrame(rows, "db string, tbl string, location string"))

If lineage system tables are enabled, system.access.table_lineage can also show which jobs read which paths. Column names vary by release, so check the schema first.

Step 2: Check each storage account's namespace

Unity Catalog external locations and the ABFS OAuth flow both expect ADLS Gen2, which is a storage account with hierarchical namespace (HNS) enabled.

az storage account show -n stlegacyraw -g rg-data --query "{hns:isHnsEnabled, kind:kind, sku:sku.name}" -o table
Result Path
hns: true You only need to rewrite paths. Same data, different endpoint (dfs instead of blob)
hns: false, account can be upgraded Run the in-place HNS upgrade (validate first)
hns: false, blocked by unsupported features Copy the data to a new HNS account with AzCopy, then cut over

In-place upgrade:

az storage account hns-migration start --type validation -n stlegacyraw -g rg-data
# read the validation result, fix blockers, then:
az storage account hns-migration start --type upgrade -n stlegacyraw -g rg-data

Caution

The HNS upgrade can't be reversed, and some Blob features are not supported on HNS accounts. Other applications that use the account through Blob APIs also need testing. Run the validation step, read the list of blocking features, and get sign-off from every owner of the account before you upgrade.

Copy option:

azcopy copy "https://stlegacyraw.blob.core.windows.net/raw/*" \
            "https://stlakeraw.dfs.core.windows.net/raw/" --recursive

Step 3: Set up governed access

Create an access connector (managed identity), and give it Storage Blob Data Contributor on the account, or on the containers if you want narrower access. Then register it in Unity Catalog:

databricks storage-credentials create --json '{
  "name": "sc_lake_raw",
  "azure_managed_identity": {
    "access_connector_id": "/subscriptions/<sub>/resourceGroups/rg-data/providers/Microsoft.Databricks/accessConnectors/ac-lake"
  }
}'
CREATE EXTERNAL LOCATION IF NOT EXISTS el_raw
  URL 'abfss://raw@stlakeraw.dfs.core.windows.net/'
  WITH (STORAGE CREDENTIAL sc_lake_raw);

GRANT READ FILES, WRITE FILES ON EXTERNAL LOCATION el_raw TO `data-engineers`;

If the account sits behind a firewall, add resource instance rules for the access connector. Serverless compute also needs network connectivity configuration (NCC) rules.

Step 4: Rewrite paths and tables

The path mapping is mechanical:

wasbs://<container>@<account>.blob.core.windows.net/<path>
abfss://<container>@<account>.dfs.core.windows.net/<path>

For external Hive metastore tables on an HNS account, the files don't move. Point the metadata at the new URI, then upgrade the table to Unity Catalog with UCX or CREATE TABLE ... LOCATION:

ALTER TABLE hive_metastore.raw.events
SET LOCATION 'abfss://raw@stlakeraw.dfs.core.windows.net/events';

CREATE TABLE main.raw.events
LOCATION 'abfss://raw@stlakeraw.dfs.core.windows.net/events';

Replace mounts with volumes, then remove each mount once nothing uses it:

CREATE EXTERNAL VOLUME main.raw.landing
LOCATION 'abfss://raw@stlakeraw.dfs.core.windows.net/landing';
dbutils.fs.unmount("/mnt/legacy-raw")

Code that read /mnt/legacy-raw/... now reads /Volumes/main/raw/landing/....

Step 5: Streams and checkpoints

This is where reprocessing happens if you are careless.

Stream source What the checkpoint remembers Cutover approach
Delta table Table ID and versions Changing the URI to the same table is normally safe. Test on a cloned job with a copied checkpoint
Auto Loader / file source File paths it has already processed The new URI can make old files look new. Start a new checkpoint with modifiedAfter, or use cloudFiles.includeExistingFiles = false
Kafka / Event Hubs Offsets Not affected by the storage path, but the checkpoint location itself still moves
(spark.readStream.format("cloudFiles")
   .option("cloudFiles.format", "parquet")
   .option("cloudFiles.includeExistingFiles", "false")
   .load("abfss://raw@stlakeraw.dfs.core.windows.net/events_in/")
   .writeStream
   .option("checkpointLocation", "/Volumes/main/raw/checkpoints/events_in_v2")
   .toTable("main.raw.events"))

Warning

If you start a new file-source checkpoint without includeExistingFiles = false or a modifiedAfter boundary, the stream reprocesses every file in the directory. Sinks that aren't idempotent end up with duplicates. Stop the old stream at a known point, note the last file timestamp, and start the new stream from that boundary.

Step 6: Remove the keys and verify

  1. Delete the fs.azure.account.key.*.blob.core.windows.net and fs.azure.sas.* entries from clusters, policies and init scripts.
  2. Rotate the storage account keys. Anything that still uses them fails loudly now, not months later.
  3. Set allowSharedKeyAccess to false on the account when nothing else needs keys:
az storage account update -n stlakeraw -g rg-data --allow-shared-key-access false
  1. Confirm that no traffic still uses key auth:
StorageBlobLogs
| where TimeGenerated > ago(7d) and AccountName == "stlakeraw"
| summarize count() by AuthenticationType, bin(TimeGenerated, 1d)

Key or SAS traffic should drop to zero. Only OAuth should remain.

Prevent it next time

  • In cluster policies, mark the known spark_conf.fs.azure.account.key.<account>... keys as "type": "forbidden". Better still, move workloads to Unity Catalog-enabled access modes, where these keys have no use.
  • Add a CI check that fails on wasbs://, blob.core.windows.net and dbutils.fs.mount in new code.
  • Create new storage accounts with HNS enabled and shared key access disabled from day one.