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

chore: allow machine auth to generate CSRF token #26003

Closed

Conversation

mapledan
Copy link
Contributor

The celery task get permissions through machine_auth.
The 'cache-warmup' task needs to call the '/api/v1/chart/warm_up_cache' endpoint .However, this endpoint is non GET requests and is therefore protected by CSRF.
Hence, when machine_auth retrieves the auth cookies, it also needs to generate a CSRF token.
This ensures that the Celery task can operate successfully.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

  1. Configure the cache-warmup task.
  2. The Celery task successfully executed the fetch_url action.

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

@@ -143,6 +144,31 @@ def get_auth_cookies(user: User) -> dict[str, str]:

return cookies

@staticmethod
def get_auth_cookie_and_csrf_token(user: User) -> tuple[dict[str, str], str]:
Copy link
Member

Choose a reason for hiding this comment

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

We could check for app.config["WTF_CSRF_ENABLED"] here and DRY the code a bit more by removing get_auth_cookies

Copy link

codecov bot commented Dec 7, 2023

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (bf5b18c) 69.19% compared to head (9eac136) 69.18%.

Files Patch % Lines
superset/tasks/cache.py 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #26003      +/-   ##
==========================================
- Coverage   69.19%   69.18%   -0.01%     
==========================================
  Files        1944     1944              
  Lines       75927    75932       +5     
  Branches     8451     8451              
==========================================
+ Hits        52534    52537       +3     
- Misses      21208    21210       +2     
  Partials     2185     2185              
Flag Coverage Δ
hive 53.68% <18.18%> (-0.01%) ⬇️
mysql 78.10% <81.81%> (+0.02%) ⬆️
postgres 78.19% <81.81%> (+<0.01%) ⬆️
presto 53.63% <18.18%> (-0.01%) ⬇️
python 82.88% <81.81%> (-0.01%) ⬇️
sqlite 76.85% <81.81%> (+<0.01%) ⬆️
unit 55.80% <18.18%> (-0.01%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mapledan
Copy link
Contributor Author

It's related to #28706

@mapledan mapledan closed this Aug 13, 2024
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.

2 participants