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

tickets/DM-45523: walk redirects for Lab manually, extracting xsrf along the way #365

Merged
merged 12 commits into from
Aug 6, 2024

Conversation

athornton
Copy link
Member

@athornton athornton commented Jul 31, 2024

Also allow setting log level for individual monkeys, which makes debugging the problem we're solving here a lot easier.

@athornton athornton marked this pull request as draft July 31, 2024 21:57
@athornton athornton changed the title Tickets/dm 45523 tickets/DM-45523: walk redirects for Lab manually, extracting xsrf along the way Jul 31, 2024
@athornton athornton requested a review from fajpunk August 2, 2024 16:24
@athornton athornton marked this pull request as ready for review August 2, 2024 16:24
requirements/main.in Outdated Show resolved Hide resolved
# automatically.
while r.is_redirect:
xsrf = self._extract_xsrf(r)
if xsrf and xsrf != self._lab_xsrf:
Copy link
Member

@fajpunk fajpunk Aug 2, 2024

Choose a reason for hiding this comment

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

Why do we need to check this against the _lab_xsrf instead of _hub_xsrf? My initial understanding is that we want to change the _hub_sxrf if we get a different one back in any of the responses.

I'm actually sort of confused as to why we're comparing the _lab_xsrf to the _hub_xsrf in auth_to_lab also, but that's not being changed here...

Copy link
Member

Choose a reason for hiding this comment

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

It's a bug in auth_to_lab as well. Looks like an old copy-paste error of mine.

Copy link
Member

Choose a reason for hiding this comment

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

Do we even need to check if the token from the response cookie is different than the one we're storing, or can we just say "if we get an xsrf cookie in a response, store it"?

Copy link
Member

Choose a reason for hiding this comment

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

if xsrf:
    self._hub_xsrf = xsrf

?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm. I misunderstood the intention. I want to check if the token is different than the one we store to cut down on the number of times we log that we're setting the token, so that I can also understand the cadence with which we get genuinely new ones.

Copy link
Member

Choose a reason for hiding this comment

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

Ahh gotcha. Yeah, with the logging it makes sense to keep the check. My main question was about comparing the hub token to the lab token and vice vera, and it looks like that was a bug originally and is fixed now.

@@ -188,6 +188,7 @@ async def execution_idle(self) -> bool:
return await self.pause(self.options.execution_idle_time)

async def shutdown(self) -> None:
await self.hub_login()
Copy link
Member

Choose a reason for hiding this comment

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

What about putting a hub_login call in delete_lab? Tradeoff is that we may call it a few extra times.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I prefer it be explicit.

@athornton athornton force-pushed the tickets/DM-45523 branch 2 times, most recently from 8c94435 to e94e901 Compare August 2, 2024 22:28
@athornton athornton requested a review from fajpunk August 6, 2024 15:56
Comment on lines +848 to +856
if xsrf is not None:
self._logger.debug(
"Extracted _xsrf cookie",
method=response.request.method,
url=response.url.copy_with(query=None, fragment=None),
status_code=response.status_code,
# Logging the set-cookie header can be useful here but it
# leaks secrets. Don't put that code in a release build.
)
Copy link
Member

Choose a reason for hiding this comment

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

Would we want to put this in each auth method so it would be easier to tell if it happened during the hub auth or the lab auth? It would be duplicated, but maybe more clear?

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, if we end up using it, we log that (with whether it is lab or hub as well). I'm not sure we even want to log it in the extraction step. Maybe I'll just leave the comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

Eh, I'm going to leave this alone for now. If it's too chatty if we need to turn on debug for real, we can change it then.

@athornton athornton merged commit 7c00a05 into main Aug 6, 2024
4 checks passed
@athornton athornton deleted the tickets/DM-45523 branch August 6, 2024 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants