-
Notifications
You must be signed in to change notification settings - Fork 12.1k
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
ServeFromSubPath: Redirect to URL with subpath when subpath missing #66724
Conversation
Prometheus follows 301 redirects when scraping metrics. Kubernetes says |
@bergquist pushed an update
|
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestSubPathRedirect(t *testing.T) { |
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.
When testing multiple cases like this it's preffered to use table testing like this https://github.com/grafana/grafana/blob/serve-from-sub-path-redirect/pkg/api/plugin_proxy_test.go#L10
Not required thou!
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.
LGTM!
While investigating why some of our test instances in the Alerting team are no longer accessible, I came across this particular PR. Our setup involves two layers of reverse proxies, which seem to be incompatible with the new redirect introduced in this PR. Additionally, I conducted a test using the officially documented configuration and found that it appears to be broken. Given that we have potentially numerous users and customers who are operating with the configuration we documented here, we might need to reconsider this PR. We could possibly revert it, or alternatively, we could place it behind a feature flag—perhaps something akin to a To illustrate my point, I've created a gist with the documented configuration. Notably, switching the Grafana image to |
@torkelo ☝️ |
@JohnnyQQQQ can you describe how?? Without this fix Grafana does not work properly with serve_from_sub_path set to true. If you have serve_from_sub_path true, then Grafana serves from that subpath, so a redirect has to happen for the session cookie to work as the session cookie will include the subpath. If you do url rewrites in the nginx proxy then you should not set serve_from_sub_path to true.
Does your nginx proxy has url rewrites? then you should not set serve_from_sub_path to true The whole point of serve_from_sub_path was so that proxies did not have to do URL rewriting |
@torkelo The main point I am bringing up is that our documentation(https://grafana.com/tutorials/run-grafana-behind-a-proxy/) uses a rewrite for serving with a subpath. We used it internally to set up a few test instances. [server]
domain = example.com
root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana/
serve_from_sub_path = true
So everyone who used this documentation as a starting point will have a bad experience updating to Grafana 10. This configuration "worked" for our use case before merging this PR (see my gist linked in the comment above). I also understand that the fix might be trivial in some cases (i.e., removing the rewrite). Still, many users might not operate Grafana on a day-to-day basis, so this change might be more intrusive than we think, and updating to Grafana 10 might result in a bad experience overall. |
@JohnnyQQQQ yea, the tutorial was updated a year ago, with incorrect instructions grafana/tutorials@3b7e7b4 |
@JohnnyQQQQ yea, I am also worried this could affect others. I don't have any other ideas for how to fix this bug which makes it so that Grafana shows you as signed out even though you are logged in, which is a very annoying bug. |
Thanks @JohnnyQQQQ for your writeup! I believe I've run into the same issue when upgrading to version @torkelo, I'm free to try stuff out if you need a tester. All details are in the referenced GitHub issue above (Rebuild Raspberry PI). edit I see that the tutorial documentation no longer contains the |
The linked to reverse proxy documentation changed. The configuration I orginally applied was incorrect. See: grafana/grafana#66724 Issue: #61
Following up to my previous comment. I removed the |
I almost always run Grafana locally with a subpath and serve_from_subpath set to true (to catch bugs related to subpath). However I have for years been frustrated by the fact that I am always logged out when I access Grafana without the subpath. This is because the session token is set with the subpath and we have no redirect in Grafana that corrects the URL so Grafana serves the index page even when the subpath is missing and the redirect to Grafana with subpath happens in the frontend.
The frontend thinks the user is not signed in as does the backend as it did not see any session token because the URL was outside the path for the session token.
This adds a redirect middleware that redirects all urls that are missing the subpath to a URL that contains it so
The tricky question is how much of a breaking change this is. As before the "serve_with_subpath" actually only strips the subpath from all requests urls so that they match url routes defined without them. So basically both work. So when you have "serve_with_sub_path" set to true and subpath is say "grafana" then all these requests work equally well
http://localhost:3000/metrics (prometheus metrics)
http://localhost:3000/grafana/metrics
etc, for all routes. They are handled identically. With this change, there will be a 301 redirect. So for instances that have serve_with_subpath and access without subpath with clients that don't follow redirect (not sure if there are such clients) then this could be a small breaking change. But would be nice to get help to evaluate that. If that is the case we would need to add a new option to revert to the old behavior of not redirecting.