Skip to content

Commit b20e678

Browse files
judyjosephabdosi
authored andcommitted
[sonic-cfggen]: Use unix socket when reading from DB only if we are using sudo. (#7002)
Closes issue #6982. The issue was root caused as we were using the unix_socket for reading from DB as a default mechanism (#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 b73d5a6 commit b20e678

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
@@ -329,10 +329,11 @@ def main():
329329
deep_update(data, json.loads(args.additional_data))
330330

331331
if args.from_db:
332+
use_unix_sock = True if os.getuid() == 0 else False
332333
if args.namespace is None:
333-
configdb = ConfigDBPipeConnector(use_unix_socket_path=True, **db_kwargs)
334+
configdb = ConfigDBPipeConnector(use_unix_socket_path=use_unix_sock, **db_kwargs)
334335
else:
335-
configdb = ConfigDBPipeConnector(use_unix_socket_path=True, namespace=args.namespace, **db_kwargs)
336+
configdb = ConfigDBPipeConnector(use_unix_socket_path=use_unix_sock, namespace=args.namespace, **db_kwargs)
336337

337338
configdb.connect()
338339
deep_update(data, FormatConverter.db_to_output(configdb.get_config()))

0 commit comments

Comments
 (0)