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(drill): specify an SA URL parm of impersonation_target for drill+sadrill #19252

Merged
merged 5 commits into from
Mar 31, 2022

Conversation

jnturton
Copy link
Contributor

@jnturton jnturton commented Mar 18, 2022

SUMMARY

Sqlalchemy-drill has been updated to support impersonation with the
drill+sadrill driver, where previously it did not. The way that callers
should specify impersonation matches that for the drill+jdbc driver in that
a SA URL parameter of impersonation_target should be set to the username
of the user to be impersonated, while the standard SA username and password
should be those of the proxy user.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A

TESTING INSTRUCTIONS

Configure a new Apache Drill connection using the drill+sadrill driver from
sqlalchemy-drill. Enable impersonation and trigger the execution of a Drill
query. In the Drill query profile history, confirm that the query was executed
as the impersonated user.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

…et".

Sqlalchemy-drill is being updated to support impersonation with the
drill+sadrill driver, where previously it did not.  The way that callers
should specify impersonation matches that for the drill+jdbc driver in that
a SA URL parameter of impersonation_target should be set to the username
of the user to be impersonated, while the stadard SA username and password
should be those of the proxy user.
@codecov
Copy link

codecov bot commented Mar 18, 2022

Codecov Report

Merging #19252 (7d3a959) into master (b5e9fad) will decrease coverage by 0.12%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master   #19252      +/-   ##
==========================================
- Coverage   66.76%   66.63%   -0.13%     
==========================================
  Files        1670     1673       +3     
  Lines       64398    63977     -421     
  Branches     6499     6499              
==========================================
- Hits        42993    42633     -360     
+ Misses      19722    19661      -61     
  Partials     1683     1683              
Flag Coverage Δ
hive 52.70% <33.33%> (+0.15%) ⬆️
mysql 81.91% <100.00%> (-0.06%) ⬇️
postgres 81.95% <100.00%> (-0.06%) ⬇️
presto 52.55% <33.33%> (+0.15%) ⬆️
python 82.39% <100.00%> (-0.05%) ⬇️
sqlite 81.73% <100.00%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
superset/db_engine_specs/drill.py 87.17% <100.00%> (+0.33%) ⬆️
superset/tasks/slack_util.py 0.00% <0.00%> (-86.96%) ⬇️
superset/views/database/views.py 31.36% <0.00%> (-60.53%) ⬇️
superset/views/database/validators.py 57.89% <0.00%> (-26.32%) ⬇️
superset/views/chart/filters.py 75.00% <0.00%> (-25.00%) ⬇️
superset/forms.py 75.00% <0.00%> (-21.88%) ⬇️
superset/views/users/api.py 88.88% <0.00%> (-11.12%) ⬇️
superset/views/alerts.py 77.77% <0.00%> (-5.74%) ⬇️
superset/views/database/forms.py 88.88% <0.00%> (-5.56%) ⬇️
superset/key_value/commands/delete.py 85.29% <0.00%> (-3.60%) ⬇️
... and 152 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b5e9fad...7d3a959. Read the comment docs.

@jnturton
Copy link
Contributor Author

Bump?

Copy link
Member

@villebro villebro left a comment

Choose a reason for hiding this comment

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

Thanks for this enhancement! Left a few comments, LMKWYT

superset/db_engine_specs/drill.py Outdated Show resolved Hide resolved
assert url.username == username
assert url.query["impersonation_target"] == username
Copy link
Member

Choose a reason for hiding this comment

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

nit: bonus points for adding impersonation tests for drill+odbc, drill+jdbc and drill+foobar.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The first two cases are already higher up in test_drill.py. I've now added the drill+foobar case.

Copy link
Member

Choose a reason for hiding this comment

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

Apologies, I stand corrected!

@pull-request-size pull-request-size bot added size/M and removed size/S labels Mar 31, 2022
Copy link
Member

@villebro villebro left a comment

Choose a reason for hiding this comment

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

LGTM, one last nit

Comment on lines 86 to 91
try:
DrillEngineSpec.modify_url_for_impersonation(url, True, username)
except Exception as e:
exception_type = type(e)

assert exception_type == SupersetDBAPIProgrammingError
Copy link
Member

Choose a reason for hiding this comment

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

nit: this is how it's usually done with pytest:

Suggested change
try:
DrillEngineSpec.modify_url_for_impersonation(url, True, username)
except Exception as e:
exception_type = type(e)
assert exception_type == SupersetDBAPIProgrammingError
with pytest.raises(SupersetDBAPIProgrammingError):
DrillEngineSpec.modify_url_for_impersonation(url, True, username)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I'll push again and watch the CI output, it looks like there might be some problem with my use of the SupersetDBAPIProgrammingError type in this module.

Copy link
Member

Choose a reason for hiding this comment

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

Oh - you may need to move the exception import into the test function

@jnturton jnturton requested a review from villebro March 31, 2022 15:34
Copy link
Member

@villebro villebro left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the additional iterations!

@villebro villebro merged commit 85e330e into apache:master Mar 31, 2022
villebro pushed a commit that referenced this pull request Apr 3, 2022
…l+sadrill (#19252)

* Update drill+sadrill to specify an SA URL parm of "impersonation_target".

Sqlalchemy-drill is being updated to support impersonation with the
drill+sadrill driver, where previously it did not.  The way that callers
should specify impersonation matches that for the drill+jdbc driver in that
a SA URL parameter of impersonation_target should be set to the username
of the user to be impersonated, while the stadard SA username and password
should be those of the proxy user.

* Remove lint.

* Address review comments.

* Use idiomatic pytest to test for a raised exception.

* Fix import statement order in drill.py.

(cherry picked from commit 85e330e)
villebro pushed a commit that referenced this pull request Apr 4, 2022
…l+sadrill (#19252)

* Update drill+sadrill to specify an SA URL parm of "impersonation_target".

Sqlalchemy-drill is being updated to support impersonation with the
drill+sadrill driver, where previously it did not.  The way that callers
should specify impersonation matches that for the drill+jdbc driver in that
a SA URL parameter of impersonation_target should be set to the username
of the user to be impersonated, while the stadard SA username and password
should be those of the proxy user.

* Remove lint.

* Address review comments.

* Use idiomatic pytest to test for a raised exception.

* Fix import statement order in drill.py.

(cherry picked from commit 85e330e)
philipher29 pushed a commit to ValtechMobility/superset that referenced this pull request Jun 9, 2022
…l+sadrill (apache#19252)

* Update drill+sadrill to specify an SA URL parm of "impersonation_target".

Sqlalchemy-drill is being updated to support impersonation with the
drill+sadrill driver, where previously it did not.  The way that callers
should specify impersonation matches that for the drill+jdbc driver in that
a SA URL parameter of impersonation_target should be set to the username
of the user to be impersonated, while the stadard SA username and password
should be those of the proxy user.

* Remove lint.

* Address review comments.

* Use idiomatic pytest to test for a raised exception.

* Fix import statement order in drill.py.
@mistercrunch mistercrunch added 🍒 1.5.0 🍒 1.5.1 🍒 1.5.2 🍒 1.5.3 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 2.0.0 labels Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels lts-v1 size/M 🍒 1.5.0 🍒 1.5.1 🍒 1.5.2 🍒 1.5.3 🚢 2.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants