Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Presto User Impersonation #4807

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions redash/query_runner/presto.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,18 @@ def configuration_schema(cls):
"schema": {"type": "string"},
"catalog": {"type": "string"},
"username": {"type": "string"},
"user_impersonation": {
"type": "boolean",
"title": "Enable User Impersonation",
},
"password": {"type": "string"},
},
"order": [
"host",
"protocol",
"port",
"username",
"user_impersonation",
"password",
"schema",
"catalog",
Expand Down Expand Up @@ -93,11 +98,17 @@ def get_schema(self, get_stats=False):
return list(schema.values())

def run_query(self, query, user):
enable_user_impersonation = self.configuration.get("user_impersonation")
principal_username = None
if enable_user_impersonation and user is not None:
principal_username = user.email.split('@')[0]

connection = presto.connect(
host=self.configuration.get("host", ""),
port=self.configuration.get("port", 8080),
protocol=self.configuration.get("protocol", "http"),
username=self.configuration.get("username", "redash"),
principal_username=principal_username,
password=(self.configuration.get("password") or None),
catalog=self.configuration.get("catalog", "hive"),
schema=self.configuration.get("schema", "default"),
Expand Down
4 changes: 2 additions & 2 deletions requirements_all_ds.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ impyla==0.16.0
influxdb==5.2.3
mysqlclient==1.3.14
oauth2client==4.1.3
pyhive==0.6.1
pyhive==0.6.3 # TODO: This needs to be updated to match the version that this fix is included in. Should not be merged until then.
pymongo[tls,srv]==3.9.0
vertica-python==0.9.5
td-client==1.0.0
Expand Down Expand Up @@ -34,4 +34,4 @@ pydgraph==2.0.2
azure-kusto-data==0.0.35
pyexasol==0.12.0
python-rapidjson==0.8.0
pyodbc==4.0.28
pyodbc==4.0.28