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

feat(trino): add support for user impersonation #14843

Merged
merged 3 commits into from May 29, 2021

Conversation

rijojoseph07
Copy link
Contributor

SUMMARY

When using authentication with trino, the current behavior is just to modify the URL to replace the username which will result in an unauthorized exception. This PR will fix this by updating the connection argument with the effective user.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

Step 1: Setup database connection to trino with credentials in URL.
Step 2: Enable impersonation from Other option
Step 3 : Log in with a different user and run the query via SQL lab and you will see the principal user as admin and user as the logged-in user in trino UI.

ADDITIONAL INFORMATION

  • Has associated issue:
  • 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

@codecov
Copy link

codecov bot commented May 26, 2021

Codecov Report

Merging #14843 (a0268dd) into master (6bdbd2b) will decrease coverage by 0.10%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #14843      +/-   ##
==========================================
- Coverage   77.62%   77.51%   -0.11%     
==========================================
  Files         963      963              
  Lines       49237    49315      +78     
  Branches     6192     6226      +34     
==========================================
+ Hits        38218    38225       +7     
- Misses      10819    10889      +70     
- Partials      200      201       +1     
Flag Coverage Δ
hive 81.36% <100.00%> (+0.04%) ⬆️
javascript 72.39% <ø> (-0.10%) ⬇️
mysql 81.64% <100.00%> (+0.04%) ⬆️
postgres 81.66% <100.00%> (+0.04%) ⬆️
presto ?
python 82.03% <100.00%> (-0.11%) ⬇️
sqlite 81.27% <100.00%> (+0.04%) ⬆️

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

Impacted Files Coverage Δ
.../CRUD/data/database/DatabaseModal/ExtraOptions.tsx 93.54% <ø> (ø)
superset/db_engine_specs/trino.py 94.73% <100.00%> (+1.40%) ⬆️
...d/src/dashboard/components/gridComponents/Tabs.jsx 76.31% <0.00%> (-11.06%) ⬇️
superset/db_engine_specs/presto.py 84.42% <0.00%> (-5.48%) ⬇️
...nd/src/explore/components/DataTablesPane/index.tsx 83.90% <0.00%> (-4.99%) ⬇️
...onfigModal/FiltersConfigForm/FiltersConfigForm.tsx 69.16% <0.00%> (-3.48%) ⬇️
...nfigModal/FiltersConfigForm/getControlItemsMap.tsx 97.05% <0.00%> (-2.95%) ⬇️
.../src/explore/components/ControlPanelsContainer.tsx 79.16% <0.00%> (-1.69%) ⬇️
superset/connectors/sqla/models.py 88.33% <0.00%> (-1.43%) ⬇️
...src/dashboard/components/FiltersBadge/selectors.ts 75.70% <0.00%> (-1.23%) ⬇️
... and 27 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 6bdbd2b...a0268dd. Read the comment docs.

@dungdm93
Copy link
Contributor

You should add Trino to superset-frontend/src/views/CRUD/data/database/DatabaseModal.tsx as well
Screenshot from 2021-05-28 22-12-14

@rijojoseph07
Copy link
Contributor Author

You should add Trino to superset-frontend/src/views/CRUD/data/database/DatabaseModal.tsx as well
Screenshot from 2021-05-28 22-12-14

Thanks, @dungdm93

Looks like this is moved here : superset-frontend/src/views/CRUD/data/database/DatabaseModal/ExtraOptions.tsx . Have updated the labels here.

Screen Shot 2021-05-28 at 9 42 53 PM

url = make_url(uri)
backend_name = url.get_backend_name()

# Must be Presto connection, enable impersonation, and set optional param
Copy link
Member

Choose a reason for hiding this comment

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

We want to do this only if "enable impersonation" is true, no? In that case it would be better to add it to modify_url_for_impersonation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is called only if impersonation is enabled

// from core.py

if self.impersonate_user:
            self.db_engine_spec.update_impersonation_config(
                connect_args, str(sqlalchemy_url), effective_username
            )

modify_url will work only if authentication is disabled - we will have to modify connection args to pass logged In user_name based on the underlying connector - for presto, its principal_username and for trino its user.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, good point, I missed that.

Copy link
Member

@betodealmeida betodealmeida left a comment

Choose a reason for hiding this comment

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

This is awesome, excited to see Trino being more supported in Superset.

superset/db_engine_specs/trino.py Outdated Show resolved Hide resolved
Co-authored-by: Đặng Minh Dũng <dungdm93@live.com>
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 great improvement!

@villebro villebro merged commit a85f5c1 into apache:master May 29, 2021
cccs-RyanS pushed a commit to CybercentreCanada/superset that referenced this pull request Dec 17, 2021
* trino impersonation feature

* Extra options label update

* Update superset/db_engine_specs/trino.py

Co-authored-by: Đặng Minh Dũng <dungdm93@live.com>

Co-authored-by: rijojoseph01 <rijo.joseph@myntra.com>
Co-authored-by: Đặng Minh Dũng <dungdm93@live.com>
QAlexBall pushed a commit to QAlexBall/superset that referenced this pull request Dec 29, 2021
* trino impersonation feature

* Extra options label update

* Update superset/db_engine_specs/trino.py

Co-authored-by: Đặng Minh Dũng <dungdm93@live.com>

Co-authored-by: rijojoseph01 <rijo.joseph@myntra.com>
Co-authored-by: Đặng Minh Dũng <dungdm93@live.com>
cccs-rc pushed a commit to CybercentreCanada/superset that referenced this pull request Mar 6, 2024
* trino impersonation feature

* Extra options label update

* Update superset/db_engine_specs/trino.py

Co-authored-by: Đặng Minh Dũng <dungdm93@live.com>

Co-authored-by: rijojoseph01 <rijo.joseph@myntra.com>
Co-authored-by: Đặng Minh Dũng <dungdm93@live.com>
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.3.0 labels Mar 12, 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 size/M 🚢 1.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants