Skip to content

Commit 74af803

Browse files
Merge pull request #55258 from nextcloud/backport/55170/stable30
[stable30] feat(db): add SSL/TLS support for PostgreSQL
2 parents 936da13 + 8fbd763 commit 74af803

File tree

3 files changed

+59
-8
lines changed

3 files changed

+59
-8
lines changed

config/config.sample.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@
502502

503503
/**
504504
* Enable SMTP class debugging.
505-
* NOTE: ``loglevel`` will likely need to be adjusted too. See docs:
505+
* NOTE: ``loglevel`` will likely need to be adjusted too. See docs:
506506
* https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/email_configuration.html#enabling-debug-mode
507507
*
508508
* Defaults to ``false``
@@ -663,7 +663,7 @@
663663
* are generated within Nextcloud using any kind of command line tools (cron or
664664
* occ). The value should contain the full base URL:
665665
* ``https://www.example.com/nextcloud``
666-
* Please make sure to set the value to the URL that your users mainly use to access this Nextcloud.
666+
* Please make sure to set the value to the URL that your users mainly use to access this Nextcloud.
667667
* Otherwise there might be problems with the URL generation via cron.
668668
*
669669
* Defaults to ``''`` (empty string)
@@ -1323,18 +1323,18 @@
13231323
/**
13241324
* custom path for ffmpeg binary
13251325
*
1326-
* Defaults to ``null`` and falls back to searching ``avconv`` and ``ffmpeg``
1326+
* Defaults to ``null`` and falls back to searching ``avconv`` and ``ffmpeg``
13271327
* in the configured ``PATH`` environment
13281328
*/
13291329
'preview_ffmpeg_path' => '/usr/bin/ffmpeg',
13301330

13311331
/**
13321332
* Set the URL of the Imaginary service to send image previews to.
1333-
* Also requires the ``OC\Preview\Imaginary`` provider to be enabled in the
1334-
* ``enabledPreviewProviders`` array, to create previews for these mimetypes: bmp,
1333+
* Also requires the ``OC\Preview\Imaginary`` provider to be enabled in the
1334+
* ``enabledPreviewProviders`` array, to create previews for these mimetypes: bmp,
13351335
* x-bitmap, png, jpeg, gif, heic, heif, svg+xml, tiff, webp and illustrator.
13361336
*
1337-
* If you want Imaginary to also create preview images from PDF Documents, you
1337+
* If you want Imaginary to also create preview images from PDF Documents, you
13381338
* have to add the ``OC\Preview\ImaginaryPDF`` provider as well.
13391339
*
13401340
* See https://github.com/h2non/imaginary
@@ -1978,6 +1978,17 @@
19781978
*/
19791979
'mysql.collation' => null,
19801980

1981+
/**
1982+
* PostgreSQL SSL connection
1983+
*/
1984+
'pgsql_ssl' => [
1985+
'mode' => '',
1986+
'cert' => '',
1987+
'rootcert' => '',
1988+
'key' => '',
1989+
'crl' => '',
1990+
],
1991+
19811992
/**
19821993
* Database types that are supported for installation.
19831994
*
@@ -2066,9 +2077,9 @@
20662077
/**
20672078
* Deny extensions from being used for filenames.
20682079
* Matching existing files can no longer be updated and in matching folders no files can be created anymore.
2069-
*
2080+
*
20702081
* The '.part' extension is always forbidden, as this is used internally by Nextcloud.
2071-
*
2082+
*
20722083
* Defaults to ``array('.filepart', '.part')``
20732084
*/
20742085
'forbidden_filename_extensions' => ['.part', '.filepart'],

lib/private/DB/ConnectionFactory.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,17 @@ public function createConnectionParams(string $configPrefix = '', array $additio
198198
'tablePrefix' => $connectionParams['tablePrefix']
199199
];
200200

201+
if ($type === 'pgsql') {
202+
$pgsqlSsl = $this->config->getValue('pgsql_ssl', false);
203+
if (is_array($pgsqlSsl)) {
204+
$connectionParams['sslmode'] = $pgsqlSsl['mode'] ?? '';
205+
$connectionParams['sslrootcert'] = $pgsqlSsl['rootcert'] ?? '';
206+
$connectionParams['sslcert'] = $pgsqlSsl['cert'] ?? '';
207+
$connectionParams['sslkey'] = $pgsqlSsl['key'] ?? '';
208+
$connectionParams['sslcrl'] = $pgsqlSsl['crl'] ?? '';
209+
}
210+
}
211+
201212
if ($type === 'mysql' && $this->config->getValue('mysql.utf8mb4', false)) {
202213
$connectionParams['defaultTableOptions'] = [
203214
'collate' => 'utf8mb4_bin',

tests/lib/DB/ConnectionFactoryTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,33 @@ public function testSplitHostFromPortAndSocket($host, array $expected) {
4040

4141
$this->assertEquals($expected, self::invokePrivate($factory, 'splitHostFromPortAndSocket', [$host]));
4242
}
43+
44+
public function testPgsqlSslConnection(): void {
45+
/** @var SystemConfig|\PHPUnit\Framework\MockObject\MockObject $config */
46+
$config = $this->createMock(SystemConfig::class);
47+
$config->method('getValue')
48+
->willReturnCallback(function ($key, $default) {
49+
return match ($key) {
50+
'dbtype' => 'pgsql',
51+
'pgsql_ssl' => [
52+
'mode' => 'verify-full',
53+
'cert' => 'client.crt',
54+
'key' => 'client.key',
55+
'crl' => 'client.crl',
56+
'rootcert' => 'rootCA.crt',
57+
],
58+
default => $default,
59+
};
60+
});
61+
$factory = new ConnectionFactory($config);
62+
63+
$params = $factory->createConnectionParams();
64+
65+
$this->assertEquals('pdo_pgsql', $params['driver']);
66+
$this->assertEquals('verify-full', $params['sslmode']);
67+
$this->assertEquals('rootCA.crt', $params['sslrootcert']);
68+
$this->assertEquals('client.crt', $params['sslcert']);
69+
$this->assertEquals('client.key', $params['sslkey']);
70+
$this->assertEquals('client.crl', $params['sslcrl']);
71+
}
4372
}

0 commit comments

Comments
 (0)