feat: [settings] environment variables as a third settings source#10845
Merged
Conversation
…P#10811) Add environment variables as a third configuration source, in addition to config.php and the system_settings database table. This is primarily useful for container and Kubernetes deployments where settings are injected as environment variables. Variables use the prefix MISP_SETTING_ followed by the setting name with each dot replaced by a double underscore, for example MISP.baseurl maps to MISP_SETTING_MISP__baseurl. Values are cast to bool, null, int, float or JSON, falling back to the raw string. Environment provided settings take precedence over both the database and the config file (env > db > file), so EnvSetting::setGlobalSetting() is applied after the existing sources in AppController and ConfigLoadTask. They are read only: serverSettingsEditValue rejects changes to a setting that is provided via the environment. Unlike the database source, sensitive settings are allowed via the environment, since environment variables are the intended channel for injecting secrets. Redis connection settings are covered automatically as they already live in the settings registry.
1 task
Member
|
That looks clean, thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does it do?
Fixes #10811
Adds environment variables as a third configuration source alongside
config.phpand thesystem_settingsdatabase table. This implementation is explicitly designed for containerized and Kubernetes environments where configuration parameters are dynamically injected at runtime.MISP_SETTING_..) into double underscores (__).Mapping Examples
MISP.baseurlMISP_SETTING_MISP__baseurlSecurity.saltMISP_SETTING_Security__saltPlugin.Enrichment.services_urlMISP_SETTING_Plugin__Enrichment__services_urlHow it works
EnvSettinghelper reads matching environment variables and writes them into theConfigurestore. It executes after the flat-file and database bootstrap routines in bothAppControllerand the CLIConfigLoadTask. Configuration precedence is resolved as follows:serverSettingsEditValuemethod is updated to reject modification attempts via the UI or API, returning a clear error message in line with howcli_onlydirectives are handled.true,false, ornullare cast to their corresponding primitive types, followed by integer and float checks. Valid JSON strings are parsed into associative arrays/objects; otherwise, the value defaults to a raw string. (Numeric strings intended to remain strings should be quoted or JSON-encoded).Security
MISP_SETTING_prefix completely avoids theHTTP_namespace defined by CGI/FastCGI implementations. Verification testing on live web servers confirms that a malicious client attempting to send aMISP_SETTING_...HTTP request header lands in PHP asHTTP_MISP_SETTING_...and is safely ignored by the loader.config.phpon disk.Out of scope
database.phpAdjustments: Database backend connection parameters utilize a distinct initialization routine that runs prior to the settings registry bootstrap. Because the official MISP Docker stack already handles the dynamic templating ofdatabase.phpfrom standard environment variables, updating this specific layer has been deferred as a potential downstream enhancement.Questions
Testing
Validation testing was executed on a local containerized v2.5 stack running under the default configuration baseline.
php -lcompliance across all modified controllers and components; runtime compilation succeeded without performance degradation.MISP_SETTING_MISP__title_text=EnvWinsforcesgetSetting MISP.title_textto correctly returnEnvWins.MISP_SETTING_MISP__redis_database=99successfully overwrites the disk configuration default of13, confirming that environment strings take absolute priority.false) and explicit digits resolve as primitive booleans and integers rather than truthy strings.Security.salt) were successfully parsed and loaded, unregistered structural categories were dropped, and unrelated process environment variables were ignored.setSettingcall against an environment-managed variable returns an explicit modification rejection, while unmanaged keys modify normally.