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

pkg/server: fix /demologin to properly redirect to home page #98319

Merged
merged 1 commit into from
Mar 20, 2023

Conversation

abarganier
Copy link
Contributor

With the introduction of the server controller, we introduced a layer between the HTTP handler and the HTTP server. When this was introduced, the logic to attempt a login to all tenants forgot to handle a specific case for /demologin, where the status code is set to a 302 redirect, instead of a 200 status OK.

This broke the redirect piece of the /demologin endpoint.

This patch updates the attemptLoginToAllTenants HTTP handler to properly set the 302 response code in the case where the underlying login function does so on the sessionWriter.

Release note: none

Epic: CRDB-12100

Fixes: #98253

@abarganier abarganier requested review from dhartunian and a team March 9, 2023 18:05
@abarganier abarganier requested a review from a team as a code owner March 9, 2023 18:05
@blathers-crl
Copy link

blathers-crl bot commented Mar 9, 2023

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

// In the case of /demologin, we want to redirect to the home page.
// If we get back a cookie along with a 302, be sure to transfer that
// into the ResponseWriter later.
if sw.code == 302 {
Copy link
Contributor

Choose a reason for hiding this comment

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

http.StatusTemporaryRedirect?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

http.StatusTemporaryRedirect is assigned to code 307. Seems like that's what we should be using anyway, so I went ahead and switched both places (the /demologin handler, and the quoted code above) to use http.StatusTemporaryRedirect.

@@ -217,7 +224,12 @@ func (c *serverController) attemptLoginToAllTenants() http.Handler {
return
}
}
w.WriteHeader(http.StatusOK)
if redirect {
w.Header()["Location"] = []string{"/"}
Copy link
Contributor

Choose a reason for hiding this comment

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

http.Redirect().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

http.Redirect(w, r, "/", http.StatusTemporaryRedirect) worked well. Thanks!

@abarganier abarganier requested a review from a team as a code owner March 14, 2023 19:19
@abarganier abarganier requested a review from knz March 14, 2023 19:22
Copy link
Collaborator

@dhartunian dhartunian left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 2 files at r2.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @knz)


pkg/server/server_controller_http.go line 228 at r1 (raw file):

Previously, abarganier (Alex Barganier) wrote…

http.Redirect(w, r, "/", http.StatusTemporaryRedirect) worked well. Thanks!

Should we also grab the Location from the fanout response?

Copy link
Contributor Author

@abarganier abarganier left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @knz)


pkg/server/server_controller_http.go line 228 at r1 (raw file):

Previously, dhartunian (David Hartunian) wrote…

Should we also grab the Location from the fanout response?

Good idea! Added this, with a default value of /

With the introduction of the server controller, we introduced a
layer between the HTTP handler and the HTTP server. When this
was introduced, the logic to attempt a login to all tenants
forgot to handle the case for `/demologin` where the status
code is set to a 307 redirect, instead of a 200 status OK.

This broke the redirect piece of the `/demologin` endpoint.

This patch updates the `attemptLoginToAllTenants` HTTP handler
to properly set the 307 response code in the case where the
underlying login function does so on the sessionWriter.

Release note: none
@abarganier abarganier requested a review from dhartunian March 16, 2023 18:46
Copy link
Collaborator

@dhartunian dhartunian left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 1 of 1 files at r4, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @knz)

@abarganier
Copy link
Contributor Author

TFTR!

bors r=dhartunian

@craig
Copy link
Contributor

craig bot commented Mar 17, 2023

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Mar 17, 2023

Build failed:

@aadityasondhi
Copy link
Collaborator

sorry for the noise, wrong PR

@abarganier
Copy link
Contributor Author

bors retry

@craig
Copy link
Contributor

craig bot commented Mar 20, 2023

Build succeeded:

@craig craig bot merged commit ea389ff into cockroachdb:master Mar 20, 2023
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.

pkg/server: /demologin doesn't redirect, doesn't provide multitenant-encoded cookie
5 participants