-
Notifications
You must be signed in to change notification settings - Fork 14.6k
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
DI-1113. ADDENDUM. Authentication: Enable user impersonation for Superset to HiveServer2 using hive.server2.proxy.user (a.fernandez) #3697
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -3,27 +3,6 @@ | |||
from thrift import Thrift | |||
|
|||
|
|||
old_Connection = hive.Connection |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer need to patch this.
superset/models/core.py
Outdated
engine_params['poolclass'] = NullPool | ||
|
||
configuration = {} | ||
configuration.update( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update configuration dictionary instead.
superset/views/core.py
Outdated
logging.info("Superset.testconn(). Masked URL: {0}".format(masked_url)) | ||
|
||
configuration = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update configuration dictionary instead.
superset/db_engine_specs.py
Outdated
@@ -187,26 +187,16 @@ def select_star(cls, my_db, table_name, schema=None, limit=100, | |||
return sql | |||
|
|||
@classmethod | |||
def modify_url_for_impersonation(cls, url, impersonate_user, username): | |||
def get_configuration_for_impersonation(cls, uri, impersonate_user, username): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the configuration dictionary instead of the URL's query dictionary so that we don't have to modify PyHive library.
Fixing unit tests right now. |
a6183fd
to
2d59285
Compare
Coverage increased (+0.2%) to 70.947% when pulling 2d592858a269dbdc008b8dc8aaec6d105b5f6d90 on afernandez:afernandez_impersonate into e121a85 on apache:master. |
2 similar comments
Coverage increased (+0.2%) to 70.947% when pulling 2d592858a269dbdc008b8dc8aaec6d105b5f6d90 on afernandez:afernandez_impersonate into e121a85 on apache:master. |
Coverage increased (+0.2%) to 70.947% when pulling 2d592858a269dbdc008b8dc8aaec6d105b5f6d90 on afernandez:afernandez_impersonate into e121a85 on apache:master. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few minor nits otherwise LGTM
superset/views/core.py
Outdated
|
||
connect_args = ( | ||
request.json | ||
.get('extras', {}) | ||
.get('engine_params', {}) | ||
.get('connect_args', {})) | ||
|
||
if len(configuration.keys()) > 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as "pythonesquier" if configurations:
superset/views/core.py
Outdated
|
||
logging.info("Superset.testconn(). Masked URL: {0}".format(masked_url)) | ||
configuration.update(db_engine.get_configuration_for_impersonation(uri, impersonate_user, username)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line if very long, goes way beyond 90chars
superset/views/core.py
Outdated
|
||
configuration = {} | ||
|
||
if database is not None and uri is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if database and uri:
…rset to HiveServer2 using hive.server2.proxy.user (a.fernandez)
2d59285
to
69d49ed
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed comments
self.db_engine_spec.get_configuration_for_impersonation(str(url), | ||
self.impersonate_user, | ||
effective_username)) | ||
if configuration: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mistercrunch fixed the long line.
self.db_engine_spec.get_configuration_for_impersonation(str(url), | ||
self.impersonate_user, | ||
effective_username)) | ||
if configuration: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mistercrunch fixed this.
|
||
configuration = {} | ||
|
||
if database and uri: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mistercrunch fixed this.
LGTM, you can sync with @graceguo-supercat to merge and deploy |
We use 2 questions:
|
BTW, I've also tried to save the URI as |
…rset to HiveServer2 using hive.server2.proxy.user (a.fernandez) (apache#3697)
…rset to HiveServer2 using hive.server2.proxy.user (a.fernandez) (apache#3697)
Figured out how to make changes to configuration dictionary instead of having to patch the PyHive library. When connecting to Hive, will determine if impersonation is enabled, and if so, will send the currently logged on user via the hive.server2.proxy.user property in the configuration dictionary to SQLAlchemy's create_engine function.
Tested this on my local Superset instance, both Test Connection and Run SQL Query.