Skip to main content

GCP GCS

You'll create a Unity Catalog storage credential (a GCP service account Databricks manages for you), grant that service account access to a GCS bucket, then create an external location that points Databricks at it in ~10 min. Need file events? Add the optional part. Need a bucket first? See the bonus at the end.

Prereqs: Cloud Object Storage overview, a GCP project with permission to grant IAM roles on the bucket, and a Databricks metastore admin or account admin

Existing or new bucket​

Unity Catalog reaches Google Cloud Storage through an external location — a named object that points at a gs:// path through a storage credential (a GCP service account Databricks authenticates as). There are two reasons to create one:

  • Access an existing GCS bucket with data. When a bucket already holds data, point an external location at it so Unity Catalog can read (and optionally write) that data in place — usually to ingest it into Databricks. Mark the location read-only if you only need to read from it.
  • Use a new bucket for Unity Catalog managed data. Create a fresh GCS bucket for Unity Catalog to store managed tables and volumes, then point an external location (or a catalog's managed storage) at it.

Either way, the setup below is the same. This page assumes the bucket already exists; if it doesn't, create one first with the bonus.

The big picture​

A GCS bucket Databricks reaches through a Unity Catalog storage credential and external location. Unlike AWS, you don't approve an automatic role hand-off: Databricks generates a GCP service account when you create the storage credential, and you grant that service account access to the bucket in the Google Cloud console. If you want file events, you also create a custom Pub/Sub role and let the Cloud Storage service agent publish notifications.

Permissions you need​

Check these before you start.

GCP​

  • Ability to sign in to the GCP project that owns the bucket and grant IAM roles on the bucket (for example Storage Admin or Owner). Granting roles on the bucket is what lets Databricks' service account read and write.
  • To enable file events, you also need permission to create a custom IAM role and grant project-level roles (Owner or IAM Admin).

Databricks​

You need these Unity Catalog privileges. Metastore admins and account admins already have them. Workspace admin is not enough on its own.

PrivilegeOnWhy you need it
CREATE STORAGE CREDENTIALMetastoreCreate the credential that wraps the GCP service account.
CREATE EXTERNAL LOCATIONMetastoreCreate the path object.

If you are not a metastore admin, ask one to grant your group:

GRANT CREATE STORAGE CREDENTIAL, CREATE EXTERNAL LOCATION ON METASTORE TO `your-group`;

Create a storage credential​

The storage credential is the Unity Catalog object that holds a Databricks-managed GCP service account. Create it first, because you grant that service account access to the bucket in the next section.

Walkthrough · 3 steps · ~3 min

Create a GCP service account storage credential in Databricks and copy its service account email.

In the Databricks workspace, click Catalog in the left sidebar, then click Create > Create a credential.

Catalog page with the Create menu open and Create a credential highlighted

On Create a new credential, keep Storage Credential selected, set Credential Type to GCP Service Account, give the credential a name (for example starterjourneycred), then click Create.

Create a new credential dialog with Storage Credential and GCP Service Account selected

Databricks generates a service account for the credential. Copy the service account email (it starts with db-uc-credential-) — you grant it access to the bucket next — then click Done.

Credential created dialog showing the service account email to copy

Reference: Create a storage credential (Databricks docs)

Grant the service account access to the bucket​

The service account has no access to the bucket yet. Grant it two roles on the bucket in the Google Cloud console — Storage Legacy Bucket Reader (list the bucket) and Storage Object Admin (read and write objects) — or the connection test at the end fails.

Walkthrough · 7 steps · ~4 min

Grant the credential's service account Storage Legacy Bucket Reader and Storage Object Admin on the GCS bucket.

In the Google Cloud console, open the bucket in Cloud Storage > Buckets, then open its Permissions tab.

GCS bucket details with the Permissions tab

Under Permissions, click Grant access, then paste the service account email you copied from Databricks into New principals.

Bucket Permissions section with the Grant access button

Under Assign roles, open Select a role and choose Storage Legacy Bucket Reader.

Assign roles with the role dropdown open and Storage Legacy Bucket Reader selected

With Storage Legacy Bucket Reader set, click Add another role.

Assign roles showing Storage Legacy Bucket Reader with Add another role

Open the second Select a role dropdown.

Second Select a role dropdown for the additional role

Search for storage and select Storage Object Admin.

Role search showing Storage Object Admin

Confirm the service account is the principal and both Storage Legacy Bucket Reader and Storage Object Admin are assigned, then click Save.

Grant access form with both roles assigned and the Save button

Reference: Connect to GCS external locations (Databricks docs)

Enable file events (optional)​

note

This part is optional. File events let Unity Catalog use bucket notifications (for example, for Auto Loader file notification mode and managed ingestion) instead of listing the bucket. Skip it if you only need to read and write the location. You can add it later.

File events need two grants: a custom Pub/Sub role on the credential's service account (so Databricks can manage the topic and subscription), and the Pub/Sub Publisher role on the project's Cloud Storage service agent (so GCS can publish object notifications).

Walkthrough · 10 steps · ~8 min

Create a custom Pub/Sub role, grant it to the credential service account, and let the Cloud Storage service agent publish notifications.

In the Google Cloud console, search for and open IAM & Admin > IAM.

Google Cloud console search for IAM & Admin

Go to Roles and click Create custom role.

IAM & Admin Roles page with Create custom role

Give the role a title (for example starterjourney-file-events) and ID, then click Add permissions.

Create role page with title, ID, and Add permissions

Add these permissions, click Add, then Create the role:

pubsub.subscriptions.consume
pubsub.subscriptions.create
pubsub.subscriptions.delete
pubsub.subscriptions.get
pubsub.subscriptions.list
pubsub.subscriptions.update
pubsub.topics.attachSubscription
pubsub.topics.detachSubscription
pubsub.topics.create
pubsub.topics.delete
pubsub.topics.get
pubsub.topics.list
pubsub.topics.update
storage.buckets.update
Add permissions dialog with pubsub and storage permissions selected

Back on IAM, click Grant access.

IAM page with Grant access

In New principals, paste the credential's service account email (the db-uc-credential- one). In Assign roles, select the custom role you just created, then click Save.

Grant access panel assigning the custom file-events role to the credential service account

Now find the project's Cloud Storage service agent — a Google-managed account that publishes notifications. See the Google guide, Get the Cloud Storage service agent.

Google docs page describing how to get the Cloud Storage service agent

In Cloud Storage > Settings, copy the Cloud Storage Service Account email.

Cloud Storage Settings page with the Cloud Storage Service Account to copy

Back on IAM, click Grant access again.

IAM page with Grant access for the service agent

Paste the Cloud Storage service agent email into New principals, assign the Pub/Sub Publisher role, then click Save.

Grant access panel assigning Pub/Sub Publisher to the Cloud Storage service agent

Reference: Enable file events (Databricks docs)

Create an external location​

The external location is the Unity Catalog object that points at the GCS bucket path through the storage credential you created.

Walkthrough · 2 steps · ~3 min

Create an external location that points at the GCS path through your storage credential.

In the Databricks workspace, click Catalog, then click Create > Create an external location.

Catalog page with the Create menu open and Create an external location highlighted

Fill in the form:

  • External location name: a descriptive name (for example starterjourneyextloc).
  • Storage type: GCP.
  • URL: the bucket path, gs://<bucket-name>/<directory> (for example gs://starterjourney/unitycatalog).
  • Storage credential: the credential you created earlier.

Click Create.

Create a new external location form with name, GCP storage type, URL, and storage credential

Reference: Create an external location (Databricks docs)

tip

If this location holds source data you only read from, mark it read-only afterward so a stray job cannot overwrite it. Follow Mark an external location as read-only.

Verify​

Test the external location's connection to confirm everything is wired up. A green success status means the service account, its bucket roles, the storage credential, and the external location all line up.

Walkthrough · 4 steps · ~2 min

Test the external location's connection from Unity Catalog and confirm every check passes.

In the Databricks workspace, open Catalog, then click Connect > External locations to open the External Data page.

Catalog page with the Connect menu open and External locations highlighted

On the External Locations tab, click the external location you created.

External Data page listing external locations with the one you created

On the location's Overview tab, click Test connection in the top-right corner.

External location Overview tab with the Test connection button

Confirm the dialog reports a success status for every check (read, list, write, delete, and path), then click Done.

Test connection dialog showing a success status for every check

Reference: Manage external locations (Databricks docs)

Where people trip​

Test connection fails with permission denied

The service account behind the storage credential is missing a role on the bucket. Confirm both Storage Legacy Bucket Reader and Storage Object Admin are granted to the db-uc-credential- service account on the bucket's Permissions tab, then test again.

External location creation fails with invalid URL

The URL has to be gs://<bucket-name>/<directory>. Confirm the bucket exists and the name is spelled correctly.

File events don't fire

File events need both grants: the custom Pub/Sub role on the credential's service account, and Pub/Sub Publisher on the project's Cloud Storage service agent. Re-check the Enable file events grants — the service agent grant is the most common one to miss.

Bonus: Create a GCS bucket​

If you don't already have a GCS bucket, create one here first, then go back to Create a storage credential and point the external location at the new bucket.

Walkthrough · 6 steps · ~5 min

Create a GCS bucket to use as a landing zone or as Unity Catalog storage.

In the Google Cloud console, open Cloud Storage > Buckets and click Create.

Cloud Storage Buckets page with the Create button

Under Get started, enter a globally unique name (for example starterjourney), then continue through the wizard.

Create a bucket Get started step with a bucket name

Review the configuration — Standard storage class, uniform access control, public access prevention on — and click Create.

Create a bucket summary with the Create button

On the Public access will be prevented dialog, keep Enforce public access prevention on this bucket checked and click Confirm.

Public access will be prevented dialog with Confirm

On the new bucket's Objects tab, click Create folder to add a directory for Unity Catalog.

Bucket details Objects tab with Create folder

Name the folder (for example unitycatalog) and click Create. Use gs://<bucket-name>/<folder> as the external location URL.

Create folder dialog with the unitycatalog folder name

Reference: Create a bucket (Google Cloud docs)

Next​