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
- A share needs database
USAGE, schemaUSAGEand object grants; add consumers withALTER 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.
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:
| Task | How |
|---|---|
| Check contents | SHOW GRANTS TO SHARE finance_share |
| Check consumers | SHOW GRANTS OF SHARE finance_share |
| Add a new table | Grant SELECT on it to the share |
| Remove an object | REVOKE SELECT ON ... FROM SHARE ... |
| Remove a consumer | ALTER SHARE ... REMOVE ACCOUNTS |
| Add a comment | ALTER SHARE ... SET COMMENT |
Rules:
- A share includes a database
USAGEgrant, a schemaUSAGEgrant and object grants. Without the first two, nothing is visible. GRANT SELECT ON ALL TABLES IN SCHEMAcovers 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.
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
| Need | Share this | Why |
|---|---|---|
| Whole table, no sensitive columns | Table | Simplest |
| Hide columns or filter rows | Secure view | Definition hidden, rows controlled |
| Join several tables before sharing | Secure view | One exposed object |
| Precomputed result that must be fast | Secure materialized view | Needs Enterprise Edition or higher |
| Hide a calculation | Secure UDF | Code stays private |
| Policies on the provider side | Secure view over the protected table | Masking 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
| View | Secure view | |
|---|---|---|
| Definition visible to consumer | Yes | No |
| Optimizer shortcuts that may expose data | Possible | Disabled |
| Performance | Best | Slightly lower, since some optimizations are skipped |
| Use in a share | Allowed | Recommended |
| Use for row level filtering by account | No | Yes, 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();
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
USAGEon the function with its argument types, notSELECT. - 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
DESCRIBEorGET_DDL.
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, schemaUSAGEand object grants; add consumers withALTER 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_USAGEconnects 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
SELECTgrant 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?
USAGEon 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.