Data Sharing and Snowflake Marketplace · Topic 4 of 10

Outbound Shares, Secure Views and Secure UDFs

Create and maintain outbound shares, choose the right object type to share, know when to use views and secure views, and share logic with secure UDFs.

  • 5 min
In a nutshell
  • A share needs database USAGE, schema USAGE and object grants; add consumers with ALTER SHARE ... ADD ACCOUNTS.
  • New objects are not shared automatically; each needs its own grant.
  • Secure views hide definitions and rows; non secure views are not protection.

What it is

An outbound share is a share that your account owns and that gives other accounts access to objects in your account. Creating one is easy. Maintaining it, and choosing what goes into it, is where an administrator earns the points.

The main decision is the object type. A table exposes everything in it. A secure view exposes only what its query returns and hides its definition. A secure UDF exposes a calculation without exposing the code.

Base tablesprivatewrapped bySecure view or secure UDFhides logic and rowsgranted toShareUSAGE and SELECTseen byConsumerresult only

How it works

Create and maintain outbound shares

CREATE SHARE finance_share;
GRANT USAGE ON DATABASE fin TO SHARE finance_share;
GRANT USAGE ON SCHEMA fin.reporting TO SHARE finance_share;
GRANT SELECT ON ALL TABLES IN SCHEMA fin.reporting TO SHARE finance_share;
ALTER SHARE finance_share ADD ACCOUNTS = myorg.partner_a, myorg.partner_b;

Maintenance tasks:

TaskHow
Check contentsSHOW GRANTS TO SHARE finance_share
Check consumersSHOW GRANTS OF SHARE finance_share
Add a new tableGrant SELECT on it to the share
Remove an objectREVOKE SELECT ON ... FROM SHARE ...
Remove a consumerALTER SHARE ... REMOVE ACCOUNTS
Add a commentALTER SHARE ... SET COMMENT

Rules:

  • A share includes a database USAGE grant, a schema USAGE grant and object grants. Without the first two, nothing is visible.
  • GRANT SELECT ON ALL TABLES IN SCHEMA covers the tables that exist now. A table created later needs its own grant to the share.
  • Dropping or recreating a shared object breaks access. Recreate it, then grant it again.
  • A secure view that reads another database in the same account needs GRANT REFERENCE_USAGE ON DATABASE other_db TO SHARE finance_share.
  • Use a database role in the share to segment access: the consumer grants each shared database role to its own roles. Database roles cannot span several databases.
Exam tip

To retire a consumer quickly, remove the account from the share. Their access ends at once, with no change in their account.

Sharing objects securely: which type

NeedShare thisWhy
Whole table, no sensitive columnsTableSimplest
Hide columns or filter rowsSecure viewDefinition hidden, rows controlled
Join several tables before sharingSecure viewOne exposed object
Precomputed result that must be fastSecure materialized viewNeeds Enterprise Edition or higher
Hide a calculationSecure UDFCode stays private
Policies on the provider sideSecure view over the protected tableMasking and row access policies protect your table; the view exposes the result

For data that must stay private, expose it only through a secure view. Non secure views can also be shared today, but their definition is visible and the optimizer may behave in ways that leak data, so they are not protection.

Use cases for views and secure views

ViewSecure view
Definition visible to consumerYesNo
Optimizer shortcuts that may expose dataPossibleDisabled
PerformanceBestSlightly lower, since some optimizations are skipped
Use in a shareAllowedRecommended
Use for row level filtering by accountNoYes, with CURRENT_ACCOUNT()

Use a plain view for internal convenience. Use a secure view for sharing, for hiding columns, and for row level security. Define one with CREATE SECURE VIEW, or convert with ALTER VIEW ... SET SECURE.

CREATE SECURE VIEW fin.reporting.v_revenue AS
SELECT region, month, revenue
FROM fin.core.revenue r
JOIN fin.core.account_map m ON r.region = m.region
WHERE m.snowflake_account = CURRENT_ACCOUNT();
Table fin.core.revenueall regionsjoined withMapping tableaccount to regionfiltersSecure viewby CURRENT_ACCOUNTinShareeach partner sees its region

Because the secure view reads the table in another schema of the same database, the share needs USAGE on the schema of the view only. If the table were in a different database, it would also need REFERENCE_USAGE on that database.

Share data with secure UDFs

A secure UDF is a function that hides its definition and runs with the same protections as a secure view. Use one to share a calculation, a scoring routine or a lookup logic.

CREATE SECURE FUNCTION fin.reporting.risk_score(amount NUMBER, region STRING)
RETURNS NUMBER
AS $$ amount * IFF(region = 'EU', 0.8, 1.1) $$;

GRANT USAGE ON FUNCTION fin.reporting.risk_score(NUMBER, STRING) TO SHARE finance_share;

Notes:

  • The grant is USAGE on the function with its argument types, not SELECT.
  • The consumer calls it as partner_db.reporting.risk_score(...).
  • A secure UDF that reads tables must read tables the share can reach, which means the schema and, for other databases, REFERENCE_USAGE.
  • Consumers cannot see the body of a secure UDF through DESCRIBE or GET_DDL.
Watch out

A normal UDF shown in a share exposes its code. Always create SECURE functions for sharing.

Common mistakes

Sharing the base table when only part of it is meant for consumers. Use a secure view.

Missing REFERENCE_USAGE. A secure view over another database fails for consumers without it.

Granting SELECT on a function. The function grant is USAGE.

What to remember for the exam

  • A share needs database USAGE, schema USAGE and object grants; add consumers with ALTER SHARE ... ADD ACCOUNTS.
  • New objects are not shared automatically; each needs its own grant.
  • Secure views hide definitions and rows; non secure views are not protection.
  • Secure UDFs are shared with GRANT USAGE ON FUNCTION.
  • REFERENCE_USAGE connects a secure view to another database; database roles segment access inside one database.

Check yourself

  • A table was added to a shared schema last week and the consumer cannot see it. Why?

    Objects are not shared automatically; the table needs its own SELECT grant to the share.

  • What does a secure view hide that a plain view does not?

    Its definition, and it also blocks optimizations that might expose data.

  • Which privilege shares a secure UDF?

    USAGE on the function, granted to the share.

Topic 4 of 10 in Data Sharing and Snowflake Marketplace

Test yourself on Data Sharing and Snowflake Marketplace

The full Snowflake ADA-C02 question bank has 814 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by Snowflake. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.