-
Notifications
You must be signed in to change notification settings - Fork 881
server: fix redirect URL in oauth2-proxy flow #8322
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
base: master
Are you sure you want to change the base?
server: fix redirect URL in oauth2-proxy flow #8322
Conversation
Summary of ChangesHello @webconn, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical issue in the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request fixes a bug in the OAuth2 proxy flow where redirects would use an internal URL, causing issues when running behind a reverse proxy. The change correctly uses a root-relative path for the redirect. I've suggested a further improvement to also handle deployments under a subpath, making the solution more robust.
| signin_url = (f'/oauth2/start?' | ||
| f'rd={rd}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change correctly fixes the issue of redirecting to an internal URL when behind a reverse proxy. However, as you noted in the PR description, using a root-relative path /oauth2/start doesn't handle cases where the application is deployed under a subpath (e.g., http://example.com/my-skypilot/). A redirect to /oauth2/start would incorrectly go to http://example.com/oauth2/start.
A more robust solution is to use request.base_url.path to construct the redirect URL. This will include the root_path if the application is mounted under a subpath, while still being a relative path that avoids the internal host issue.
This change will work correctly in all scenarios:
- Directly:
request.base_url.pathis/, URL becomes/oauth2/start. - Behind a reverse proxy (no subpath):
request.base_url.pathis/, URL becomes/oauth2/start. - Behind a reverse proxy (with subpath, e.g.,
/my-skypilot):request.base_url.pathis/my-skypilot/, URL becomes/my-skypilot/oauth2/start.
This approach is more robust and addresses the concern you raised about base_path. It could also be applied to the other redirect you pointed out in sky/server/server.py for consistency.
| signin_url = (f'/oauth2/start?' | |
| f'rd={rd}') | |
| signin_url = (f'{request.base_url.path}oauth2/start?' | |
| f'rd={rd}') |
I encountered a problem running SkyPilot API server with oauth2-proxy behind a reverse proxy.
This redirect was sending a client to an internal URL (available behind the reverse proxy but not available from the client) thus breaking the flow.
I'm not sure if it was intentional. I can imagine if
root_pathshould be taken into account somehow (e.g. if the server is deployed to be available with a prefix, likehttp://example.com/my-skypilot/dashboard) and I couldn't find a solid explanation in FastAPI / Starlette docs. In SkyPilot itself though there is a place where such a redirect is already used:skypilot/sky/server/server.py
Line 2144 in 8572b31
With my fix it seems to work both behind a reverse proxy and directly.
Tested (run the relevant ones):
bash format.sh/smoke-test(CI) orpytest tests/test_smoke.py(local)/smoke-test -k test_name(CI) orpytest tests/test_smoke.py::test_name(local)/quicktest-core(CI) orpytest tests/smoke_tests/test_backward_compat.py(local)