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

NEW Added MySQL SSL PDO Support (fixes #7077) #7233

Merged
merged 2 commits into from
Aug 3, 2017
Merged

NEW Added MySQL SSL PDO Support (fixes #7077) #7233

merged 2 commits into from
Aug 3, 2017

Conversation

johndalangin
Copy link
Contributor

Modified ConfigureFromEnv.php to parse SS_DATABASE_SSL variables (also added a bit of documentation)
Modified PDOConnector.php to implement variables set in ConfigureFromEnv if exists
Modified install files MySQLDatabaseConfigurationHelper and install.php5 to accept and implement SS_DATABASE_SSL variables set in _ss_environment.php

TODO: Add documentation

Modified ConfigureFromEnv.php to parse SS_DATABASE_SSL variables (also added a bit of documentation)
Modified PDOConnector.php to implement variables set in ConfigureFromEnv if exists
Modified install files MySQLDatabaseConfigurationHelper and install.php5 to accept and implement SS_DATABASE_SSL variables set in _ss_environment.php

TODO: Add documentation
@johndalangin
Copy link
Contributor Author

@dhensby fixes #7077

Thank you.

Copy link
Contributor

@dhensby dhensby left a comment

Choose a reason for hiding this comment

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

Looks good - only thing I'm concerned about is tight coupling to MySQL

@@ -116,6 +124,25 @@
// For SQlite3 memory databases (mainly for testing purposes)
if(defined('SS_DATABASE_MEMORY'))
$databaseConfig["memory"] = SS_DATABASE_MEMORY;

// PDO MySQL SSL parameters
if(defined('SS_DATABASE_CLASS') && SS_DATABASE_CLASS === 'MySQLPDODatabase') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this only for MySQL using PDO or do all PDO drivers support this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now it's only for MySQL using PDO.

@dhensby dhensby requested a review from tractorcow August 2, 2017 14:29
@dhensby
Copy link
Contributor

dhensby commented Aug 2, 2017

I'd like @tractorcow's thoughts, again

@johndalangin
Copy link
Contributor Author

@tractorcow @dhensby Thank you for your prompt response. I checked the contents of /model/connect and it seems that the only 2 DB connectors included by default are MySQLi and MySQLPDO.

I've taken a look at the MySQLi documentation and it seems that there might be a way to implement SSL via the mysqli::ssl_set directive. (http://php.net/manual/en/mysqli.ssl-set.php). I can create another issue and work on this as well.

I don't have any experience working with PostgreSQL or MSSQL with Silverstripe so it might take me a while to get working on an implementation. Maybe we can indicate in the documentation that SSL is only supported on MySQL via MySQLi and PDOMySQL in the mean time so we can push this forward and worry about tight coupling later? I can work on the documentation as well.

Let me know your thoughts.

Thank you.

defined('SS_DATABASE_SSL_CA')
) {

$databaseConfig['ssl_key'] = SS_DATABASE_SSL_KEY;
Copy link
Contributor

Choose a reason for hiding this comment

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

My feeling is that perhaps we should set these for all connectors, and we allow classes that support these options to configure them internally. Otherwise, $databaseConfig will keep these values but will be ignored by unsupported backends.

As it stands I wouldn't be able to support a custom connector with SSL.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Understood. The reason why I encapsulated setting the SSL variables to PDO is because I feared I would break something with the other databases. If the setting the variables will be innocuous for other database, I can remove the condition.

$databaseConfig['ssl_key'] = SS_DATABASE_SSL_KEY;
$databaseConfig['ssl_cert'] = SS_DATABASE_SSL_CERT;
$databaseConfig['ssl_ca'] = SS_DATABASE_SSL_CA;
$databaseConfig['ssl_cipher'] = defined('SS_DATABASE_SSL_CIPHER') ? SS_DATABASE_SSL_CIPHER : 'DHE-RSA-AES256-SHA';
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of setting the default cipher here, let's leave it up to the DB connection to choose it's own default.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noted.

$databaseConfig['ssl_key'] = SS_DATABASE_SSL_KEY;
$databaseConfig['ssl_cert'] = SS_DATABASE_SSL_CERT;
$databaseConfig['ssl_ca'] = SS_DATABASE_SSL_CA;
$databaseConfig['ssl_cipher'] = defined('SS_DATABASE_SSL_CIPHER') ? SS_DATABASE_SSL_CIPHER : 'DHE-RSA-AES256-SHA';
Copy link
Contributor

Choose a reason for hiding this comment

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

Also here, let's leave it blank if not defined, and let the connector choose it's own default.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noted.

$options[PDO::MYSQL_ATTR_SSL_KEY] = $parameters['ssl_key'];
$options[PDO::MYSQL_ATTR_SSL_CERT] =$parameters['ssl_cert'];
$options[PDO::MYSQL_ATTR_SSL_CA] = $parameters['ssl_ca'];
$options[PDO::MYSQL_ATTR_SSL_CIPHER] = $parameters['ssl_cipher'];
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets make this a config rather than hard coding it.

private static $ssl_cipher_default = 'DHE-RSA-AES256-SHA';
// ...
$options[PDO::MYSQL_ATTR_SSL_CIPHER] = $parameters['ssl_cipher'] ?: $this->config()->ssl_cipher_default;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Understood.

@johndalangin
Copy link
Contributor Author

@tractorcow I'll have the changes ready within the day. Thank you for your feedback.

@tractorcow
Copy link
Contributor

That's fine @johndalangin, thanks for the great feature!

@johndalangin
Copy link
Contributor Author

@tractorcow No worries! It's my pleasure to contribute. We've been working with Silverstripe for a couple of years now and we'd love to contribute every change we'd get.

The requested revisions have been pushed. Feel free to take a look and let me know if you have any more comments.

@tractorcow
Copy link
Contributor

I'm happy. @dhensby you have any thoughts or shall we just merge it?

@johndalangin
Copy link
Contributor Author

johndalangin commented Aug 3, 2017

@tractorcow @dhensby Thanks for your feedback! I'll work on the MySQLi connector integration in a separate issue. Do you have a release schedule for the next minor version? I can work on the SSL MySQLi integration by next week but if you need it faster, I can adjust my schedule so we can release both simultaneously.

I'll also do the documentation in a separate issue which will most likely affect Security, Models and Databases, and Configuration.

Let me know if you have concerns.

@dhensby
Copy link
Contributor

dhensby commented Aug 3, 2017

I'm happy

@dhensby dhensby merged commit 723ae37 into silverstripe:3 Aug 3, 2017
@johndalangin johndalangin deleted the 7077-add-mysql-pdo-ssl branch August 3, 2017 10:41
@lerni lerni mentioned this pull request Mar 20, 2019
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