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

Fix user impersonation with presto #9422

Closed
wants to merge 1 commit 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
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pre-commit==1.17.0
psycopg2-binary==2.7.5
pycodestyle==2.5.0
pydruid==0.5.7
pyhive==0.6.1
pyhive==0.6.2
pylint==1.9.2
redis==3.2.1
requests==2.22.0
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def get_git_sha():
"hive": ["pyhive[hive]>=0.6.1", "tableschema", "thrift>=0.11.0, <1.0.0"],
"mysql": ["mysqlclient==1.4.2.post1"],
"postgres": ["psycopg2-binary==2.7.5"],
"presto": ["pyhive[presto]>=0.4.0"],
"presto": ["pyhive[presto]>=0.6.2"],
"elasticsearch": ["elasticsearch-dbapi>=0.1.0, <0.2.0"],
"druid": ["pydruid==0.5.7", "requests==2.22.0"],
"hana": ["hdbcli==2.4.162", "sqlalchemy_hana==0.4.0"],
Expand Down
10 changes: 7 additions & 3 deletions superset/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,10 @@ def get_sqla_engine(
# If using MySQL or Presto for example, will set url.username
# If using Hive, will not do anything yet since that relies on a
# configuration parameter instead.
self.db_engine_spec.modify_url_for_impersonation(
sqlalchemy_url, self.impersonate_user, effective_username
)
if not user_name or not str(sqlalchemy_url).startswith('presto'):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There shouldn't be any database specific logic in core.py hence the reason for the self.db_engine_spec.modify_url_for_impersonation(...) method. You should do something like this.

self.db_engine_spec.modify_url_for_impersonation(
sqlalchemy_url, self.impersonate_user, effective_username
)

masked_url = self.get_password_masked_url(sqlalchemy_url)
logger.debug("Database.get_sqla_engine(). Masked URL: %s", str(masked_url))
Expand All @@ -313,6 +314,9 @@ def get_sqla_engine(
if connect_args:
params["connect_args"] = connect_args

if user_name and self.impersonate_user and str(sqlalchemy_url).startswith('presto'):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See ^^. You should update get_configuration_for_impersonation to handle this. Note given that this isn't part of the connection key the get_configuration_for_impersonation needs be refactored to be get_connection_args_for_impersonation.

params["connect_args"]['principle_username'] = user_name

params.update(self.get_encrypted_extra())

if DB_CONNECTION_MUTATOR:
Expand Down