Snowflake SQL Tutorial 164 - Snowflake Refused To Drop This One, And In Episode 157 It Did Not

Snowflake SQL · Episode 164

In this post we are going to cover network policies and network rules in Snowflake.

A network policy is a named object that holds a list of IP addresses. When it is applied to an account or to a user, it decides which addresses are allowed to reach that account. A network rule is a separate object that holds a list of values, and a policy can be built out of rules instead of out of addresses.

We will start by looking at what is already on the account, then create a policy, read it back two different ways, and build it up step by step.

One thing to say before anything else. Nothing on this page is ever applied to anything. Every policy here is created, read and dropped, and not one of them is attached to the account or to a user. A network policy decides who can reach the account, and the only account here is the one these queries were run on. Two questions below end with “I do not know” because of that, and saying so is better than finding out the hard way on a live account.

Every address used below comes from a range reserved for documentation, so no real network is named anywhere.

Episode 164 of the Snowflake SQL: Zero to Hero series on TechBrothersIT.

Let's see what is on this account before we start

There is no sample table in this post. The objects we are about to make are account-level objects, so the first thing worth knowing is what is already there.

Let's ask for every network policy on the account.

Query
SHOW NETWORK POLICIES;
Result0 rows · 7 columns · scroll →
created_onnamecommententries_in_allowed_ip_listentries_in_blocked_ip_listentries_in_allowed_network_rulesentries_in_blocked_network_rules

Column headings and nothing underneath. The count says the same thing in one cell.

Query
SELECT COUNT(*) AS POLICIES_ALREADY_HERE
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 1 column
POLICIES_ALREADY_HERE
0

Now the same question about network rules.

Query
SHOW NETWORK RULES;
Result0 rows · 10 columns · scroll →
created_onnamedatabase_nameschema_nameownercommenttypemodeentries_in_valuelistowner_role_type
Query
SELECT COUNT(*) AS RULES_ALREADY_HERE
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 1 column
RULES_ALREADY_HERE
0

So everything we see from here on is ours. Nothing on this account was restricting who could reach it.

And the parameter that decides whether a policy is in force

A policy only does anything once it is applied, and what it is applied to is a parameter called NETWORK_POLICY. Let's read it on the account.

Query
SHOW PARAMETERS LIKE 'NETWORK_POLICY' IN ACCOUNT;
Result1 row · 6 columns · scroll →
keyvaluedefaultleveldescriptiontype
NETWORK_POLICYNetwork policy assigned for the given target.STRING

One row. The value cell is empty, which means no policy is in force. Let's read the same row back with the columns we care about.

Query
SELECT "key", "value", "default", "level", "description"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 5 columns
keyvaluedefaultleveldescription
NETWORK_POLICYNetwork policy assigned for the given target.

The same parameter can be set on a single user as well. The statement for that names a user, so the name below stands in for the real one.

Query
-- The same question asked about one user instead of the account.
-- The real statement names a user, so the name below stands in for it.
SHOW PARAMETERS LIKE 'NETWORK_POLICY' IN USER YOUR_USER_NAME;
Result1 row · 4 columns
keyvaluedefaultlevel
NETWORK_POLICY

Empty there too. Nothing is restricting this account at the account level or at the user level, and that is how it stays all the way through.

The one rule for this episode

Do not apply a policy you have just written to the account you are working from. If the list is wrong, the thing you have locked out is yourself. Create it, read it, and test it against an account you can afford to lose access to.

Let's create our first network policy

The smallest useful policy is a name and one allowed range.

Query
CREATE OR REPLACE NETWORK POLICY NP_T164
  ALLOWED_IP_LIST = ('192.0.2.0/24')
  COMMENT = 'episode 164 - created, read, dropped, and NEVER APPLIED to anything';
Result1 row · 1 column
status
Network policy NP_T164 is created.

Created. Now let's find it in the catalogue.

Query
SHOW NETWORK POLICIES LIKE 'NP\\_T164';
Result1 row · 7 columns · scroll →
created_onnamecommententries_in_allowed_ip_listentries_in_blocked_ip_listentries_in_allowed_network_rulesentries_in_blocked_network_rules
2026-10-06 12:21:59.705000-07:00NP_T164episode 164 - created, read, dropped, and NEVER APPLIED to anything1000

One row, and four of its columns are counts. entries_in_allowed_ip_list reads 1 and the other three read 0.

Query
SELECT "name", "comment", "entries_in_allowed_ip_list",
       "entries_in_blocked_ip_list", "created_on"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 5 columns
namecommententries_in_allowed_ip_listentries_in_blocked_ip_listcreated_on
NP_T164episode 164 - created, read, dropped, and NEVER APPLIED to anything102026-10-06 12:21:59.705000-07:00

Now let's ask DESCRIBE the same question

SHOW gave us counts. DESCRIBE gives us contents, and that is a different answer to the same question.

Query
DESCRIBE NETWORK POLICY NP_T164;
Result1 row · 2 columns
namevalue
ALLOWED_IP_LIST192.0.2.0/24

One row with two columns, a property name and its value. This is where the address itself lives.

Query
SELECT COUNT(*) AS DESCRIBE_ROWS
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 1 column
DESCRIBE_ROWS
1

So keep both in mind. SHOW NETWORK POLICIES tells you how many entries a policy has. DESCRIBE NETWORK POLICY tells you what they are. Neither one is the full picture on its own.

Now let's see what the IP list will take

The first policy used a range written with a CIDR suffix. Let's try a single address with nothing after it.

Query
CREATE OR REPLACE NETWORK POLICY NPONE_T164
  ALLOWED_IP_LIST = ('203.0.113.7');
Result1 row · 1 column
status
Network policy NPONE_T164 is created.

Accepted. And here is what it stored.

Query
DESCRIBE NETWORK POLICY NPONE_T164;
Result1 row · 2 columns
namevalue
ALLOWED_IP_LIST203.0.113.7

Exactly what we typed. Snowflake did not add a /32 on our behalf, and it did not rewrite the value at all.

Now several ranges at once

An allowed list can hold more than one entry. Let's give it three and watch the counts.

Query
CREATE OR REPLACE NETWORK POLICY NPMANY_T164
  ALLOWED_IP_LIST = ('192.0.2.0/24', '198.51.100.0/24', '203.0.113.0/24');
Result1 row · 1 column
status
Network policy NPMANY_T164 is created.
Query
SELECT "name", "entries_in_allowed_ip_list", "entries_in_blocked_ip_list"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 3 columns
nameentries_in_allowed_ip_listentries_in_blocked_ip_list
NPMANY_T16430

entries_in_allowed_ip_list reads 3, so SHOW is counting the ranges one by one.

Now the same policy through DESCRIBE.

Query
SELECT "name", "value"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 2 columns
namevalue
ALLOWED_IP_LIST192.0.2.0/24,198.51.100.0/24,203.0.113.0/24

Still one row. All three ranges came back inside a single comma-separated value.

Two pictures of one object

So SHOW counts and DESCRIBE concatenates. If you are writing something that reads these entries back, that difference decides which statement you want and how much string work you have to do afterwards.

What happens when the value is not an IPv4 address?

Let's try something that is not an address at all.

Query
CREATE OR REPLACE NETWORK POLICY NPBAD_T164
  ALLOWED_IP_LIST = ('not.an.ip.address');
Query failed — Snowflake returned an error
003043 (22023): SQL compilation error:
Not supported IPv4 format for values '[not.an.ip.address]'.  Current support format is single IPv4 address with or without CIDR.

003043, and the message quotes the value back at us.

Now a number too big to be an octet.

Query
CREATE OR REPLACE NETWORK POLICY NPBAD2_T164
  ALLOWED_IP_LIST = ('999.0.2.1');
Query failed — Snowflake returned an error
003043 (22023): SQL compilation error:
Not supported IPv4 format for values '[999.0.2.1]'.  Current support format is single IPv4 address with or without CIDR.

The same code. Let's check that neither of those left anything behind.

Query
SHOW NETWORK POLICIES LIKE 'NPBAD%';
Result0 rows · 7 columns · scroll →
created_onnamecommententries_in_allowed_ip_listentries_in_blocked_ip_listentries_in_allowed_network_rulesentries_in_blocked_network_rules
Query
SELECT COUNT(*) AS BAD_POLICIES_LEFT
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 1 column
BAD_POLICIES_LEFT
0

Nothing. A refused CREATE leaves no half-written object to clean up.

And now an IPv6 address

This is the one where the message earns its keep.

Query
CREATE OR REPLACE NETWORK POLICY NPV6_T164
  ALLOWED_IP_LIST = ('2001:db8::/32');
Query failed — Snowflake returned an error
003043 (22023): SQL compilation error:
Not supported IPv4 format for values '[2001:db8::/32]'.  Current support format is single IPv4 address with or without CIDR.

003043 again, and read the second sentence: current support format is single IPv4 address with or without CIDR. A network policy's IP list is IPv4 only, and the error says so in its own words rather than making us guess.

Query
SELECT COUNT(*) AS IPV6_POLICY_ROWS
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 1 column
IPV6_POLICY_ROWS
0

So all three of those attempts are the same code, and all three left the account exactly as it was.

Now let's try three policies that should not make sense

These are the three I expected to be told off for. None of them was.

First, a blocked list and no allowed list

Query
CREATE OR REPLACE NETWORK POLICY NPBLOCK_T164
  BLOCKED_IP_LIST = ('203.0.113.0/24')
  COMMENT = 'episode 164 - blocked only, never applied';
Result1 row · 1 column
status
Network policy NPBLOCK_T164 is created.
Query
SELECT "name", "entries_in_allowed_ip_list", "entries_in_blocked_ip_list",
       "comment"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 4 columns
nameentries_in_allowed_ip_listentries_in_blocked_ip_listcomment
NPBLOCK_T16401episode 164 - blocked only, never applied

Made, with 0 in the allowed list and 1 in the blocked list. That is a perfectly reasonable thing to want, so this one is not really a surprise.

Query
SELECT "name", "value"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 2 columns
namevalue
BLOCKED_IP_LIST203.0.113.0/24

Second, the same range allowed and blocked at once

This is the one. Let's put one range in both lists.

Query
CREATE OR REPLACE NETWORK POLICY NPBOTH_T164
  ALLOWED_IP_LIST = ('203.0.113.0/24')
  BLOCKED_IP_LIST = ('203.0.113.0/24');
Result1 row · 1 column
status
Network policy NPBOTH_T164 is created.
Query
SELECT "name", "entries_in_allowed_ip_list", "entries_in_blocked_ip_list"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 3 columns
nameentries_in_allowed_ip_listentries_in_blocked_ip_list
NPBOTH_T16411

Accepted, with 1 in each list. And DESCRIBE reports it twice.

Query
SELECT "name", "value"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result2 rows · 2 columns
namevalue
ALLOWED_IP_LIST203.0.113.0/24
BLOCKED_IP_LIST203.0.113.0/24
An honest gap

Which list wins? I do not know. Finding out means applying this policy to something, and the only thing here is the account these queries ran on. So that question is left open on purpose, and the two rows above are all we have.

Third, a policy with no lists at all

Query
CREATE OR REPLACE NETWORK POLICY NPEMPTY_T164
  COMMENT = 'episode 164 - no lists at all';
Result1 row · 1 column
status
Network policy NPEMPTY_T164 is created.
Query
SHOW NETWORK POLICIES LIKE 'NPEMPTY\\_T164';
Result1 row · 7 columns · scroll →
created_onnamecommententries_in_allowed_ip_listentries_in_blocked_ip_listentries_in_allowed_network_rulesentries_in_blocked_network_rules
2026-10-06 12:22:10.779000-07:00NPEMPTY_T164episode 164 - no lists at all0000

Also accepted. All four count columns read 0. It is an object that exists and constrains nothing at all.

Query
SELECT COUNT(*) AS EMPTY_POLICY_ROWS
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 1 column
EMPTY_POLICY_ROWS
1

Let's change a policy with ALTER

The three-range policy is still there. Let's check it before we touch it.

Query
SELECT "name", "entries_in_allowed_ip_list"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 2 columns
nameentries_in_allowed_ip_list
NPMANY_T1643

Three entries. Now let's set the allowed list to one range and see what happens to the other two.

Query
ALTER NETWORK POLICY NPMANY_T164 SET ALLOWED_IP_LIST = ('192.0.2.0/24');
Result1 row · 1 column
status
Statement executed successfully.
Query
SELECT "name", "entries_in_allowed_ip_list", "entries_in_blocked_ip_list"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 3 columns
nameentries_in_allowed_ip_listentries_in_blocked_ip_list
NPMANY_T16410

One. The other two are gone.

Query
SELECT "name", "value"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 2 columns
namevalue
ALLOWED_IP_LIST192.0.2.0/24

SET replaces the whole list. It does not add to it. If you want to add a range, you write out every range you want to keep as well.

And the two ALTERs that leave the list alone

Let's set a comment on the same policy.

Query
ALTER NETWORK POLICY NPMANY_T164 SET COMMENT = 'episode 164 - altered once';
Result1 row · 1 column
status
Statement executed successfully.
Query
SELECT "name", "comment", "entries_in_allowed_ip_list"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 3 columns
namecommententries_in_allowed_ip_list
NPMANY_T164episode 164 - altered once1

The comment changed and the entry count did not. Now let's unset a blocked list that was never set in the first place.

Query
ALTER NETWORK POLICY NPMANY_T164 UNSET BLOCKED_IP_LIST;
Result1 row · 1 column
status
Statement executed successfully.
Query
SELECT "name", "entries_in_allowed_ip_list", "entries_in_blocked_ip_list"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 3 columns
nameentries_in_allowed_ip_listentries_in_blocked_ip_list
NPMANY_T16410

Statement executed successfully, and nothing moved. Unsetting something that is already empty is not an error.

Now let's make a network rule

A network rule is a separate object with a separate shape. It has a type, a mode, and a list of values.

Query
CREATE OR REPLACE NETWORK RULE INRULE_T164
  TYPE       = IPV4
  MODE       = INGRESS
  VALUE_LIST = ('192.0.2.0/24', '198.51.100.0/24')
  COMMENT    = 'episode 164 - the kind of rule a policy consumes';
Result1 row · 1 column
status
Network rule INRULE_T164 is created.

Created. Note that a rule lives in a database and a schema, which a network policy does not.

Query
SHOW NETWORK RULES LIKE 'INRULE\\_T164';
Result1 row · 10 columns · scroll →
created_onnamedatabase_nameschema_nameownercommenttypemodeentries_in_valuelistowner_role_type
2026-10-06 12:22:20.690000-07:00INRULE_T164DEMO_DBPUBLICACCOUNTADMINepisode 164 - the kind of rule a policy consumesIPV4INGRESS2ROLE
Query
SELECT "name", "type", "mode", "entries_in_valuelist", "comment"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 5 columns
nametypemodeentries_in_valuelistcomment
INRULE_T164IPV4INGRESS2episode 164 - the kind of rule a policy consumes

Type IPV4, mode INGRESS, and entries_in_valuelist reads 2.

And DESCRIBE on a rule gives us the values themselves, comma-separated in one column, the same way it did for a policy.

Query
SELECT "name", "type", "mode", "value_list"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 4 columns
nametypemodevalue_list
INRULE_T164IPV4INGRESS192.0.2.0/24,198.51.100.0/24

A type and a mode, and the two are paired

Let's try a mode that is not a mode at all, to see what the refusal tells us.

Query
CREATE OR REPLACE NETWORK RULE BADMODE_T164
  TYPE       = IPV4
  MODE       = SIDEWAYS
  VALUE_LIST = ('192.0.2.0/24');
Query failed — Snowflake returned an error
098502 (22023): The network rule mode must be one of the snowflake supported network rule mode.

098502. The mode must be one of the supported modes, and the message does not say what those are. So let's ask a better question: a real mode, on a real type, in a combination that might not be allowed.

Query
CREATE OR REPLACE NETWORK RULE EGIPV4_T164
  TYPE       = IPV4
  MODE       = EGRESS
  VALUE_LIST = ('192.0.2.0/24');
Query failed — Snowflake returned an error
098511 (22023): SQL compilation error: The network rule mode EGRESS is not supported by the network rule type IPv4. The network rule mode must be one of [INGRESS, POSTGRES_INGRESS, POSTGRES_EGRESS].

098511, and this one is doing our work for us. It names the whole set of modes that IPV4 accepts.

Query
SHOW NETWORK RULES LIKE 'EGIPV4\\_T164';
Result0 rows · 10 columns · scroll →
created_onnamedatabase_nameschema_nameownercommenttypemodeentries_in_valuelistowner_role_type
Query
SELECT COUNT(*) AS EGRESS_IPV4_ROWS
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 1 column
EGRESS_IPV4_ROWS
0

Nothing created. Now the other way round: the HOST_PORT type, with the mode that IPV4 wanted.

Query
CREATE OR REPLACE NETWORK RULE OUTRULE_T164
  TYPE       = HOST_PORT
  MODE       = INGRESS
  VALUE_LIST = ('example.com:443');
Query failed — Snowflake returned an error
098511 (22023): SQL compilation error: The network rule mode INGRESS is not supported by the network rule type HOST_PORT. The network rule mode must be one of [EGRESS, DATA_CONNECTIVITY_PROXY_EGRESS].

The same code, naming a different set. So 098511 is worth provoking on purpose: it hands you the pairing table for the type you are holding.

Query
SELECT COUNT(*) AS HOST_PORT_INGRESS_ROWS
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 1 column
HOST_PORT_INGRESS_ROWS
0
Rule typeModes the refusal named for it
IPV4INGRESS, POSTGRES_INGRESS, POSTGRES_EGRESS
HOST_PORTEGRESS, DATA_CONNECTIVITY_PROXY_EGRESS

Both of those lists are read straight off the two error panes above. The second one is the list Episode 154 reached from the other direction.

Let's build a policy out of a rule instead of addresses

A policy does not have to hold addresses. It can name a rule, and the rule holds the addresses.

Query
CREATE OR REPLACE NETWORK POLICY NPRULE_T164
  ALLOWED_NETWORK_RULE_LIST = (INRULE_T164)
  COMMENT = 'episode 164 - built from a rule, and still never applied';
Result1 row · 1 column
status
Network policy NPRULE_T164 is created.
Query
SELECT "name", "entries_in_allowed_ip_list", "entries_in_blocked_ip_list",
       "entries_in_allowed_network_rules", "entries_in_blocked_network_rules"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 5 columns
nameentries_in_allowed_ip_listentries_in_blocked_ip_listentries_in_allowed_network_rulesentries_in_blocked_network_rules
NPRULE_T1640010

Both IP counts read 0, and entries_in_allowed_network_rules reads 1. That last column is empty on every address-based policy we have made.

And DESCRIBE shows us something we have not seen yet.

Query
SELECT "name", "value"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 2 columns
namevalue
ALLOWED_NETWORK_RULE_LIST[{"fullyQualifiedRuleName":"DEMO_DB.PUBLIC.INRULE_T164"}]

JSON, with the fully qualified name of the rule inside it. Database, schema, rule.

One honest correction before we go on

The demo also tried to build a policy out of the egress rule from the last section, and out of a rule name that was never used at all.

Query
-- A policy that names the egress rule from two blocks ago.
CREATE OR REPLACE NETWORK POLICY NPEG_T164
  ALLOWED_NETWORK_RULE_LIST = (EGIPV4_T164);
Query
-- And a policy that names a rule nobody ever created.
CREATE OR REPLACE NETWORK POLICY NPGHOST_T164
  ALLOWED_NETWORK_RULE_LIST = (NO_SUCH_RULE_T164);

Both were refused with 002003, and the message in each case is that the named network rule does not exist or is not authorised.

That is not a rule about egress rules inside policies. The egress rule was never created, because the statement that would have made it was refused with 098511 in the last section. So the error is about absence, not about egress, and it would be easy to read it the other way.

Why there is no error pane for those two

The two refusals above are not shown as error panes on this page. Both messages name this account's own identifier, and an error pane here is printed exactly as it came back rather than edited, so the whole pane is left out instead. Nothing about Snowflake's behaviour is missing from the paragraph above it.

Query
SELECT COUNT(*) AS EGRESS_RULE_POLICY_ROWS
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 1 column
EGRESS_RULE_POLICY_ROWS
0

And neither attempt left a policy behind.

Can we drop a rule a policy is using?

The rule-based policy is still pointing at our ingress rule. Let's try to drop the rule out from under it.

Query
DROP NETWORK RULE INRULE_T164;
Query failed — Snowflake returned an error
098509 (2BP01): Cannot drop Network rule INRULE_T164 as it is associated with some network policies.

098509. Refused, and the message says why: the rule is associated with some network policies.

Query
SHOW NETWORK RULES LIKE 'INRULE\\_T164';
Result1 row · 10 columns · scroll →
created_onnamedatabase_nameschema_nameownercommenttypemodeentries_in_valuelistowner_role_type
2026-10-06 12:22:20.690000-07:00INRULE_T164DEMO_DBPUBLICACCOUNTADMINepisode 164 - the kind of rule a policy consumesIPV4INGRESS2ROLE
Query
SELECT COUNT(*) AS RULE_STILL_THERE
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 1 column
RULE_STILL_THERE
1

The count says 1. The rule is still there and the drop simply did not happen.

Query
SELECT "name", "value"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 2 columns
namevalue
ALLOWED_NETWORK_RULE_LIST[{"fullyQualifiedRuleName":"DEMO_DB.PUBLIC.INRULE_T164"}]

And the policy still names it.

The same question, two different answers

This is worth sitting with for a second. In Episode 157 we dropped a resource monitor that was actively guarding a warehouse, and it just worked, silently. Here the same shape of statement is refused outright. Same question, opposite answers, and nothing about either statement tells you which kind of object you are holding.

Now the names that exist and the names that do not

Let's try to create a policy with a name that is already taken.

Query
CREATE NETWORK POLICY NP_T164 ALLOWED_IP_LIST = ('192.0.2.0/24');
Query failed — Snowflake returned an error
002002 (42710): SQL compilation error:
Object 'NP_T164' already exists.

002002, object already exists. Now the same statement with IF NOT EXISTS, and a different allowed list and comment inside it.

Query
CREATE NETWORK POLICY IF NOT EXISTS NP_T164
  ALLOWED_IP_LIST = ('203.0.113.0/24')
  COMMENT = 'episode 164 - this comment should NOT appear';
Result1 row · 1 column
status
NP_T164 already exists, statement succeeded.

That succeeded. But look at what the policy says now.

Query
SELECT "name", "comment", "entries_in_allowed_ip_list"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 3 columns
namecommententries_in_allowed_ip_list
NP_T164episode 164 - created, read, dropped, and NEVER APPLIED to anything1

The original comment, and the original entry count. IF NOT EXISTS did not update anything. It noticed the object was there and stopped.

And a policy that is not there at all

Query
DESCRIBE NETWORK POLICY NO_SUCH_POLICY_T164;
Query failed — Snowflake returned an error
002003 (02000): SQL compilation error:
Network policy 'NO_SUCH_POLICY_T164' does not exist or not authorized. Your primary role ACCOUNTADMIN or one of your secondary roles must have at least one privilege granted on NETWORK POLICY NO_SUCH_POLICY_T164.
Query
DROP NETWORK POLICY NO_SUCH_POLICY_T164;
Query failed — Snowflake returned an error
002003 (02000): SQL compilation error:
Network policy 'NO_SUCH_POLICY_T164' does not exist or not authorized. Your primary role ACCOUNTADMIN or one of your secondary roles must have at least one privilege granted on NETWORK POLICY NO_SUCH_POLICY_T164.

The same 002003 from both. And with IF EXISTS the drop goes quiet instead.

Query
DROP NETWORK POLICY IF EXISTS NO_SUCH_POLICY_T164;
Result1 row · 1 column
status
Drop statement executed successfully (NO_SUCH_POLICY_T164 already dropped).

The status message tells us it was already dropped, which is a nicer thing to read in a script than a refusal.

One last thing: let's put the account back

Everything above was created, read and is now dropped. Here is the account afterwards.

Query
SHOW NETWORK POLICIES;
Result0 rows · 7 columns · scroll →
created_onnamecommententries_in_allowed_ip_listentries_in_blocked_ip_listentries_in_allowed_network_rulesentries_in_blocked_network_rules
Query
SELECT COUNT(*) AS MY_POLICIES_LEFT
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
 WHERE "name" LIKE '%\\_T164' ESCAPE '\\';
Result1 row · 1 column
MY_POLICIES_LEFT
0
Query
SHOW NETWORK RULES;
Result0 rows · 10 columns · scroll →
created_onnamedatabase_nameschema_nameownercommenttypemodeentries_in_valuelistowner_role_type
Query
SELECT COUNT(*) AS MY_RULES_LEFT
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
 WHERE "name" LIKE '%\\_T164' ESCAPE '\\';
Result1 row · 1 column
MY_RULES_LEFT
0

Empty, and both counts read 0. And the parameter we read in the first section, one more time.

Query
SELECT "key", "value", "default", "level"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 4 columns
keyvaluedefaultlevel
NETWORK_POLICY

Still empty. Not one of the policies on this page was ever applied to anything, and that grid is the proof of it.

Key points

  • A network policy holds an allowed IP list, a blocked IP list, or a list of network rules. It does nothing until it is applied.
  • SHOW NETWORK POLICIES counts the entries. DESCRIBE NETWORK POLICY gives you the entries themselves, comma-separated in one value.
  • A bare address is stored exactly as written. No /32 is added for you.
  • An IP list is IPv4 only. Anything else, IPv6 included, is 003043, and nothing is left behind.
  • A blocked-only policy is accepted. So is a policy with no lists at all. So is the same range in both lists at once.
  • ALTER ... SET replaces the whole list. SET COMMENT leaves the list alone, and UNSET on something that was never set succeeds.
  • A network rule has a TYPE and a MODE, and the two are paired. 098511 names the whole set of modes the type allows.
  • A policy can name a rule instead of an address, and DESCRIBE returns JSON with the rule's fully qualified name in it.
  • A rule that a policy is using cannot be dropped: 098509, and the rule is still there afterwards.
Next in this series

In the next post we move from who can reach the account to what they can see once they are in: masking policies. A policy attached to a column, two roles getting two different answers, and the case where the owner of the table and the policy cannot read their own data.

Every query and every result grid on this page was captured from a live Snowflake account (version 10.36.101) running the demo script for this episode. No policy on this page was applied to the account or to a user, and the NETWORK_POLICY parameter is read empty in the first section and read empty again in the last. Every address used is from a range reserved for documentation, so no real network is named. Two refusals are described in prose rather than shown, because their message text names this account; that is said where it happens. Nothing here is timed and no performance claims are made anywhere in this series. Behaviour follows the Snowflake CREATE NETWORK POLICY documentation.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.