Storage Credentials and External Locations
Earn 25 points (50 with Pro) in two steps
- ① Read through the lesson — each section gets a ✓ as you scroll through it.
- ② When every section has a ✓, tap Complete lesson.
0 of 10 read · keep scrolling
✦ See fewer ads and earn double points — 50 a lesson instead of 25 — with Pro
Mastering Data Access Control: Storage Credentials and External Locations in Unity Catalog
Introduction: The Foundation of Secure Data Governance
In the evolving landscape of data engineering and analytics, the ability to manage data securely is no longer an optional feature—it is a fundamental requirement. Unity Catalog serves as the centralized governance layer for data and AI assets within the Databricks ecosystem. At the heart of this governance model lies a critical question: How do we allow compute clusters to read from or write to cloud object storage (like AWS S3, Azure Data Lake Storage, or Google Cloud Storage) without exposing long-lived, high-privilege credentials to end users?
The answer lies in the strategic use of Storage Credentials and External Locations. These two constructs decouple the physical storage layer from the logical data access layer. By implementing these, you move away from the dangerous practice of hardcoding access keys or environment variables in notebooks and jobs. Instead, you create a controlled, audited, and managed bridge between your storage accounts and your Databricks workspace. Understanding these concepts is vital for any data architect or platform engineer because they represent the primary defense mechanism against unauthorized data exposure and accidental misconfiguration.
This lesson explores how to design, implement, and manage these assets, ensuring that your organization can scale its data footprint while maintaining rigorous security standards.
Not read yet
Understanding the Architecture of Storage Credentials
A Storage Credential in Unity Catalog is a secure, reusable object that holds the identity information needed to access your cloud storage provider. Think of it as a "passport" that you issue to your Databricks workspace, allowing it to act on behalf of a specific service principal or managed identity. When you define a storage credential, you are essentially telling Unity Catalog, "If you need to talk to this specific cloud account, use these specific permissions."
Why Decouple Credentials from Data?
In older, non-governed data environments, users often had to manage their own cloud access keys. This led to several issues, including "credential sprawl," where keys were copied into notebooks, stored in version control systems, or shared via messaging apps. If a user left the company, those keys often remained active, creating significant security vulnerabilities.
By using Unity Catalog Storage Credentials, the administration of access is shifted to the platform level. You grant the storage credential the necessary permissions in your cloud provider (e.g., IAM roles in AWS or Managed Identities in Azure), and then you grant Unity Catalog users permission to use that credential. The users themselves never see the secret keys, and they cannot export them to other environments.
Callout: Identity vs. Access It is important to distinguish between the identity of the person running the query and the identity of the storage credential. When a user runs a query against an external table, Unity Catalog uses the Storage Credential to authenticate with the cloud provider, but it uses the User's Identity to check if they have the
READorWRITEprivilege on the specific catalog, schema, or table. This dual-layer check ensures that even if you have access to the storage, you cannot bypass the governance policies defined in Unity Catalog.
Not read yet
External Locations: The Controlled Gateway
While a Storage Credential defines how to authenticate, an External Location defines where you are allowed to go. An External Location is a Unity Catalog object that maps a specific path in your cloud storage (e.g., s3://my-data-bucket/finance/) to a Storage Credential.
Without an External Location, your data is essentially "dark" to Unity Catalog. You might have the credentials to access an S3 bucket, but Unity Catalog will prevent any interaction with that bucket unless an External Location has been explicitly registered. This prevents users from accidentally or intentionally using their access to read or write data in unauthorized areas of your cloud storage.
The Lifecycle of an External Location
- Storage Setup: You create the bucket or container in your cloud provider and configure the necessary IAM roles or policies.
- Credential Creation: You create a Storage Credential in Unity Catalog that references the cloud identity (the IAM role or Managed Identity).
- Location Registration: You define an External Location that points to the specific storage path and associates it with the Storage Credential.
- Granting Access: You grant specific users or groups
READorWRITEpermissions on that External Location.
This tiered approach allows for "least privilege" access. You can grant a data scientist READ access to an external location containing raw data, while restricting WRITE access to a different location where they can save their processed results.
Not read yet
Practical Implementation: Step-by-Step Guide
To implement these features, you must have the appropriate administrative privileges in both Databricks (Metastore Admin) and your cloud provider (e.g., Cloud Administrator).
Step 1: Configuring the Cloud Identity
Before touching Databricks, you must ensure the cloud provider trusts Databricks. For AWS, this involves creating an IAM role with a trust policy that allows the Databricks cross-account role to assume it. For Azure, this involves creating a User-Assigned Managed Identity and granting it the "Storage Blob Data Contributor" role on your storage account.
Step 2: Creating the Storage Credential
Once the cloud identity is ready, you can create the Storage Credential using SQL or the Databricks UI.
-- Create a storage credential using an AWS IAM Role
CREATE STORAGE CREDENTIAL my_aws_credential
WITH IAM_ROLE 'arn:aws:iam::123456789012:role/my-databricks-access-role';
After executing this command, the credential object exists in your metastore. It is currently empty of permissions, meaning no one can use it yet.
Step 3: Creating the External Location
Now, map a specific storage path to that credential.
CREATE EXTERNAL LOCATION my_finance_data
URL 's3://my-company-data-bucket/finance/'
WITH (CREDENTIAL my_aws_credential);
Note: The URL must be the exact path to the directory. If you provide a path like
s3://my-company-data-bucket/finance/2023/, you will only be able to create external tables within that specific sub-directory. It is best practice to define locations at a high enough level to be useful, but narrow enough to enforce security boundaries.
Step 4: Granting Permissions
Finally, enable users to use this location.
GRANT READ, WRITE ON EXTERNAL LOCATION my_finance_data TO `data_engineers_group`;
Not read yet
Comparing Access Methods
It is helpful to compare the modern Unity Catalog approach with legacy methods to understand the improvement in security posture.
| Feature | Legacy Access (Access Keys) | Unity Catalog (External Locations) |
|---|---|---|
| Credential Management | Manual (Notebooks/Env Vars) | Managed by Metastore |
| Visibility | Credentials visible to users | Credentials hidden from users |
| Auditability | Difficult to track usage | Full audit logs in System Tables |
| Granularity | All or nothing per bucket | Path-level control |
| Lifecycle | Static keys, hard to rotate | Dynamic, managed by IAM/Managed ID |
Best Practices for Secure Governance
Implementing Storage Credentials and External Locations is not a "set it and forget it" task. To maintain a secure environment, consider the following industry standards.
1. Principle of Least Privilege
Do not create a single "master" storage credential that has access to every bucket in your organization. If that credential is compromised, your entire data estate is at risk. Instead, create specific credentials for specific business units or projects (e.g., hr_storage_cred, marketing_storage_cred).
2. Use Managed Identities
Whenever possible, use cloud-native identities like Azure Managed Identities or AWS IAM Roles for Service Accounts. These provide temporary, short-lived security tokens. Avoid static access keys at all costs. Static keys are permanent and difficult to revoke without breaking existing pipelines.
3. Regular Audits
Unity Catalog provides system tables that track every access request. Regularly query these tables to identify unusual access patterns. For example, if a user is trying to access an external location they don't have permission for, that will show up in the audit logs.
-- Example: Querying audit logs for access denials
SELECT event_time, user_identity, action_type, result
FROM system.access.audit
WHERE action_type = 'ACCESS_EXTERNAL_LOCATION'
AND result = 'DENIED';
4. Separate Environments
Maintain distinct External Locations for dev, test, and prod environments. Never point a production notebook to a development storage path, and vice versa. This prevents the accidental corruption of production data by experimental code.
5. Leverage Managed Tables
While External Locations are excellent for data that must reside in your own cloud buckets, try to use Managed Tables whenever possible. Managed tables are stored in the Unity Catalog-managed storage location. Because Unity Catalog manages the storage entirely, you do not need to worry about External Locations or Storage Credentials for these tables—the catalog handles the security automatically.
Not read yet
Common Pitfalls and Troubleshooting
Even with a well-designed architecture, issues can arise. Understanding these common traps will save you significant debugging time.
The "Permission Denied" Paradox
A user might have the READ permission on an External Location, yet still receive a "Permission Denied" error when trying to read a file. This is often caused by a mismatch between the Unity Catalog permission and the underlying Cloud IAM permission.
- The Fix: Ensure the IAM role associated with the Storage Credential actually has the
s3:GetObjectorBlob Storage Data Readerpermission on the specific bucket path. Unity Catalog cannot grant permissions that the underlying cloud identity does not possess.
The "Over-Broad" Location
If you define an external location as s3://my-bucket/, users can access any file within that entire bucket. If you have sensitive data in s3://my-bucket/hr/ and general data in s3://my-bucket/public/, you have created a security hole.
- The Fix: Always define external locations at the most granular level possible. If you need to expose different parts of the bucket to different teams, create multiple External Locations with different credentials or different access grants.
Hardcoding Paths in Code
A common mistake is hardcoding the full URI (e.g., s3://my-bucket/data/table) in Spark code. This makes your code brittle.
- The Fix: Use table names managed by the catalog. If you must use external files, use the External Location name as a reference, or better yet, define an External Table on top of the location. This allows you to change the underlying storage path in the future without updating every notebook in your organization.
Warning: Deleting Credentials Be extremely cautious when deleting a Storage Credential. If you drop a credential that is currently being used by active External Locations or tables, those assets will immediately become inaccessible. Always check for dependencies before running a
DROP STORAGE CREDENTIALcommand.
Not read yet
Advanced Management: Automating with Infrastructure as Code
As your organization grows, manually creating storage credentials and locations becomes unsustainable. You should treat these objects as part of your infrastructure code. By using tools like Terraform or the Databricks CLI, you can ensure that your governance setup is reproducible, version-controlled, and tested.
Example Terraform Snippet
resource "databricks_storage_credential" "external" {
name = "prod_storage_credential"
aws_iam_role {
role_arn = "arn:aws:iam::123456789012:role/databricks-access"
}
}
resource "databricks_external_location" "finance" {
name = "finance_location"
url = "s3://my-company-data/finance/"
credential_name = databricks_storage_credential.external.id
comment = "Finance department data location"
}
Using Infrastructure as Code (IaC) provides a clear audit trail of who created a location, why it was created, and what permissions were associated with it. It also prevents "configuration drift," where settings are changed manually in the UI and eventually diverge from the intended security baseline.
Not read yet
Deep Dive: How Unity Catalog Validates Access
It is worth understanding the internal handshake that occurs when a query is executed. When a user runs SELECT * FROM external_table, the following process happens:
- Authorization Check: Unity Catalog checks if the user has
SELECTpermission on the table object in the metastore. - Path Resolution: The metastore resolves the table's location to an External Location object.
- Identity Impersonation: Unity Catalog identifies the Storage Credential associated with that External Location.
- Credential Exchange: Unity Catalog requests a short-lived security token from the cloud provider using the identity defined in the Storage Credential.
- Data Access: The compute cluster receives this temporary token, allowing it to perform the specific requested operation on the cloud storage.
This flow is why Unity Catalog is so effective: the user's identity is used for the logic governance, while the system's identity is used for the storage access. The user never holds the keys, and the keys are never exposed to the compute environment longer than necessary.
Not read yet
Frequently Asked Questions (FAQ)
Q: Can I use the same Storage Credential for multiple External Locations?
A: Yes, absolutely. You can define one Storage Credential (e.g., main_data_lake_access) and use it across dozens of External Locations. This is a common pattern when multiple buckets are managed by the same IAM role.
Q: What happens if I update the IAM role policy in AWS? A: Unity Catalog does not automatically know that the underlying IAM policy has changed. If you restrict permissions in AWS, Unity Catalog will fail to access the data. You do not need to update the Storage Credential object in Databricks, but you must ensure the cloud-side permissions align with the expectations of the External Locations.
Q: Is it possible to restrict access by IP address? A: Yes, you can combine Unity Catalog's access control with Cloud-native network policies (like VPC endpoints or S3 bucket policies that restrict access to specific IP ranges). While Unity Catalog handles the identity layer, your cloud provider handles the network layer. A robust strategy uses both.
Q: How do I migrate existing data to Unity Catalog?
A: You don't necessarily need to move the data. You can simply define an External Location pointing to your existing bucket and then create an EXTERNAL TABLE pointing to the files in that location. This allows you to bring existing data under governance without the overhead of re-copying terabytes of information.
Not read yet
Summary and Key Takeaways
Implementing Storage Credentials and External Locations is the single most effective way to secure data access in Databricks. By mastering these concepts, you transition your organization from a fragile, manual security model to a robust, automated, and audited governance framework.
Key Takeaways
- Decoupling is Mandatory: Never use hardcoded keys. Separate your compute identity (the storage credential) from your logical data structure (the external location).
- Least Privilege: Always define External Locations as specifically as possible to prevent unauthorized browsing of your cloud storage.
- Governance Layers: Understand that Unity Catalog performs two checks: one for the user's rights to the object, and one for the system's rights to the underlying storage. Both must pass for access to be granted.
- Auditability: Use the system tables to monitor access patterns. If you aren't looking at your logs, you aren't really governing your data.
- Use Infrastructure as Code: Treat your storage credentials and external locations as software. Use Terraform or similar tools to manage their lifecycle and ensure consistency across environments.
- Managed Tables vs. External: Prefer Managed Tables for internal data to let Unity Catalog handle the security entirely. Use External Locations only when you have a specific requirement to point to existing, externally managed storage.
- Lifecycle Management: Regularly review your storage credentials and external locations. If a project is decommissioned, remove the associated credentials and locations to reduce the attack surface of your data lake.
By following these principles, you ensure that your data platform remains secure, compliant, and ready to scale. Governance is a journey, not a destination, and these tools are the foundation upon which that journey is built.
Not read yet
Each section gets a ✓ as you scroll through it. Tap the button to jump to the next one.
- VNet Injection and Private Link
- VNet Injection and Private Link Quiz5q
- Access Control and Authentication
- Access Control and Authentication Quiz5q
- Secret Management with Azure Key Vault
- Secret Management with Azure Key Vault Quiz5q
- Workspace Administration Best Practices
- Workspace Administration Best Practices Quiz5q
- Exam Domain Review
- Exam Domain Review Quiz5q
- Azure Databricks Best Practices
- Best Practices Quiz5q
- Troubleshooting Databricks Issues
- Troubleshooting Quiz5q
- Cost Optimization Strategies
- Cost Optimization Quiz5q
- DP-750 Practice Exam
- DP-750 Practice Exam Quiz5q
- Databricks SQL Warehouses
- SQL Warehouses Quiz5q
- Lakehouse Architecture Concepts
- Lakehouse Architecture Quiz5q
- Final Comprehensive Review
- Final Comprehensive Quiz5q
Spend your points to unlock exam-style practice questions
Spend points to unlock DP-750 exam-style practice questions.
Practice for DP-750