Repository navigation
fix(reports): stamp login time on machine-auth sessions - #45876
Draft
sadpandajoe wants to merge 2 commits into
Draft
sadpandajoe wants to merge 2 commits into
sadpandajoe wants to merge 2 commits into
Conversation
Add a regression test that mints a report-execution session with MachineAuthProvider.get_auth_cookies for a user whose session-invalidation epoch is set (as after a password change), replays the cookie against a real app request, and asserts the request stays authenticated. The session has no login time, so enforce_session_validity treats it as older than the epoch and the request is rejected with a 401. The test fails until machine-minted sessions carry a login time. Controls cover the same cookie with no epoch, and sessions with a login time after and before the epoch. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
MachineAuthProvider.get_auth_cookies logs the report owner in with a bare login_user(), so the minted session has no _login_at. Once a user has a session-invalidation epoch (any password change or reset), the enforce_session_validity hook treats such a session as older than the epoch, logs it out, and the replayed request is anonymous. CSV and XLSX report chart-data fetches then fail with a 401 on every run. Stamp the login time the same way a normal login does, so a session minted after the epoch is valid.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #45876 +/- ##
===========================================
+ Coverage 65.62% 84.71% +19.09%
===========================================
Files 3069 3069
Lines 205661 205663 +2
Branches 48336 48337 +1
===========================================
+ Hits 134955 174220 +39265
+ Misses 67625 28150 -39475
- Partials 3081 3293 +212
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SUMMARY
Scheduled CSV and XLSX chart reports fail on every run with
Chart data request failed: category=http status=401once the report owner has had a password change or reset (or any other session invalidation). The chart itself loads fine in the UI, and the failure happens before any query runs.Root Cause
MachineAuthProvider.get_auth_cookieslogs the report owner in with a barelogin_user(user)inside a throwaway request context and replays the resultingsessioncookie against/api/v1/chart/data. Unlike a normal login, which stampssession["_login_at"]throughon_user_login, that session carries only the Flask-Login keys.enforce_session_validityruns before every request and compares_login_atwith the user'ssessions_invalidated_atepoch.is_session_invalidated(None, epoch)deliberately fails closed, so once the user has an epoch the hook logs the machine-minted session out, the request continues anonymously, and@protect()falls through to the JWT check and answers401 Missing Authorization Header. The report code then surfaces that as the generic chart-data HTTP error.The line itself is old, and the missing stamp only matters since the session-invalidation hook (#40695) and the change that started stamping the epoch on password change and reset for active users (#42934, and the later reset and recovery flows). Users who never changed their password have no epoch and are unaffected, which is why reports worked until a routine password reset.
The fix stamps the login time right after a successful
login_user(), the same way a normal login does, so a session minted after the epoch is valid. The stamp is only applied whenlogin_user()succeeds: an inactive user is still refused andget_auth_cookiesstill returns{}, which is the empty-cookie case the report code reports as missing authentication cookies. The hook, and its fail-closed handling of sessions that predate it, are unchanged: a session whose login time is before the epoch is still rejected.Not addressed here
MACHINE_AUTH_PROVIDER_CLASSthat callslogin_useritself needs the same stamp.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
UI QA: not-required (backend-only change to how a server-side session is minted; no user-visible UI surface). The regression test is the evidence.
Before (the regression test run without the fix),
tests/unit_tests/utils/machine_auth_test.py:After (this PR):
5 passed.TESTING INSTRUCTIONS
Automated:
The new tests mint a session with
MachineAuthProvider.get_auth_cookies, replay the cookie through a real request that passesenforce_session_validity, and assert the result:test_machine_auth_cookie_survives_epochfails without the fix (401) and passes with it. It stamps the epoch in the past through the realinvalidate_sessions_for_user.{}, no cookie).Manual:
superset fab reset-password.Chart data request failed: category=http status=401; with it the email carries the CSV and the run succeeds.ADDITIONAL INFORMATION