Country or region and language

    Choose your country or region and your language.

    Suggested for you

      All countries and regions

        Choose your character

        It shows in the top bar and on your profile. Change it any time.

        Sign in or join
        Snowflake SQL course

        Production policy boundaries

        Opening Snowflake SQL
        Your turn

        Snowflake masking policy and row access policy tests

        A masking policy decides which value a reader sees in a column. A row access policy decides which rows the reader sees at all. Both are expressions that Snowflake evaluates at query time, for the role running the query, so you test them by reading the table as each role that matters.

        Role matrix

        List the roles before you write the policy: the owner, every privileged branch, and at least one restricted reader. For each role, write down what it should see, including a row whose value is NULL. Then query the protected table once per role and compare. A test run only as the administrator proves the privileged branch and nothing else.

        CURRENT_ROLE and IS_ROLE_IN_SESSION

        CURRENT_ROLE() returns the session’s primary role. IS_ROLE_IN_SESSION('ENGINEER') is true when ENGINEER is anywhere in the active role hierarchy, including roles the primary role inherits. If SYSADMIN inherits ENGINEER, a condition written as CURRENT_ROLE() = 'ENGINEER' masks SYSADMIN as well. Decide which behavior you want and test both roles.

        NULL values and missing regions

        In a row access policy, region = 'Northeast' is not true when the region is NULL, so that row stays hidden from restricted readers. That is usually what you want. Treating NULL as allowed discloses a row nobody approved. In a masking policy, decide whether a stored NULL should come back as NULL or as the replacement text, because the two say different things to the reader.

        Secure views

        A secure view hides its definition from users who do not own it. It does not mask anything by itself. Build it over the protected table, so the masking and row rules still apply, and grant SELECT on the view to the reader.

        The policy boundaries lesson checks each policy for SYSADMIN, ENGINEER and ANALYST, and the governed delivery project applies both kinds of policy to a published table. Masking and row access policies need Enterprise Edition or higher.

        References: Column-level security, Row access policies, IS_ROLE_IN_SESSION.

        Guides on this topic

        Your Work Gym account

        Save your progress and pick up on another device. Your browser's progress comes with you.

        Your account can start a 5-day free trial: every course, unit, project and exam. Card needed; cancel any time and pay nothing.

        New accounts get 6 hours of full access: every course, unit, project and exam. The clock starts when you go past the free lessons.

        Plan your practice from a job ad or syllabus

        Have a referral code?

        or

        You can keep practicing without an account.

        Change your plan

        Checking the price

        Help and feedback

        Ask a question, tell us what is not working, or share an idea. We reply by email.

        What is it about?

        We use it only to reply to you.