Run a notebook as a different user or role

pdiamond
Contributor

Outside of running jobs with different users, is there any way for me to run a notebook (or even better a cell within a notebook) as either a different user or a specific role that is not my user default?

I'm trying to find an easy way to test data masking functions with something like this:

set user or rule to be one without elevated privileges;
select SSN from table;
If SSN = '********' then pass the test;
------
set user or rule to be one with elevated privileges;
select SSN from table;
If SSN = '123456789' then pass the test;

Walter_C
Databricks Employee
Databricks Employee

Unfortunately there is no direct way to run a notebook using additional principal, only option is to set up a notebook job task and on the Run As specify the principal that will run the job that can be a user or a Service Principal.

View solution in original post