From 47b3491f3ac376caae5fa4fcad02ea398930890b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Horva=CC=81th=20Ma=CC=81te=CC=81?= Date: Thu, 5 Jul 2018 23:50:24 +0200 Subject: [PATCH 1/4] Redis-custom-pass --- .devilbox/www/config.php | 8 +++++++- .devilbox/www/include/lib/container/Redis.php | 3 +++ docker-compose.yml | 6 ++++++ env-example | 5 +++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/.devilbox/www/config.php b/.devilbox/www/config.php index 0c9f6850..d6579a74 100644 --- a/.devilbox/www/config.php +++ b/.devilbox/www/config.php @@ -128,7 +128,13 @@ function loadClass($class) { case 'Redis': loadFile($class, $cnt_dir); - $_LOADED_LIBS[$class] = \devilbox\Redis::getInstance($GLOBALS['REDIS_HOST_NAME']); + if(loadClass('Helper')->getEnv('REDIS_ROOT_PASSWORD') == ''){ + $_LOADED_LIBS[$class] = \devilbox\Redis::getInstance($GLOBALS['REDIS_HOST_NAME']); + }else{ + $_LOADED_LIBS[$class] = \devilbox\Redis::getInstance($GLOBALS['REDIS_HOST_NAME'], array( + 'pass' => loadClass('Helper')->getEnv('REDIS_ROOT_PASSWORD'), + )); + } break; case 'Memcd': diff --git a/.devilbox/www/include/lib/container/Redis.php b/.devilbox/www/include/lib/container/Redis.php index 6d2334f9..e58e000e 100644 --- a/.devilbox/www/include/lib/container/Redis.php +++ b/.devilbox/www/include/lib/container/Redis.php @@ -44,6 +44,9 @@ class Redis extends BaseClass implements BaseInterface $this->setConnectErrno(1); //loadClass('Logger')->error($this->_connect_error); } else { + if(array_key_exists('pass', $data)){ + $redis->auth($data['pass']); + } $redis->set('devilbox-version', $GLOBALS['DEVILBOX_VERSION'].' ('.$GLOBALS['DEVILBOX_DATE'].')'); $this->_redis = $redis; } diff --git a/docker-compose.yml b/docker-compose.yml index 41547f63..bfb63296 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -394,6 +394,12 @@ services: # ------------------------------------------------------------ redis: image: redis:${REDIS_SERVER:-3.2} + + # REDIS CUSTOM PASSWORD SETUP + #comment out the following 3 lines if you want to set a custom redis password, also set the redis pass variable in .env + #command: redis-server --requirepass ${REDIS_ROOT_PASSWORD} + #environment: + # - ALLOW_EMPTY_PASSWORD=yes ports: # [local-machine:]local-port:docker-port diff --git a/env-example b/env-example index d2956599..c333afe2 100644 --- a/env-example +++ b/env-example @@ -541,6 +541,11 @@ HOST_PORT_PGSQL=5432 ### HOST_PORT_REDIS=6379 +### +### Comment out to set the redis custom password also, in docker-compose.yml comment out the REDIS CUSTOM PASSWORD SETUP section +### +#REDIS_ROOT_PASSWORD=root + ################################################################################ From 32592b03dc89868b08aecd293390d2e5fe5128d6 Mon Sep 17 00:00:00 2001 From: cytopia Date: Sat, 11 Aug 2018 13:50:21 +0200 Subject: [PATCH 2/4] Replace Redis password option with Redis startup options to make it more dynamic --- .devilbox/www/config.php | 22 +++++++++++++++---- .devilbox/www/include/lib/container/Redis.php | 2 +- docker-compose.yml | 11 +++++----- env-example | 16 ++++++++++++-- 4 files changed, 38 insertions(+), 13 deletions(-) diff --git a/.devilbox/www/config.php b/.devilbox/www/config.php index d6579a74..19fd8ad1 100644 --- a/.devilbox/www/config.php +++ b/.devilbox/www/config.php @@ -127,12 +127,26 @@ function loadClass($class) { break; case 'Redis': + + // Check if redis is using a password + $REDIS_ROOT_PASSWORD = ''; + + $_REDIS_ARGS = loadClass('Helper')->getEnv('REDIS_ARGS'); + $_REDIS_PASS = preg_split("/--requirepass\s+/", $_REDIS_ARGS); + if (is_array($_REDIS_PASS) && count($_REDIS_PASS)) { + // In case the option is specified multiple times, use the last effective one. + $_REDIS_PASS = $_REDIS_PASS[count($_REDIS_PASS)-1]; + if (strlen($_REDIS_PASS) > 0) { + $REDIS_ROOT_PASSWORD = $_REDIS_PASS; + } + } + loadFile($class, $cnt_dir); - if(loadClass('Helper')->getEnv('REDIS_ROOT_PASSWORD') == ''){ + if ($REDIS_ROOT_PASSWORD == '') { $_LOADED_LIBS[$class] = \devilbox\Redis::getInstance($GLOBALS['REDIS_HOST_NAME']); - }else{ + } else { $_LOADED_LIBS[$class] = \devilbox\Redis::getInstance($GLOBALS['REDIS_HOST_NAME'], array( - 'pass' => loadClass('Helper')->getEnv('REDIS_ROOT_PASSWORD'), + 'pass' => $REDIS_ROOT_PASSWORD, )); } break; @@ -149,7 +163,7 @@ function loadClass($class) { // Get optional docker classes default: - // Redis + // Unknown class exit('Class does not exist: '.$class); } return $_LOADED_LIBS[$class]; diff --git a/.devilbox/www/include/lib/container/Redis.php b/.devilbox/www/include/lib/container/Redis.php index e58e000e..078bd322 100644 --- a/.devilbox/www/include/lib/container/Redis.php +++ b/.devilbox/www/include/lib/container/Redis.php @@ -44,7 +44,7 @@ class Redis extends BaseClass implements BaseInterface $this->setConnectErrno(1); //loadClass('Logger')->error($this->_connect_error); } else { - if(array_key_exists('pass', $data)){ + if (array_key_exists('pass', $data)) { $redis->auth($data['pass']); } $redis->set('devilbox-version', $GLOBALS['DEVILBOX_VERSION'].' ('.$GLOBALS['DEVILBOX_DATE'].')'); diff --git a/docker-compose.yml b/docker-compose.yml index a5156ab6..08206056 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -402,12 +402,11 @@ services: # ------------------------------------------------------------ redis: image: redis:${REDIS_SERVER:-3.2} - - # REDIS CUSTOM PASSWORD SETUP - #comment out the following 3 lines if you want to set a custom redis password, also set the redis pass variable in .env - #command: redis-server --requirepass ${REDIS_ROOT_PASSWORD} - #environment: - # - ALLOW_EMPTY_PASSWORD=yes + + # Apply custom arguments to redis startup + command: redis-server ${REDIS_ARGS:- } + environment: + - REDIS_ARGS=${REDIS_ARGS:- } ports: # [local-machine:]local-port:docker-port diff --git a/env-example b/env-example index 21ef5762..5fd1efbc 100644 --- a/env-example +++ b/env-example @@ -576,10 +576,22 @@ HOST_PORT_PGSQL=5432 ### HOST_PORT_REDIS=6379 + ### -### Comment out to set the redis custom password also, in docker-compose.yml comment out the REDIS CUSTOM PASSWORD SETUP section +### Custom startup arguments ### -#REDIS_ROOT_PASSWORD=root +### Apply custom startup arguments to redis +### +### Example: Password protection +### Add password protection to the Redis server by specifying it should +### require a password. +### Note: Do not add quotes or spaces to the password +### +### REDIS_ARGS=--requirepass my-redis-root-password +### +### +REDIS_ARGS= +#REDIS_ARGS=--requirepass my-redis-root-password From b0f43a2077e76359867f91a51c040dffc7b0ca3a Mon Sep 17 00:00:00 2001 From: cytopia Date: Sat, 11 Aug 2018 22:42:19 +0200 Subject: [PATCH 3/4] Documentation: Redis startup parameter --- docs/configuration-files/env-file.rst | 41 +++++++++++++++++++++++++++ env-example | 5 +++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/docs/configuration-files/env-file.rst b/docs/configuration-files/env-file.rst index 460d5a0b..91d3ba74 100644 --- a/docs/configuration-files/env-file.rst +++ b/docs/configuration-files/env-file.rst @@ -1542,6 +1542,47 @@ connect to PostgreSQL and will not be able to display information inside the bun Keep this variable in sync with the actual PostgreSQL password. +.. _env_redis: + +Redis +----- + +REDIS_ARGS +^^^^^^^^^^ + +This option lets you add extra startup parameters to Redis. This could include adding a password +protection to Redis or increasing its verbosity. + ++-------------------------+------------------------------------------+----------------+ +| Name | Allowed values | Default value | ++=========================+==========================================+================+ +| ``REDIS_ARGS`` | valid ``redis-server`` startup parameter | empty | ++-------------------------+------------------------------------------+----------------+ + +Example: Adding password protection +""""""""""""""""""""""""""""""""""" + +.. code-block:: bash + + REDIS_ARGS=--requirepass my-redis-root-password + +.. important:: Do not quote the password and do not use spaces inside the password. + +Example: Increasing verbosity +""""""""""""""""""""""""""""" + +.. code-block:: bash + + REDIS_ARGS=--loglevel verbose + +Example: Combining options +"""""""""""""""""""""""""" + +.. code-block:: bash + + REDIS_ARGS=--loglevel verbose --requirepass my-redis-root-password + + Bind ---- diff --git a/env-example b/env-example index 5fd1efbc..886cf81b 100644 --- a/env-example +++ b/env-example @@ -589,9 +589,12 @@ HOST_PORT_REDIS=6379 ### ### REDIS_ARGS=--requirepass my-redis-root-password ### +### Example: Verbosity +### +### REDIS_ARGS=--loglevel verbose ### REDIS_ARGS= -#REDIS_ARGS=--requirepass my-redis-root-password +#REDIS_ARGS=--loglevel verbose --requirepass my-redis-root-password From 8df3ed5d8f9d01f9c4a2e22c72a6ca7041fcf506 Mon Sep 17 00:00:00 2001 From: cytopia Date: Sat, 11 Aug 2018 23:24:11 +0200 Subject: [PATCH 4/4] Fix linkcheck --- docs/conf.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 972a54d3..fc4a240a 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -96,7 +96,8 @@ rst_epilog = """ linkcheck_ignore = [ r'http(s)?://localhost(/)?.*', r'http(s)?://127\.0\.0\.1(/)?.*', - r'http(s)?://.+\.loc$' + r'http(s)?://.+\.loc$', + r'http(s)?://.+\.loc/.+$' ] linkcheck_retries = 5 linkcheck_timeout = 60