如何查看Snowflake中已应用的用户级网络策略及用户关联关系?
Absolutely! Snowflake has you covered with built-in system views that make it easy to track which user-level network policies are applied to which users, plus view all existing policies. Here's how to pull that information:
To see every network policy attached to a user, along with key details about the policy and user, run this query:
SELECT np.POLICY_NAME, np.POLICY_TYPE, pr.REFERENCE_ENTITY_NAME AS ASSIGNED_USER, pr.REFERENCE_ENTITY_TYPE AS ENTITY_TYPE, np.CREATED_ON, np.LAST_ALTERED FROM ACCOUNT_USAGE.NETWORK_POLICIES np JOIN ACCOUNT_USAGE.POLICY_REFERENCES pr ON np.POLICY_ID = pr.POLICY_ID WHERE pr.REFERENCE_ENTITY_TYPE = 'USER' ORDER BY np.POLICY_NAME, ASSIGNED_USER;
What this does:
- Joins
ACCOUNT_USAGE.NETWORK_POLICIES(stores all network policy metadata) withACCOUNT_USAGE.POLICY_REFERENCES(tracks which entities policies are linked to) - Filters for only user-level assignments (excludes roles, warehouses, etc.)
- Returns the policy name, type, assigned user, and timestamps for policy creation/modification
If you only care about one user's applied network policies, tweak the query to target their username:
SELECT np.POLICY_NAME, np.ALLOWED_IP_LIST, np.BLOCKED_IP_LIST, np.CREATED_ON FROM ACCOUNT_USAGE.NETWORK_POLICIES np JOIN ACCOUNT_USAGE.POLICY_REFERENCES pr ON np.POLICY_ID = pr.POLICY_ID WHERE pr.REFERENCE_ENTITY_NAME = 'YOUR_TARGET_USER' -- Replace with actual username AND pr.REFERENCE_ENTITY_TYPE = 'USER';
This will show you the exact IP rules (allowed/blocked) tied to that user's policies.
If you want a full list of every network policy in your account—even those not yet attached to any user—use this simpler query:
SELECT POLICY_NAME, POLICY_TYPE, ALLOWED_IP_LIST, BLOCKED_IP_LIST, CREATED_ON, LAST_ALTERED FROM ACCOUNT_USAGE.NETWORK_POLICIES ORDER BY CREATED_ON DESC;
Important Note on Permissions
To access these ACCOUNT_USAGE views, you'll need either the ACCOUNTADMIN role, or have been granted the MONITOR USAGE privilege by an account admin. If you get permission errors, reach out to your Snowflake account administrator for access.
内容的提问来源于stack exchange,提问作者RJ E2

