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

Add Cloud SQL MySQL support #7302

Merged
merged 3 commits into from
Jun 18, 2021
Merged

Add Cloud SQL MySQL support #7302

merged 3 commits into from
Jun 18, 2021

Conversation

r0mant
Copy link
Collaborator

@r0mant r0mant commented Jun 15, 2021

Adds support for connecting to MySQL Cloud SQL databases with database access.

MySQL in Cloud SQL does not support IAM authentication, so instead we're using GCP Cloud SQL Admin API to emulate one-time passwords: before each connect we reset the requested database user's password to a generated token and then connect with it. See linked ticket for more details on the used APIs, if interested.

This approach means that we have to serialize all connections to the same database/user to avoid races with clients updating the password - esp. keeping in mind HA scenario where there may be multiple database services proxying the same database instance.

The nice property about this approach though is that it can be used with regular database users as opposed to Postgres IAM auth where you have to connect with service accounts.

I've also refactored the way database service handles creating cloud clients a bit along the way, to make it a bit cleaner, ensure better separation of concerns and also to make it easier in future to introduce dynamically added/removed databases - previously it would only initialize all clients upon startup, now it initializes required clients on demand and caches them.

Closes #7146.

@r0mant r0mant added database-access Database access related issues and PRs db/mysql MySQL related database access issues labels Jun 15, 2021
@r0mant r0mant added this to the 7.0 "Stockholm" milestone Jun 15, 2021
@r0mant r0mant self-assigned this Jun 15, 2021
Copy link
Contributor

@xacrimon xacrimon left a comment

Choose a reason for hiding this comment

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

LGTM but please beware that I lack experience with most of the stuff here and the Go MySQL stuff so some things may go over my head without me noticing.

lib/srv/db/common/auth.go Outdated Show resolved Hide resolved
lib/srv/db/common/cloud.go Outdated Show resolved Hide resolved
Copy link
Contributor

@russjones russjones left a comment

Choose a reason for hiding this comment

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

Bot.

@r0mant r0mant merged commit 58012cf into master Jun 18, 2021
@r0mant r0mant deleted the roman/gcpmysql branch June 18, 2021 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
database-access Database access related issues and PRs db/mysql MySQL related database access issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MySQL for GCP Cloud SQL support
5 participants