-
Notifications
You must be signed in to change notification settings - Fork 824
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
Conversation
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
There was a problem hiding this 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
conf/ConfigureFromEnv.php
Outdated
@@ -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') { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
I'd like @tractorcow's thoughts, again |
@tractorcow @dhensby Thank you for your prompt response. I checked the contents of I've taken a look at the MySQLi documentation and it seems that there might be a way to implement SSL via the 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. |
conf/ConfigureFromEnv.php
Outdated
defined('SS_DATABASE_SSL_CA') | ||
) { | ||
|
||
$databaseConfig['ssl_key'] = SS_DATABASE_SSL_KEY; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
dev/install/install.php5
Outdated
$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'; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted.
conf/ConfigureFromEnv.php
Outdated
$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'; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted.
model/connect/PDOConnector.php
Outdated
$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']; |
There was a problem hiding this comment.
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;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood.
@tractorcow I'll have the changes ready within the day. Thank you for your feedback. |
That's fine @johndalangin, thanks for the great feature! |
@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. |
I'm happy. @dhensby you have any thoughts or shall we just merge it? |
@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 Let me know if you have concerns. |
I'm happy |
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