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(#13378): Ensure g.user is set for impersonation #13878

Merged

Conversation

benjreinhart
Copy link
Contributor

@benjreinhart benjreinhart commented Mar 31, 2021

SUMMARY

This fixes #13378 by ensuring that Flask's global object g contains a user object set to the user who initiated the request when queries are executing asynchronously. There is currently some deeply buried code that expects this when constructing the query. This is not a particularly robust fix, so if anyone has any suggestions I'd be very interested in hearing them. Ideally, we'd have a way to explicitly pass the username to where it's needed for impersonation configuration (like SQL lab does), but this would require a substantial amount of changes as far as I can tell. Even if refactoring that is the goal, I think we should get this out to unblock folks first.

TEST PLAN

This is difficult to test well, so the unit tests were updated to ensure a function is called that I manually tested. This is not a great test, and I almost omitted it altogether, but ended up including it. Let me know if you have suggestions.

Additionally, I would like to test this end-to-end but I don't have that environment setup yet. I'm going to work to get this set up. In the meantime, @juneauwang and @gorcurek if you're able to pull this branch down and test it, that would be lovely.

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 Mar 31, 2021

Codecov Report

Merging #13878 (7ed6588) into master (84560e8) will increase coverage by 0.21%.
The diff coverage is 68.31%.

❗ Current head 7ed6588 differs from pull request most recent head 01e226f. Consider uploading reports for the commit 01e226f to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master   #13878      +/-   ##
==========================================
+ Coverage   77.33%   77.55%   +0.21%     
==========================================
  Files         935      935              
  Lines       47278    47307      +29     
  Branches     5883     5907      +24     
==========================================
+ Hits        36564    36690     +126     
+ Misses      10570    10473      -97     
  Partials      144      144              
Flag Coverage Δ
cypress 56.02% <49.09%> (-0.05%) ⬇️
hive 80.29% <70.58%> (?)
mysql 80.59% <70.58%> (-0.01%) ⬇️
postgres 80.50% <66.66%> (-0.14%) ⬇️
presto 80.29% <70.58%> (?)
python 81.00% <66.66%> (+0.28%) ⬆️
sqlite 80.19% <70.58%> (-0.01%) ⬇️

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

Impacted Files Coverage Δ
...frontend/src/components/Checkbox/CheckboxIcons.tsx 85.71% <ø> (ø)
superset-frontend/src/components/Icon/index.tsx 100.00% <ø> (ø)
...ontend/src/components/URLShortLinkButton/index.jsx 100.00% <ø> (ø)
...src/dashboard/components/filterscope/treeIcons.jsx 100.00% <ø> (ø)
...erset-frontend/src/datasource/DatasourceEditor.jsx 65.82% <0.00%> (ø)
...rontend/src/explore/components/EmbedCodeButton.jsx 80.76% <ø> (ø)
...ore/components/controls/AnnotationLayerControl.jsx 82.85% <ø> (ø)
...explore/components/controls/ColorPickerControl.jsx 85.00% <ø> (ø)
...plore/components/controls/FilterBoxItemControl.jsx 73.58% <ø> (ø)
...re/components/controls/TimeSeriesColumnControl.jsx 57.40% <ø> (ø)
... and 38 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 84560e8...01e226f. Read the comment docs.

@juneauwang
Copy link

juneauwang commented Mar 31, 2021

Hi @benjreinhart , thanks a lot for your fix! I just tested it on our dev. effective user can be fetched correctly now.

effective username is wei-peng.wang
[2021-03-31 09:36:41,850: INFO/ForkPoolWorker-7] effective username is wei-peng.wang
[2021-03-31 09:36:41,851: WARNING/ForkPoolWorker-7] /etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt
[2021-03-31 09:36:41,871: WARNING/ForkPoolWorker-7] XXXXIIIIIIIIIIIIII

@robdiciuccio robdiciuccio merged commit ca506e9 into apache:master Mar 31, 2021
@robdiciuccio robdiciuccio deleted the benjreinhart/impersonation-bug branch March 31, 2021 18:23
allanco91 pushed a commit to allanco91/superset that referenced this pull request May 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Worker can't do impersonation while enable global async
3 participants