Add SALT envar for Security.salt setting, with special handling#385
Add SALT envar for Security.salt setting, with special handling#385ostefano merged 2 commits intoMISP:masterfrom
Conversation
|
Related to #384 |
| # encryption key. defaults to empty string | ||
| ENCRYPTION_KEY= | ||
| # salt, mostly vestigial. autogenerated if blank and unset in config.php | ||
| SALT= |
There was a problem hiding this comment.
Not sure from here whether it gets autogenerated each time we start the container?
What happens to redis persisted sessions?
There was a problem hiding this comment.
if we have SALT= as blank, what happens is:
- entrypoint starts, a bunch of stuff happens
- eventually we run
init_minimum_configinconfigure_misp.shwhich will add theSecurity.saltconfiguration directive as blank by setting the default fromminimum_config.defaults.json, only if it does not already exist:
"Security.salt": {
"default_value": "",
"command_args": "-f"
},
- straight after this
configure_misp.shrunsinit_configurationwhich does the new "setSecurity.saltto theSALTenvar, if the envar is not blank". does nothing because it's blank. - MISP starts, sees a blank
Security.saltand generates one, updating the config.
on subsequent container starts, 2 won't run because Security.salt exists, leaving the existing autogenerated salt alone, 3 is still blank so does nothing, and 4 sees a good value so does nothing.
davidz@ocp:~/stuff/misp-docker$ sudo grep salt configs/config.php
davidz@ocp:~/stuff/misp-docker$ grep SALT .env
SALT=
davidz@ocp:~/stuff/misp-docker$ docker compose up -d 2>/dev/null
davidz@ocp:~/stuff/misp-docker$ sudo grep salt configs/config.php
davidz@ocp:~/stuff/misp-docker$ sudo grep salt configs/config.php
'salt' => 'P#fxQ3f*o9lXUBY_pC*U-vQtwiK1?8WG',
davidz@ocp:~/stuff/misp-docker$ docker compose restart misp-core 2>/dev/null
davidz@ocp:~/stuff/misp-docker$ sudo grep salt configs/config.php
'salt' => 'P#fxQ3f*o9lXUBY_pC*U-vQtwiK1?8WG',
If SALT=blah, 1 and 2 still happens, 3 sets Security.salt to blah, 4 sees a good value so nothing happens.
There was a problem hiding this comment.
redis (or whatever session method is used) persisted stuff will only invalidate if the salt changes, which it shouldn't unless you delete it from the config, or set SALT to a value.
This adds the
SALTenvar to the image, to control theSecurity.saltsetting.It took a bit of digging to figure out if
Security.saltdoes anything anymore, but it turns out it at least is used in session handling by CakePHP. I discovered that if I allowed a load balanced HA MISP deployment to have divergedSecurity.saltvalues I would get CSRF issues frequently. If I then converged the values, they would go away.I wanted to be able to have each MISP instance in the HA deployment generate its own identical configs using this project's image, which is currently not possible unless I do something like use EFS to share app/Config between the containers, which leads to other issues such as race conditions with which instance is editing updating the config. For this reason I am adding the SALT envar.
MISP will by default auto-generate a value if the value in the config.php file is blank, but not if the line is absent from the config.php file, in which case it just shits the bed.
The current state of the MISP/misp-docker image is to just set it to "" (blank) in the config file if unset. This leverages MISP internal functionality to rewrite the config file with a nice random value.
Adding this as an envar means that if the envar is blank, it will auto-generate a new value every container start, which isn't great.
As a result, I added a new parameter to the envar json structure called
blank_protectionwhich will do nothing if the envar value is blank. In combination with the existing blank setting of the unset value, this leads to the following:SALT=: If unset inconfig.php, make it blank, otherwise leave it alone. MISP will see the blank and auto-generate a nice value.SALT=1234: Always set salt to1234#SALT=: Equivalent to uncommented blankThe default behaviour is unchanged, and existing salt values will be left alone.