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

MySQL storage - Take 2 #1485

Merged
merged 2 commits into from
Jul 23, 2019
Merged

MySQL storage - Take 2 #1485

merged 2 commits into from
Jul 23, 2019

Conversation

bonifaido
Copy link
Member

@bonifaido bonifaido commented Jul 13, 2019

This PR tries to continue where #924 dropped off, namely on the work of @pborzenkov, I have changed the following stuff:

  • rebased his branch on the current master
  • compile-time issues and tests fixed
  • Travis based MySQL conformance test enabled (I have also changed to Xenial, which is a good starting point IMHO, but if you are not ok with it I change to MySQL 5.7 the other way)
  • added basic documentation for MySQL storage

Tested with MySQL 5.7 and 8.0.

I know that maintaining a storage backend takes a lot of time, I can offer my help (becoming a maintainer if needed/acceptable).

Copy link
Contributor

@srenatus srenatus left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution, and thanks for picking up where this was left off. (Also thanks to @pborzenkov)

I know that maintaining a storage backend takes a lot of time, I can offer my help (becoming a maintainer if needed/acceptable).

I think that might be a good idea -- @JoelSpeed, what do you think?

}

func testDB(t *testing.T, o opener, withTransactions bool) {
// t.Fatal has a bad habbit of not actually printing the error
Copy link
Contributor

Choose a reason for hiding this comment

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

IIRC the problem is the timeout. If a test times out, the t.Fatal(...) output will be lost. If it doesn't timeout, you'll see it just fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

Should I just change it back? TBH I haven't had issues with Fatal.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's fine, we can revisit that some other time 👍

@@ -61,14 +63,14 @@ func (c *conn) migrate() (int, error) {
}

type migration struct {
stmt string
stmts []string
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this? I haven't dug into this code in a while, but I'd think we could wrap stuff in BEGIN; ... COMMIT;, maybe? What's wrong with the ; concatenation? 🤔I guess it's difficult to spot what's wrong; transactions-wise, I think it should not matter, should it?

Copy link
Member Author

@bonifaido bonifaido Jul 18, 2019

Choose a reason for hiding this comment

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

The issue here is that MySQL driver by default doesn't support multiple statements in one execution, in my original implementation I have used https://github.com/go-sql-driver/mysql#multistatements and this change is not needed. If you think that using that is better I can use that version.

@@ -77,8 +79,8 @@ var migrations = []migration{
public boolean not null,
name text not null,
logo_url text not null
);

);`,
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] If we do this as multiple calls to tx.Exec, we don't need the ending ;, I think.

@@ -38,8 +38,10 @@ func (c *conn) migrate() (int, error) {

Copy link
Contributor

Choose a reason for hiding this comment

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

Correct me if I'm wrong, but if this change has nothing to do with the mysql backend, I'd rather split it off... 😃

Copy link
Member Author

Choose a reason for hiding this comment

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

This is because of the multistatement stuff :)

matrix:
include:
- go: '1.12.x'

env:
global: DEX_POSTGRES_DATABASE=postgres DEX_POSTGRES_USER=postgres DEX_POSTGRES_HOST="localhost" DEX_ETCD_ENDPOINTS=http://localhost:2379 DEX_LDAP_TESTS=1 DEBIAN_FRONTEND=noninteractive DEX_KEYSTONE_URL=http://localhost:5000 DEX_KEYSTONE_ADMIN_URL=http://localhost:35357 DEX_KEYSTONE_ADMIN_USER=demo DEX_KEYSTONE_ADMIN_PASS=DEMO_PASS
global:
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 It's about time this happens.

@bonifaido
Copy link
Member Author

The Postgres backend uses strict SSL verification by default, should this backend have the same semantics?

@srenatus
Copy link
Contributor

The Postgres backend uses strict SSL verification by default, should this backend have the same semantics?

I think that would be fair. 🤔

@bonifaido
Copy link
Member Author

I made MySQL tls=true default, which the strictest available option for the MySQL Go driver.

@srenatus
Copy link
Contributor

@bonifaido would you mind squashing these? maybe one commit per author?

pborzenkov and others added 2 commits July 23, 2019 14:26
It will be shared by both Postgres and MySQL configs.

Signed-off-by: Pavel Borzenkov <[email protected]>
@bonifaido
Copy link
Member Author

bonifaido commented Jul 23, 2019

Rebase done! 👍

Copy link
Contributor

@srenatus srenatus left a comment

Choose a reason for hiding this comment

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

Thank you, @pborzenkov and @bonifaido! 🎉 👏

@srenatus srenatus merged commit bc27a61 into dexidp:master Jul 23, 2019
@bonifaido bonifaido deleted the mysql-storage branch July 23, 2019 13:25
mmrath pushed a commit to mmrath/dex that referenced this pull request Sep 2, 2019
@forsberg
Copy link

Question: Is there anything that specifically requires MySQL 5.7, or would 5.6 work?

I'd like to run it against an Amazon Aurora Serverless database, and they claim they are compatible with MySQL 5.6.

@bonifaido
Copy link
Member Author

bonifaido commented Sep 23, 2019

Hi @forsberg, the only issue that comes into my mind is the transaction_isolation system variable
renaming issue (I just recompiled the code with tx_isolation and it works fine on MySQL 5.6):

https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_transaction_isolation

Note
transaction_isolation was added in MySQL 5.7.20 as an alias for tx_isolation, which is now deprecated and is removed in MySQL 8.0. Applications should be adjusted to use transaction_isolation in preference to tx_isolation.

So we need to add some kind of logic to detect MySQL 5.6 and use tx_isolation instead of transaction_isolation, or add it explicitly in the config. I'm checking what is possible right now with the driver.

But, I just checked and AWS Aurora supports 5.7 today: https://aws.amazon.com/about-aws/whats-new/2018/02/amazon-aurora-is-compatible-with-mysql-5-7/

It would be nice to run some tests on Aurora first since they say that SERIALIZABLE isolation level is not supported, but I have no idea if it is or not, and that is a hard requirement by Dex currently, please see: #1370 (comment)

@bonifaido bonifaido self-assigned this Sep 23, 2019
@bonifaido
Copy link
Member Author

Okay, I just created an AWS Aurora instance for a quick check with MySQL 5.7 (Aurora version of the db was 2.04.6) and the transaction_isolation variable is still unavailable, probably this version is not MySQL 5.7.20.

@bonifaido
Copy link
Member Author

#1550

@forsberg
Copy link

AWS Aurora does indeed support what they call 5.7, but AWS Aurora Serverless (where you don't have to run instances yourself) only support 5.6. This is pretty hard to find in the documentation, but is documented in the FAQ.

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.

4 participants