Skip to content

Commit

Permalink
use redis password auth check
Browse files Browse the repository at this point in the history
fix bug in redis password

add REDIS_PASSWORD variable in admin
  • Loading branch information
luqin committed May 19, 2020
1 parent 6d1d3aa commit b7f87af
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions scripts/kubernetes/.env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export ADMIN_HOST=singa-auto-admin
export ADMIN_PORT=3000
export REDIS_HOST=singa-auto-redis
export REDIS_PORT=6379
export REDIS_PASSWORD=singa_auto
export PREDICTOR_PORT=3003
export WEB_ADMIN_HOST=singa-auto-admin-web
export ZOOKEEPER_HOST=singa-auto-zookeeper
Expand Down
9 changes: 7 additions & 2 deletions scripts/kubernetes/create_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
DB_DIR_PATH = sys.argv[51]
INGRESS_NAME = sys.argv[52]
INGRESS_EXT_PORT = sys.argv[53]
REDIS_PASSWORD = sys.argv[54]

#zk service
content = {}
Expand Down Expand Up @@ -275,9 +276,12 @@
container = {}
container.setdefault('name', REDIS_HOST)
container.setdefault('image', IMAGE_REDIS)
template.setdefault('spec', {'containers': [container]})
container.setdefault('args', ['--appendonly','yes', "--requirepass", REDIS_PASSWORD])
# volumes = {}
# volumes.setdefault('name', 'redis-data')
# volumes.setdefault('nfs', {'server': RAFIKI_ADDR, 'path': HOST_WORKDIR_PATH + '/database/redis'})
template.setdefault('spec', {'containers': [container] })
with open('{}/scripts/kubernetes/start_redis_deployment.json'.format(PYTHONPATH), 'w') as f:

f.write(json.dumps(content, indent=4))

#admin deployment
Expand Down Expand Up @@ -327,6 +331,7 @@
env.append({'name': 'ADMIN_PORT', 'value': ADMIN_PORT})
env.append({'name': 'REDIS_HOST', 'value': REDIS_HOST})
env.append({'name': 'REDIS_PORT', 'value': REDIS_PORT})
env.append({'name': 'REDIS_PASSWORD', 'value': REDIS_PASSWORD})
env.append({'name': 'KAFKA_HOST', 'value': KAFKA_HOST})
env.append({'name': 'KAFKA_PORT', 'value': KAFKA_PORT})
env.append({'name': 'PREDICTOR_PORT', 'value': PREDICTOR_PORT})
Expand Down
3 changes: 2 additions & 1 deletion scripts/kubernetes/generate_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,5 @@ $CONTAINER_MODE \
$CLUSTER_MODE \
$DB_DIR_PATH \
$INGRESS_NAME \
$INGRESS_EXT_PORT
$INGRESS_EXT_PORT \
$REDIS_PASSWORD
2 changes: 1 addition & 1 deletion singa_auto/admin/services_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ServiceDeploymentError(Exception):
ENVIRONMENT_VARIABLES_AUTOFORWARD = [
'POSTGRES_HOST', 'POSTGRES_PORT', 'POSTGRES_USER', 'POSTGRES_PASSWORD', 'POSTGRES_DB',
'SUPERADMIN_PASSWORD',
'REDIS_HOST', 'REDIS_PORT',
'REDIS_HOST', 'REDIS_PORT', 'REDIS_PASSWORD',
'ADMIN_HOST', 'ADMIN_PORT',
'DATA_DIR_PATH', 'LOGS_DIR_PATH', 'PARAMS_DIR_PATH',
'KAFKA_HOST', 'KAFKA_PORT',
Expand Down
7 changes: 4 additions & 3 deletions singa_auto/redis/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import time
import logging
import msgpack
import os

logger = logging.getLogger(__name__)

Expand All @@ -47,7 +48,7 @@ def __init__(
self._uid = str(
uuid.uuid4()) # Process identifier for distributed locking
self._namespace = namespace
self._redis = self._make_redis_client(redis_host, redis_port)
self._redis = self._make_redis_client(redis_host, redis_port, os.environ.get('REDIS_PASSWORD', None))

def acquire_lock(self):
lock_value = self._uid
Expand Down Expand Up @@ -141,12 +142,12 @@ def _decode_value(self, value):
def _get_redis_name(self, name):
return '{}:{}'.format(self._namespace, name)

def _make_redis_client(self, host, port):
def _make_redis_client(self, host, port, passwd):
if host is not None and port is not None:
import redis
from redis import ConnectionPool
from redis import StrictRedis
cache_connection_url = 'redis://{}:{}'.format(host, port)
cache_connection_url = 'redis://:{}@{}:{}'.format(passwd, host, port)
connection_pool = ConnectionPool.from_url(cache_connection_url)
client = StrictRedis(connection_pool=connection_pool,
decode_responses=True)
Expand Down

0 comments on commit b7f87af

Please sign in to comment.