0

Can we encrypt stored procedures in Snowflake similar to what we do in SQL Server?

For example, similar to

CREATE PROCEDURE #EncryptSP
WITH ENCRYPTION
AS
QUERY HERE
GO
alroc
  • 27,574
  • 6
  • 51
  • 97
srinu7j
  • 1
  • 2

1 Answers1

1

Everything in Snowflake databases is encrypted, so I believe the issue is allowing users to run a stored procedure but not see its contents. That's not a problem.

-- Using a database called TEST
grant usage on database test to role public;
grant usage on schema public to role public;

-- Create a secure procedure and run it as SYSADMIN (or whatever role you want)
create or replace secure procedure test.public.hello_world()
returns string
language JavaScript
execute as owner
as
$$

    return "Hello world";

$$;

-- Allow users in the PUBLIC role to run the procedure
grant usage on procedure HELLO_WORLD() to role PUBLIC;

-- Test that users in role PUBLIC can run the procedure
use role public;
use database test;
use schema public;
call HELLO_WORLD();

-- However, they cannot see the stored procedure
select get_ddl('procedure', 'HELLO_WORLD()');

-- The owner can.
use role SYSADMIN;
select get_ddl('procedure', 'HELLO_WORLD()');
Greg Pavlik
  • 10,089
  • 2
  • 12
  • 29