cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Can define custom session variable for login user authentication in databricks for Row -Column level security .

vinaykumar
New Contributor III

can create custom session variable for login user authentication in databricks .

Like HANA session Variables, we have scenarios like todayโ€™s spotfire where we use a single generic user to connect to HANA ( we donโ€™t have single sign on enabled ) in this case what we do is we set session variables before the call happens to HANA

And based on these session variables we do certain actions like identifying the user who is connecting on spotfire and implement security rules like column masking, row level security, impersonation ( to be able to proxy as different user ) 

3 REPLIES 3

Anonymous
Not applicable

@vinay kumarโ€‹ :

Yes, you can define custom session variables for login user authentication in Databricks. These session variables can be used to implement row-level and column-level security, similar to what you described for HANA.

To define custom session variables in Databricks, you can use the Databricks REST API or Databricks CLI. Here's an example using the Databricks CLI:

  1. Install the Databricks CLI on your local machine
  2. Open a terminal window and authenticate to your Databricks workspace using the databricks configure command
  3. Run the following command to set a custom session variable:
databricks workspace set-user-session "user1" "key1" "value1"

This command sets the custom session variable key1 with a value of value1 for the user user1 You can set multiple custom session variables for a user by running this command multiple times with different key-value pairs.

Once you have set the custom session variables for the user, you can access them in your Databricks notebooks or jobs using the dbutils.entry_point.getDbutils().notebook().getContext().tags() method. This method returns a dictionary containing the custom session variables for the current user.

For example, you can access the value of the key1 custom session variable using the following code:

key1_value = dbutils.entry_point.getDbutils().notebook().getContext().tags().get("key1")

You can then use the value of key1_value to implement row-level and column-level security in your Databricks notebooks or jobs.

Sachin1
New Contributor II

Hello, thanks for the insight on how to pass set session variable through CLI. However I do have a need to set a session variable while making a database connection from a BI reporting tool. Wondering whether there is any provision in setting a session variable through a JDBC connection and pass the session variable to SQL queries subsequently.

Anonymous
Not applicable

Hi @vinay kumarโ€‹ 

Hope everything is going great.

Just wanted to check in if you were able to resolve your issue. If yes, would you be happy to mark an answer as best so that other members can find the solution more quickly? If not, please tell us so we can help you. 

Cheers!

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.