<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Accessing secret scope keys from Unity Catalog SQL UDFs without granting users READ permission in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/accessing-secret-scope-keys-from-unity-catalog-sql-udfs-without/m-p/177591#M57332</link>
    <description>&lt;OL&gt;
&lt;LI&gt;
&lt;P&gt;Is this expected? Yes. The SQL secret() function reads from a workspace secret scope and checks the querying user's READ permission on that scope, even inside a mask or ABAC function owned by someone else. So it can't keep the key hidden from users who query the table.&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;Supported approach: use a Unity Catalog secret in a UC Python UDF that declares it in the SECRETS clause. The UDF reads the secret with the function owner's permissions. Callers only need EXECUTE, with no privilege on the secret (docs).&lt;/P&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;PRE&gt;&lt;CODE&gt;      CREATE OR REPLACE FUNCTION gov.masking.hmac_mask(value STRING)
      RETURNS STRING
      LANGUAGE PYTHON
      DETERMINISTIC
      SECRETS (gov.masking_keys.hmac_key)
      ENVIRONMENT (environment_version = '6')
      AS $$
      import hashlib, hmac
      from databricks.secrets import get
      key = get(catalog="gov", schema="masking_keys", key="hmac_key")
      return None if value is None else hmac.new(key.encode(), value.encode(), hashlib.sha256).hexdigest()
      $$;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Wrap this in a SQL function and use it as your ABAC column-mask function.&lt;/P&gt;
&lt;P&gt;Notes:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;environment_version must be 6 or higher.&lt;/LI&gt;
&lt;LI&gt;Supported compute: serverless, pro or serverless SQL warehouses, or DBR 19+ in standard access mode.&lt;/LI&gt;
&lt;LI&gt;The function owner needs READ SECRET. Masked users don't.&lt;/LI&gt;
&lt;LI&gt;Never return the key from the UDF.&lt;/LI&gt;
&lt;/UL&gt;
&lt;OL start="3"&gt;
&lt;LI&gt;UC Secrets vs. External Secrets: both work through the SECRETS clause. External (Azure Key Vault-backed) UC secrets only change where the value is stored and rotated, not the permission model. Workspace secret scopes used with secret(), including Key Vault-backed scopes, still require READ for every caller.&lt;/LI&gt;
&lt;/OL&gt;</description>
    <pubDate>Wed, 25 Nov 2026 15:14:36 GMT</pubDate>
    <dc:creator>Kashif_Inamdar</dc:creator>
    <dc:date>2026-11-25T15:14:36Z</dc:date>
    <item>
      <title>Accessing secret scope keys from Unity Catalog SQL UDFs without granting users READ permission</title>
      <link>https://community.databricks.com/t5/data-engineering/accessing-secret-scope-keys-from-unity-catalog-sql-udfs-without/m-p/177582#M57331</link>
      <description>&lt;P&gt;&lt;SPAN&gt;We are implementing a dynamic data masking solution on Azure Databricks using Unity Catalog ABAC policies and SQL UDFs for deterministic masking.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Our masking functions retrieve a secret key from a Databricks-backed secret scope using the &lt;/SPAN&gt;&lt;SPAN&gt;secret()&lt;/SPAN&gt;&lt;SPAN&gt; function.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The issue is that when users query a masked table, they appear to require READ permission on the secret scope, even though they are not the owners of the masking UDF.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Granting users READ permission defeats our security objective, as users who should only see masked data would also be able to retrieve the masking key.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;My questions are:&lt;/SPAN&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;&lt;SPAN&gt;Is this the expected behavior of &lt;/SPAN&gt;&lt;SPAN&gt;secret()&lt;/SPAN&gt;&lt;SPAN&gt; within Unity Catalog SQL UDFs?&lt;/SPAN&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;SPAN&gt;Is there a supported way for a masking UDF to access a secret without granting the querying user direct access to it?&lt;/SPAN&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;SPAN&gt;Would Unity Catalog Secrets or Unity Catalog External Secrets address this limitation?&lt;/SPAN&gt;&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;SPAN&gt;Has anyone encountered a similar issue or found a recommended solution?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Any guidance would be greatly appreciated. Thanks!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Nov 2026 14:28:08 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/accessing-secret-scope-keys-from-unity-catalog-sql-udfs-without/m-p/177582#M57331</guid>
      <dc:creator>pxs132</dc:creator>
      <dc:date>2026-11-25T14:28:08Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing secret scope keys from Unity Catalog SQL UDFs without granting users READ permission</title>
      <link>https://community.databricks.com/t5/data-engineering/accessing-secret-scope-keys-from-unity-catalog-sql-udfs-without/m-p/177591#M57332</link>
      <description>&lt;OL&gt;
&lt;LI&gt;
&lt;P&gt;Is this expected? Yes. The SQL secret() function reads from a workspace secret scope and checks the querying user's READ permission on that scope, even inside a mask or ABAC function owned by someone else. So it can't keep the key hidden from users who query the table.&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;Supported approach: use a Unity Catalog secret in a UC Python UDF that declares it in the SECRETS clause. The UDF reads the secret with the function owner's permissions. Callers only need EXECUTE, with no privilege on the secret (docs).&lt;/P&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;PRE&gt;&lt;CODE&gt;      CREATE OR REPLACE FUNCTION gov.masking.hmac_mask(value STRING)
      RETURNS STRING
      LANGUAGE PYTHON
      DETERMINISTIC
      SECRETS (gov.masking_keys.hmac_key)
      ENVIRONMENT (environment_version = '6')
      AS $$
      import hashlib, hmac
      from databricks.secrets import get
      key = get(catalog="gov", schema="masking_keys", key="hmac_key")
      return None if value is None else hmac.new(key.encode(), value.encode(), hashlib.sha256).hexdigest()
      $$;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Wrap this in a SQL function and use it as your ABAC column-mask function.&lt;/P&gt;
&lt;P&gt;Notes:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;environment_version must be 6 or higher.&lt;/LI&gt;
&lt;LI&gt;Supported compute: serverless, pro or serverless SQL warehouses, or DBR 19+ in standard access mode.&lt;/LI&gt;
&lt;LI&gt;The function owner needs READ SECRET. Masked users don't.&lt;/LI&gt;
&lt;LI&gt;Never return the key from the UDF.&lt;/LI&gt;
&lt;/UL&gt;
&lt;OL start="3"&gt;
&lt;LI&gt;UC Secrets vs. External Secrets: both work through the SECRETS clause. External (Azure Key Vault-backed) UC secrets only change where the value is stored and rotated, not the permission model. Workspace secret scopes used with secret(), including Key Vault-backed scopes, still require READ for every caller.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Wed, 25 Nov 2026 15:14:36 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/accessing-secret-scope-keys-from-unity-catalog-sql-udfs-without/m-p/177591#M57332</guid>
      <dc:creator>Kashif_Inamdar</dc:creator>
      <dc:date>2026-11-25T15:14:36Z</dc:date>
    </item>
  </channel>
</rss>

