[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.
This commit is contained in:
parent
b73d5a659e
commit
b20e67819f
@ -329,10 +329,11 @@ def main():
|
||||
deep_update(data, json.loads(args.additional_data))
|
||||
|
||||
if args.from_db:
|
||||
use_unix_sock = True if os.getuid() == 0 else False
|
||||
if args.namespace is None:
|
||||
configdb = ConfigDBPipeConnector(use_unix_socket_path=True, **db_kwargs)
|
||||
configdb = ConfigDBPipeConnector(use_unix_socket_path=use_unix_sock, **db_kwargs)
|
||||
else:
|
||||
configdb = ConfigDBPipeConnector(use_unix_socket_path=True, namespace=args.namespace, **db_kwargs)
|
||||
configdb = ConfigDBPipeConnector(use_unix_socket_path=use_unix_sock, namespace=args.namespace, **db_kwargs)
|
||||
|
||||
configdb.connect()
|
||||
deep_update(data, FormatConverter.db_to_output(configdb.get_config()))
|
||||
|
Loading…
Reference in New Issue
Block a user