You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is useful for systems where configuration files might be(come) public or
world readable and thus secrets must be kept separately in files. Examples are
NixOS or Docker (secrets).
|`db_type`|`postgresql` or `mariadb`|`postgresql`|
60
+
|`db_host`| your db host |`localhost`|
61
+
|`db_port`| your db port |`5432`|
62
+
|`db_name`| your db name ||
63
+
|`db_user`| your db user ||
64
+
|`db_password`| your db password ||
65
+
|`db_password_file`| path to file containing the db password ||
66
+
|`mariadb_charset`| the charset for mariadb connections |`utf8mb4`|
67
+
68
+
* Values without a default value are mandatory, except that
69
+
* only one of `db_password` or `db_passowrd_file` must be set.
70
+
* Only the first line of the file specified by `db_passowrd_file` is read.
71
+
* Not more than 100 characters of the first line are read.
72
+
* Whitespace-like characters are [stripped](https://www.php.net/manual/en/function.trim.php) from the beginning and end of the read password.
59
73
60
74
### 2. SQL Queries
61
-
that will be used to read/write data
75
+
76
+
that will be used to read/write data.
77
+
62
78
- queries use named parameters. You have to use the exact names as shown in the examples. For
63
79
example, to retrieve the hash for a user, the query named `get_password_hash_for_user` will be
64
80
used. Write your custom SQL query and simply put `:username` where you are referring to
@@ -67,8 +83,7 @@ that will be used to read/write data
67
83
leave the query `get_home` commented. This app will recognize
68
84
this and [communicate](https://docs.nextcloud.com/server/13/developer_manual/api/OCP/UserInterface.html#OCP\UserInterface::implementsActions) to Nextcloud that this feature is not available.
69
85
- `user_exists` and `get_users` are required, the rest is optional.
70
-
- For user authentication (i.e. login) you need at least `get_password_hash_for_user`,
71
-
`user_exists` and `get_users`.
86
+
- For user authentication (i.e. login) you need at least `get_password_hash_for_user`, `user_exists` and `get_users`.
72
87
73
88
- For all queries that read data, only the first column is interpreted.
74
89
- Two queries require a little bit of attention:
@@ -84,7 +99,9 @@ that will be used to read/write data
84
99
[prepare()](http://php.net/manual/en/pdo.prepare.php) method of a PDO object.
85
100
86
101
### 3. Hash Algorithm For New Passwords
87
-
used for the creation of new passwords
102
+
103
+
used for the creation of new passwords.
104
+
88
105
- is optional and, if you leave it empty, defaults to `bcrypt` ($2y$).
89
106
- Other supported hash algorithms are MD5-CRYPT, SHA-256-CRYPT, SHA-512-CRYPT, Argon2i and Argon2id.
90
107
The config values are `md5`, `sha256`, `sha512`, `argon2i`, `argon2id` respectively, e.g.
@@ -100,13 +117,15 @@ The config values are `md5`, `sha256`, `sha512`, `argon2i`, `argon2id` respectiv
100
117
101
118
102
119
## Security
120
+
103
121
- Password length is limited to 100 characters to prevent denial of service attacks against the
104
122
web server. Without a limit, malicious users could feed your Nextcloud instance with passwords that have a length of tens of thousands of characters, which could cause a very
105
123
high load due to expensive password hashing operations.
106
124
- The username during user creation (`create_user`) and the display name (`set_display_name`) are
107
125
not limited in length. You should limit this on the db layer.
108
126
109
127
## Troubleshooting
128
+
110
129
-**TL;DR**: check the log file
111
130
- This app has no UI, therefore all error output (exceptions and explicit logs) is written to [Nextcloud's log](https://docs.nextcloud.com/server/20/admin_manual/configuration_server/logging_configuration.html),
112
131
by default */var/www/nextcloud/data/nextcloud.log* or */var/log/syslog*. Log level 3 is sufficient for all non-debug output.
if ($passwordIsSet === $passwordFileIsSet) { // expression is a "not XOR"
151
+
thrownew \UnexpectedValueException('Exactly one of ' . self::CONFIG_KEY_DB_PASSWORD . ' or ' . self::CONFIG_KEY_DB_PASSWORD_FILE . ' must be set (not be empty) in the config.');
152
+
}
153
+
154
+
if ($passwordIsSet) {
155
+
$this->logger->debug("Will use db password specified directly in config.php.");
156
+
return$password;
157
+
}
158
+
159
+
if ($passwordFileIsSet) {
160
+
$this->logger->debug("Will use db password stored in file " . $passwordFilePath). ".";
161
+
$error_message_prefix = "Specified db password file with path {$passwordFilePath}";
162
+
163
+
if (!file_exists($passwordFilePath)) {
164
+
thrownew \UnexpectedValueException("{$error_message_prefix} does not exist or is not accessible.");
165
+
}
166
+
if (is_link($passwordFilePath)) {
167
+
thrownew \UnexpectedValueException("{$error_message_prefix} is a symbolic link, which might be a security problem and is therefore not allowed.");
168
+
}
169
+
if (is_dir($passwordFilePath)) {
170
+
thrownew \UnexpectedValueException("{$error_message_prefix} is a directory but I need a file to read the password.");
171
+
}
172
+
$file = fopen($passwordFilePath, "r");
173
+
if ($file === FALSE) {
174
+
thrownew \UnexpectedValueException("{$error_message_prefix} can not be opened. Maybe insufficient permissions?");
175
+
}
176
+
// + 1 because fgets() reads one less byte than specified and we want to keep the promise of reading 100 bytes
0 commit comments