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

admin: statement diagnostics uses correct auth helpers #99051

Merged
merged 1 commit into from
Mar 21, 2023

Conversation

dhartunian
Copy link
Collaborator

Previously, the statement diagnostics HTTP handler was initialized using the incorrect ctx value. This caused the HTTP request context to not be correctly handed down to the handler. Furthermore, the call to userFromIncomingRPCContext was incorrect in this scenario since it relied on a gRPC context being populated with HTTP session information, which did not exist. That code sets a root user when context is missing because the gRPC handlers are used for inter-node communication and HTTP with the DB console and external tools.

This commit attaches the request context to the diagnostics bundle handler correctly, and amends the authorization code to use userFromHTTPAuthInfoContext which correctly reads the session cookie info from the request (like many api/v2 handlers do since those exist outside the gRPC infrastructure).

Resolves #99049

Epic: None

Release note (security update): Previously, users could gain unauthorized access to statement diagnostic bundles they did not create if they requested the bundle through an HTTP request to /_admin/v1/stmtbundle/<id> and correctly guessed its (non-secret) ID. This change locks down this endpoint behind the usual SQL gating that correctly uses the SQL user in the HTTP session as identified by their cookie.

@dhartunian dhartunian requested a review from a team March 20, 2023 19:44
@dhartunian dhartunian requested a review from a team as a code owner March 20, 2023 19:44
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Previously, the statement diagnostics HTTP handler was initialized using the
incorrect `ctx` value. This caused the HTTP request context to not be correctly
handed down to the handler. Furthermore, the call to
`userFromIncomingRPCContext` was incorrect in this scenario since it relied on
a gRPC context being populated with HTTP session information, which did not
exist. That code sets a `root` user when context is missing because the gRPC
handlers are used for inter-node communication *and* HTTP with the DB console
and external tools.

This commit attaches the request context to the diagnostics bundle handler
correctly, and amends the authorization code to use
`userFromHTTPAuthInfoContext` which correctly reads the session cookie info
from the request (like many `api/v2` handlers do since those exist outside the
gRPC infrastructure).

Resolves cockroachdb#99049

Epic: None

Release note (security update): Previously, users could gain unauthorized
access to statement diagnostic bundles they did not create if they requested
the bundle through an HTTP request to `/_admin/v1/stmtbundle/<id>` and
correctly guessed its (non-secret) ID.  This change locks down this endpoint
behind the usual SQL gating that correctly uses the SQL user in the HTTP
session as identified by their cookie.
@dhartunian dhartunian force-pushed the statement-diagnostics-helpers branch from 23f5b18 to 0db60c5 Compare March 20, 2023 21:21
@dhartunian
Copy link
Collaborator Author

bors r=knz

@craig
Copy link
Contributor

craig bot commented Mar 21, 2023

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Mar 21, 2023

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Mar 21, 2023

Build failed:

@knz
Copy link
Contributor

knz commented Mar 21, 2023

bors r+ single on

@craig
Copy link
Contributor

craig bot commented Mar 21, 2023

Build succeeded:

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.

server: statement diagnostics download endpoint does not correctly validate user auth
3 participants