sjyangkevin commented on code in PR #77138:
URL: https://github.com/apache/airflow/pull/77138#discussion_r4587637912
##########
providers/fab/src/airflow/providers/fab/auth_manager/fab_auth_manager.py:
##########
@@ -310,23 +337,37 @@ def get_user(self) -> User:
def session(self):
return self.appbuilder.session
- @cachedmethod(lambda self: self.cache, key=lambda _, token:
int(token["sub"]))
def deserialize_user(self, token: dict[str, Any]) -> User:
user_id = int(token["sub"])
+ fingerprint = token.get(PASSWORD_FINGERPRINT_CLAIM)
+ user = self._get_active_user(user_id)
+ if not _is_password_fingerprint_matching(fingerprint, user):
+ # The cached user may predate a password change. Re-read it so a
token issued after the
+ # change is accepted without waiting for the cache entry to expire.
+ user = self._fetch_active_user(user_id)
+ self.cache[user_id] = user
+ if not _is_password_fingerprint_matching(fingerprint, user):
+ raise ValueError(f"Token of user with id {user_id} was not
issued for their current password")
+ return user
+
+ @cachedmethod(lambda self: self.cache, key=lambda _, user_id: user_id)
Review Comment:
Yes. The current implementation reuse the existing TTL mechanism, but I
would appreciate more feedback about this. We can also implement a different
TTL for this specifically, with a shorter timeout. A trade-off is every time
such comparison is going to reach the DB if that is short or removed.
for the test, I think
`test_deserialize_user_accepts_new_token_while_cached_user_is_stale` should
cover this case, but I will double check.
thanks for the feedback!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]