cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
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 ) 

4 REPLIES 4

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.

AntonioR
New Contributor II

Sachin, 

I am struggling with a similar problem. I would want to set these session variables on EVERY Session, regardless of what client the queries are coming from, and I can't do it through changing the client's behavior e.g. connecting and issuing separate commands to initialize these before starting their "real" queries. I need to do this to set variables for use in Unity Catalog row filters and column mask UDFs. If you made any progress on this, I'd appreciate hearing about it... 

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!

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group