Skip to content

Commit fdb9d02

Browse files
authored
[redis] Add redis Group And Grant Read/Write Access to Members (#5289)
sonic-cfggen is now using Unix Domain Socket for Redis DB. The socket is created using root account. Subsequently, services that are started as admin fails to start. This PR creates redis group and add admin user to redis group. It also grants read/write access on redis.sock for redis group members. signed-off-by: Tamer Ahmed <[email protected]>
1 parent dd908c2 commit fdb9d02

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

build_debian.sh

+5-2
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,12 @@ sudo cp files/docker/docker.service.conf $_
242242
## Fix systemd race between docker and containerd
243243
sudo sed -i '/After=/s/$/ containerd.service/' $FILESYSTEM_ROOT/lib/systemd/system/docker.service
244244

245+
## Create redis group
246+
sudo LANG=C chroot $FILESYSTEM_ROOT groupadd -f redis
247+
245248
## Create default user
246-
## Note: user should be in the group with the same name, and also in sudo/docker group
247-
sudo LANG=C chroot $FILESYSTEM_ROOT useradd -G sudo,docker $USERNAME -c "$DEFAULT_USERINFO" -m -s /bin/bash
249+
## Note: user should be in the group with the same name, and also in sudo/docker/redis groups
250+
sudo LANG=C chroot $FILESYSTEM_ROOT useradd -G sudo,docker,redis $USERNAME -c "$DEFAULT_USERINFO" -m -s /bin/bash
248251
## Create password for the default user
249252
echo "$USERNAME:$PASSWORD" | sudo LANG=C chroot $FILESYSTEM_ROOT chpasswd
250253

files/build_templates/docker_image_ctl.j2

+5-7
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ function postStartAction()
131131
/usr/bin/db_migrator.py -o migrate
132132
fi
133133
fi
134+
# Add redis UDS to the redis group and give read/write access to the group
135+
REDIS_SOCK="/var/run/redis${DEV}/redis.sock"
136+
chgrp -f redis $REDIS_SOCK && chmod -f 0760 $REDIS_SOCK
134137
{%- elif docker_container_name == "swss" %}
135138
docker exec swss$DEV rm -f /ready # remove cruft
136139
if [[ "$BOOT_TYPE" == "fast" ]] && [[ -d /host/fast-reboot ]]; then
@@ -354,13 +357,8 @@ NAMESPACE_PREFIX="asic"
354357
if [ "$DEV" ]; then
355358
NET_NS="$NAMESPACE_PREFIX$DEV" #name of the network namespace
356359

357-
# While using -n (namespace) argument, sonic-cfggen/sonic-db-cli uses redis UNIX socket
358-
# for accessing redis DB in a namespace. This unix socket has permission restrictions since
359-
# it is created by systemd database.servce started with [User] as [root].
360-
# sudo is needed here for services which are started by systemd with [User] as [admin]
361-
# and needs to override this unix socket permission restrictions.
362-
SONIC_CFGGEN="sudo sonic-cfggen -n $NET_NS"
363-
SONIC_DB_CLI="sudo sonic-db-cli -n $NET_NS"
360+
SONIC_CFGGEN="sonic-cfggen -n $NET_NS"
361+
SONIC_DB_CLI="sonic-db-cli -n $NET_NS"
364362
else
365363
NET_NS=""
366364
SONIC_CFGGEN="sonic-cfggen"

0 commit comments

Comments
 (0)