Skip to content

ccl/sqlproxyccl: handle implicit auth in OpenTenantConnWithToken#77111

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
jaylim-crl:jay/fix-token-auth
Mar 1, 2022
Merged

ccl/sqlproxyccl: handle implicit auth in OpenTenantConnWithToken#77111
craig[bot] merged 1 commit intocockroachdb:masterfrom
jaylim-crl:jay/fix-token-auth

Conversation

@jaylim-crl
Copy link
Copy Markdown
Contributor

@jaylim-crl jaylim-crl commented Feb 27, 2022

Informs #76000. Extracted from #76805.

Previously, we assumed that with the token-based authentication, the server is
ready to accept queries the moment we connect to it. This assumption has been
proved wrong during the integration tests with the forwarder, and there's
an implicit AuthenticateOK step that happens after connecting to the server.
During that time, initial connection data such as ParameterStatus and
BackendKeyData messages will be sent to the client as well. For now, we will
ignore those messages. Once we start implementing query cancellation within
the proxy, that has to be updated to cache the new BackendKeyData.

This commit also fixes a buglet to handle pgwire messages with no body.
pgproto3's Receive methods will still call Next if the body size is 0, and
previously, we were returning an io.EOF error. This commit changes that
behavior to return an empty slice.

Release note: None

Release justification: This fixes two buglets: one that was introduced when we
added token-based authentication support to the proxy in #76417, and another
when we added the interceptors. This is low risk as part of the code is
guarded behind the connection migration feature, which is currently not being
used in production. To add on, CockroachCloud is the only user of sqlproxy.

@jaylim-crl jaylim-crl requested a review from a team as a code owner February 27, 2022 22:22
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

jaylim-crl added a commit to jaylim-crl/cockroach that referenced this pull request Feb 28, 2022
Informs cockroachdb#76000. Builds on top of cockroachdb#77109 and cockroachdb#77111.

This commit completes the connection migration feature in the the forwarder
within sqlproxy. The idea is as described in the RFC.

A couple of new sqlproxy metrics have been added as well:
- proxy.conn_migration.requested
- proxy.conn_migration.accepted
- proxy.conn_migration.rejected
- proxy.conn_migration.success
- proxy.conn_migration.error
- proxy.conn_migration.fail
- proxy.conn_migration.timeout_closed
- proxy.conn_migration.timeout_recoverable

For more details, see metrics.go in the sqlproxyccl package.

Release note: None
@jaylim-crl jaylim-crl force-pushed the jay/fix-token-auth branch 2 times, most recently from 63bd54d to 8b2c82d Compare February 28, 2022 13:17
//
// Discarding messages is fine because this will only be used during connection
// migration with the token-based authentication, and the proxy is the client.
var implicitAuthenticate = func(crdbConn net.Conn) error {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The name "implicitAuthenticate" feels off to me. The method is not authenticating. It's finishing the connection startup process. What do you think of the name: readUntilReady() or readStartupReply()?

Informs cockroachdb#76000. Extracted from cockroachdb#76805.

Previously, we assumed that with the token-based authentication, the server is
ready to accept queries the moment we connect to it. This assumption has been
proved wrong during the integration tests with the forwarder, and there's
an implicit AuthenticateOK step that happens after connecting to the server.
During that time, initial connection data such as ParameterStatus and
BackendKeyData messages will be sent to the client as well. For now, we will
ignore those messages. Once we start implementing query cancellation within
the proxy, that has to be updated to cache the new BackendKeyData.

This commit also fixes a buglet to handle pgwire messages with no body.
pgproto3's Receive methods will still call Next if the body size is 0, and
previously, we were returning an io.EOF error. This commit changes that
behavior to return an empty slice.

Release note: None

Release justification: This fixes two buglets: one that was introduced when we
added token-based authentication support to the proxy in cockroachdb#76417, and another
when we added the interceptors. This is low risk as part of the code is
guarded behind the connection migration feature, which is currently not being
used in production. To add on, CockroachCloud is the only user of sqlproxy.
Copy link
Copy Markdown
Contributor Author

@jaylim-crl jaylim-crl left a comment

Choose a reason for hiding this comment

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

TFTR! I also fixed a small buglet within the chunkreader that I found when working on this.

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


pkg/ccl/sqlproxyccl/authentication.go, line 143 at r1 (raw file):

Previously, JeffSwenson (Jeff Swenson) wrote…

The name "implicitAuthenticate" feels off to me. The method is not authenticating. It's finishing the connection startup process. What do you think of the name: readUntilReady() or readStartupReply()?

Renamed this to readTokenAuthResult based on our discussions. Did not extract the initial connection data part, and left that as a TODO instead given that we're in a stabilization period.

Copy link
Copy Markdown
Collaborator

@jeffswenson jeffswenson left a comment

Choose a reason for hiding this comment

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

LGTM

@jaylim-crl
Copy link
Copy Markdown
Contributor Author

bors r=JeffSwenson

jaylim-crl added a commit to jaylim-crl/cockroach that referenced this pull request Mar 1, 2022
Informs cockroachdb#76000. Builds on top of cockroachdb#77109 and cockroachdb#77111.

This commit completes the connection migration feature in the the forwarder
within sqlproxy. The idea is as described in the RFC.

A couple of new sqlproxy metrics have been added as well:
- proxy.conn_migration.requested
- proxy.conn_migration.success
- proxy.conn_migration.error_fatal
- proxy.conn_migration.error_recoverable
- proxy.conn_migration.attempted
- proxy.conn_migration.protocol_error

For more details, see metrics.go in the sqlproxyccl package.

Release note: none

Release justification: This completes the first half of the connection
migration feature. This is low risk as part of the code is guarded behind the
connection migration feature, which is currently not being used in production.
To add on, CockroachCloud is the only user of sqlproxy.
@craig
Copy link
Copy Markdown
Contributor

craig bot commented Mar 1, 2022

Build failed (retrying...):

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Mar 1, 2022

Build failed (retrying...):

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Mar 1, 2022

Build succeeded:

@craig craig bot merged commit 8eb279a into cockroachdb:master Mar 1, 2022
@jaylim-crl jaylim-crl deleted the jay/fix-token-auth branch March 1, 2022 13:50
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