โ02-14-2023 08:00 AM
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 )
โ04-09-2023 08:13 AM
@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:
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.
โ04-07-2024 07:23 AM
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.
โ07-02-2024 01:34 PM - edited โ07-02-2024 02:22 PM
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...
โ04-20-2023 02:29 AM
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!
Passionate about hosting events and connecting people? Help us grow a vibrant local communityโsign up today to get started!
Sign Up Now