docs: MM_CONFIG is ignored when storing the configuration in the database
Summary
MM_CONFIG is used to connect to the database initially. Mattermost then reads SqlSettings.Datasource from the configurations table and ignores MM_CONFIG from that point forward. That means two separate configurations need to be manually kept in sync when rotating passwords.
Steps to reproduce
Using Mattermost version 8.0.1 9.4.1:
- Ensure that you’ve pointed to the configuration from the database, not the
config.json. - Validate that
MM_CONFIGandSqlSettings.Datasourceare identical - Change the password for the database user, and adjust
MM_CONFIGaccordingly. - Restart Mattermost
- Observe that the logs indicate that connecting to the database failed.
- Manually adjust
SqlSettings.Datasourcein theconfigurationstable to the new password. - Restart Mattermost
- Observe, that Mattermost starts up fine now.
Expected behavior
There are two alternatives that feel appropriate in this situation:
- When
MM_CONFIGis set,SqlSettings.Datasourceshould always be ignored. - It should be possible to
resetthe fieldSqlSettings.Datasourcewithout it being immediately filled fromMM_CONFIGagain: running the commandmmctl config reset SqlSettings.DataSourceclaims thatValue/s reset successfullybut reading the value immediately after, shows that it has immediately returned
Observed behavior (that appears unintentional)
MM_CONFIG is only used to connect to the database to read the actual database configurations. Then a new connection is started with the connection string from the database it has already connected to.
Possible fixes
Not sure.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 16 (7 by maintainers)
I think we have never explicitly mention that the configuration database and Mattermost application database are two different things. So that means you can use different databases for those, you can even use postgres on one and mysql on the other.
Quoting from @aboukhal
SqlSettings.Datasourceshould be updated first (considering that updating this value is much easier when application is running), then changing theMM_CONFIGto the new DSN.mmctlcommand remotely.mmctl config resetwould just set everything to default value anyway, so it wouldn’t make sense to go with that command.The alternative route can be explicitly setting
MM_SQLSETTINGS_DATASOURCEenvironment variable to override what has been defined in the configuration (whether it’s in a DB, or in a file). This would allow to pass correct DSN to the application.I think this explains more or less what happened to @corang.
The improvement here would be explicitly documenting this. I’m not sure whether this designed to be work on two different databases but it can be useful time to time. cc @agnivade @cwarnermm
This issue introduced a significant problem for us during a database migration. Our aim was to transition to a new DB server.
Initially, we provisioned a new database on a fresh server and copied the MM DB there. Subsequently, we updated the
MM_CONFIGenvironment variable (in the Helm chart) to utilize the new connection string. As a check, we hadn’t yet configured the firewall for the new DB. As expected, MM couldn’t start due to the inability to connect to the new DB. After fixing the firewall, MM successfully started, indicating that everything was in order.However, upon startup, MM retrieved the old credentials from the new DB and established a connection to the old database server. Since we kept the old DB instance running for a few days (call it a good habit…), we didn’t immediately notice that MM wasn’t writing to the new DB until we decommissioned the old DB several days later.
Fortunately, we could restore from a recent backup.
@isacikgoz good point, I will test
MM_SQLSETTINGS_DATASOURCE. If that works, I’ll be happy.@amyblais Saw the note that it wasn’t clear how to reproduce, so I’ll sum up a quick repro here:
Our current workaround is to manually edit the
configurationstable by replacing all old db connection strings with the new/correct one when restoring from a snapshot.Yes, we will upgrade after the holidays.