Skip to content

Commit 0c80f47

Browse files
judyjosephraphaelt-nvidia
authored andcommitted
[sonic-cfggen]: Use unix socket when reading from DB only if we are using sudo. (sonic-net#7002)
Closes issue sonic-net#6982. The issue was root caused as we were using the unix_socket for reading from DB as a default mechanism (sonic-net#5250). The redis unix socket is created as follows. admin@str--acs-1:~$ ls -lrt /var/run/redis/redis.sock srwxrw---- 1 root redis 0 Mar 6 01:57 /var/run/redis/redis.sock So it used to work fine for the user "root" or if user is part of redis group ( admin was made part of redis group by default ) Check if the user is with sudo permissions then use the redis unix socket, else fallback to tcp socket.
1 parent 433a4f4 commit 0c80f47

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/sonic-config-engine/sonic-cfggen

+3-2
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,11 @@ def main():
350350
deep_update(data, json.loads(args.additional_data))
351351

352352
if args.from_db:
353+
use_unix_sock = True if os.getuid() == 0 else False
353354
if args.namespace is None:
354-
configdb = ConfigDBPipeConnector(use_unix_socket_path=True, **db_kwargs)
355+
configdb = ConfigDBPipeConnector(use_unix_socket_path=use_unix_sock, **db_kwargs)
355356
else:
356-
configdb = ConfigDBPipeConnector(use_unix_socket_path=True, namespace=args.namespace, **db_kwargs)
357+
configdb = ConfigDBPipeConnector(use_unix_socket_path=use_unix_sock, namespace=args.namespace, **db_kwargs)
357358

358359
configdb.connect()
359360
deep_update(data, FormatConverter.db_to_output(configdb.get_config()))

0 commit comments

Comments
 (0)