ssh工具依赖系统so,和软件包自带依赖加载隔离

This commit is contained in:
zhang_xubo
2024-01-22 14:52:13 +08:00
parent a9ff6b5538
commit e6b90c2452
13 changed files with 69 additions and 22 deletions

View File

@ -53,7 +53,9 @@ from gspylib.common.copy_python_lib import copy_lib
from base_utils.os.user_util import UserUtil
DefaultValue.doConfigForParamiko()
copy_lib()
SYSTEM_SSH_ENV = "export LD_LIBRARY_PATH=/usr/lib64"
try:
import paramiko
@ -761,7 +763,7 @@ General options:
output: True/False, hostname
"""
bashrc_file = os.path.join(pwd.getpwuid(os.getuid()).pw_dir, ".bashrc")
cmd = 'source %s;ssh -n %s %s true' % (bashrc_file,
cmd = 'source %s;%s;/usr/bin/ssh -n %s %s true' % (bashrc_file, SYSTEM_SSH_ENV,
DefaultValue.SSH_OPTION, hostname)
(status, output) = subprocess.getstatusoutput(cmd)
if status != 0:
@ -782,7 +784,7 @@ General options:
for(key, value) in list(result.items()):
hostnameList.append(value)
for hostname in hostnameList:
cmd = 'ssh-keyscan -t ed25519 %s >> %s ' % (hostname, self.known_hosts_fname)
cmd = '%s;/usr/bin/ssh-keyscan -t ed25519 %s >> %s ' % (SYSTEM_SSH_ENV, hostname, self.known_hosts_fname)
cmd += '&& sed -i "$ s/$/ #OM/" %s ' % self.known_hosts_fname
cmd += "&& chmod %s %s" % (DefaultValue.KEY_FILE_MODE, self.known_hosts_fname)
(status, output) = subprocess.getstatusoutput(cmd)
@ -1018,15 +1020,15 @@ General options:
output: NA
'''
bashrc_file = os.path.join(pwd.getpwuid(os.getuid()).pw_dir, ".bashrc")
cmd = 'source %s;' %bashrc_file
cmd += ('scp -q -o "BatchMode yes" -o "NumberOfPasswordPrompts 0" ' +
cmd = 'source %s;%s;' % (bashrc_file, SYSTEM_SSH_ENV)
cmd += ('/usr/bin/scp -q -o "BatchMode yes" -o "NumberOfPasswordPrompts 0" ' +
'%s %s %s:.ssh/' % (self.id_rsa_fname, self.id_rsa_pub_fname, hostname))
cmd += ''' && temp_auth=$(grep '#OM' %s)''' \
''' && ssh %s "sed -i '/#OM/d' %s; echo '${temp_auth}' >> %s"''' % (
''' && /usr/bin/ssh %s "sed -i '/#OM/d' %s; echo '${temp_auth}' >> %s"''' % (
self.authorized_keys_fname, hostname, self.authorized_keys_fname,
self.authorized_keys_fname)
cmd += ''' && temp_auth=$(grep '#OM' %s)''' \
''' && ssh %s "sed -i '/#OM/d' %s; echo '${temp_auth}' >> %s"''' % (
''' && /usr/bin/ssh %s "sed -i '/#OM/d' %s; echo '${temp_auth}' >> %s"''' % (
self.known_hosts_fname, hostname, self.known_hosts_fname,
self.known_hosts_fname)
(status, output) = subprocess.getstatusoutput(cmd)
@ -1179,7 +1181,8 @@ General options:
self.logger.debug("Creating a remote directory [%s] successfully on node "
"[%s]." %(tmp_path, hostname))
# scp ssh_protect to remote node
cmd = 'source %s; scp -q -r -2' % bashrc_file
cmd = 'source %s;%s;/usr/bin/scp -q -r -2' % (bashrc_file, SYSTEM_SSH_ENV)
cmd = '%s -o "BatchMode yes" -o ' % (cmd)
cmd = '%s "NumberOfPasswordPrompts 0" %s' % (cmd, protect_path)
cmd = '%s [%s]:%s' % (cmd, hostname, tmp_path)
@ -1359,8 +1362,8 @@ General options:
def copy_shell_to_remote_node(self, shell_file, hostname):
# scp ssh_protect to remote node
cmd = 'source ~/.bashrc;'
cmd += ('scp -q -o "BatchMode yes" -o "NumberOfPasswordPrompts 0" ' + '%s %s:.ssh/' % (
cmd = 'source ~/.bashrc;%s;' % SYSTEM_SSH_ENV
cmd += ('/usr/bin/scp -q -o "BatchMode yes" -o "NumberOfPasswordPrompts 0" ' + '%s %s:.ssh/' % (
shell_file, hostname))
(status, output) = subprocess.getstatusoutput(cmd)
if status != 0:

View File

@ -137,6 +137,7 @@ g_lock = thread.allocate_lock()
BASE_ID_GTM = 1001
BASE_ID_DATANODE = 6001
SYSTEM_SSH_ENV = "export LD_LIBRARY_PATH=/usr/lib64"
def check_content_key(content, key):
if not (type(content) == bytes):
@ -2594,7 +2595,7 @@ class DefaultValue():
:param logger:
:return:
"""
clear_cmd = "source %s;ssh-add -D" %mpprcfile
clear_cmd = "source %s;%s;/usr/bin/ssh-add -D" % (mpprcfile, SYSTEM_SSH_ENV)
status, output = subprocess.getstatusoutput(clear_cmd)
if status != 0:
if logger:
@ -2615,8 +2616,8 @@ class DefaultValue():
"""
DefaultValue.clear_ssh_id_rsa(mpprcfile, logger)
id_rsa_path = DefaultValue.SSH_PRIVATE_KEY
cmd = "source %s;echo \"%s\" | /bin/sh %s %s" %(
mpprcfile, str(secret_word), shell_file, id_rsa_path)
cmd = "source %s;%s;echo \"%s\" | /bin/sh %s %s" %(
mpprcfile, SYSTEM_SSH_ENV, str(secret_word), shell_file, id_rsa_path)
if logger:
logger.debug("ssh-add cmd:%s" %cmd)
(status, stdout, stderr) = DefaultValue.try_fast_popen(cmd)
@ -2642,7 +2643,7 @@ class DefaultValue():
agent_path = os.path.join("~/gaussdb_tmp/", "gauss_socket_tmp")
agent_path = os.path.expanduser(agent_path)
cmd = "ssh-agent -a %s" % (agent_path)
cmd_ssh_add = "source %s;ssh-agent -a %s" % (mpprcfile, agent_path)
cmd_ssh_add = "source %s;%s;ssh-agent -a %s" % (mpprcfile, SYSTEM_SSH_ENV, agent_path)
list_pid = DefaultValue.get_pid(cmd)
if not list_pid:
if os.path.exists(agent_path):
@ -2691,7 +2692,7 @@ class DefaultValue():
"""
RETRY_TIMES = 0
while True:
check_cmd = "source %s;ssh-add -D" % mpprcfile
check_cmd = "source %s;%s;ssh-add -D" % (mpprcfile, SYSTEM_SSH_ENV)
proc = FastPopen(check_cmd, stdout=PIPE, stderr=PIPE,
preexec_fn=os.setsid, close_fds=True)
stdout, stderr = proc.communicate()
@ -2782,7 +2783,7 @@ class DefaultValue():
:param logger:
:return:
"""
clear_cmd = "source %s;ssh-add -D" % mpprcfile
clear_cmd = "%s;/usr/bin/ssh-add -D" % SYSTEM_SSH_ENV
(env_msg, channel_read) = DefaultValue.ssh_exec_cmd(session, clear_cmd)
if env_msg and "All identities removed" not in env_msg:
if logger:
@ -2829,7 +2830,7 @@ class DefaultValue():
delete_cmd = "rm -rf %s" % agent_path
DefaultValue.ssh_exec_cmd(session, delete_cmd)
cmd = "ssh-agent -a %s" % agent_path
cmd_ssh_add = "source %s;ssh-agent -a %s" % (ClusterConstants.ETC_PROFILE, agent_path)
cmd_ssh_add = "source %s;%s;ssh-agent -a %s" % (ClusterConstants.ETC_PROFILE, SYSTEM_SSH_ENV, agent_path)
(env_msg, channel_read) = DefaultValue.ssh_exec_cmd(session, cmd_ssh_add)
if env_msg and "Address already in use" not in env_msg:
if logger:

View File

@ -4793,7 +4793,7 @@ class dbClusterInfo():
remoteDynamicConfigFile = "%s/bin/cluster_dynamic_config_%s" \
% (gaussHome, dbNode.name)
if dbNode.name != localHostName:
cmd = "scp %s:%s %s" % (
cmd = "export LD_LIBRARY_PATH=/usr/lib64;/usr/bin/scp %s:%s %s" % (
dbNode.name, dynamicConfigFile, remoteDynamicConfigFile)
status, output = subprocess.getstatusoutput(cmd)
if status:
@ -4834,7 +4834,7 @@ class dbClusterInfo():
cmd = "cp -f %s %s" % (sourceFile, targetFile)
status, output = subprocess.getstatusoutput(cmd)
else:
cmd = "scp %s %s:%s" % (sourceFile, dbNode.name, targetFile)
cmd = "export LD_LIBRARY_PATH=/usr/lib64;/usr/bin/scp %s %s:%s" % (sourceFile, dbNode.name, targetFile)
status, output = subprocess.getstatusoutput(cmd)
if status:
raise Exception(ErrorCode.GAUSS_514["GAUSS_51400"] % cmd +

View File

@ -278,6 +278,7 @@ class TaskThread(threading.Thread):
ssh_auth_sock = self.get_env_variable("SSH_AUTH_SOCK", bashrc_file)
ssh_agent_pid = self.get_env_variable("SSH_AGENT_PID", bashrc_file)
env = os.environ
env["LD_LIBRARY_PATH"] = "/usr/lib64"
env.update({"SSH_AUTH_SOCK": ssh_auth_sock,
"SSH_AGENT_PID": ssh_agent_pid})
self.proc = FastPopen(self.cmd, shell=False, stdout=subprocess.PIPE,

View File

@ -138,7 +138,7 @@ def run(hosts, opts, args):
str(agent_port), path, remote_path]
manager.add_task(host, cmd)
else:
cmd = ['scp', '-qCr']
cmd = ['/usr/bin/scp', '-qCr']
if opts.extra:
cmd.extend(shlex.split(opts.extra))
if opts.opt:

View File

@ -129,7 +129,7 @@ def run(hosts):
cmd = ['python3', cmd_sender_path, '-H', host, '-p',
str(agent_port), '-a', action, '-t', str(opts.timeout)]
else:
cmd = ["ssh", host, "-q",
cmd = ["/usr/bin/ssh", host, "-q",
"-o", "SendEnv=PSSH_NODENUM PSSH_HOST",
"-o", "BatchMode=yes",
"-o", "ConnectionAttempts=10",

View File

@ -82,7 +82,7 @@ def check_ssh_agent_available(bashrc_file, logger):
:param logger:
:return:
"""
check_cmd = "source %s;ssh-add -l" % bashrc_file
check_cmd = "source %s;export LD_LIBRARY_PATH=/usr/lib64;ssh-add -l" % bashrc_file
proc = FastPopen(check_cmd, stdout=PIPE, stderr=PIPE,
preexec_fn=os.setsid, close_fds=True)
stdout, stderr = proc.communicate()

7
script/scp Normal file
View File

@ -0,0 +1,7 @@
#!/bin/bash
#############################################################################
# Copyright (c): 2021-2025, Huawei Tech. Co., Ltd.
# FileName : scp
# Date : 2023-12-09
#############################################################################
export LD_LIBRARY_PATH=/usr/lib64 && /usr/bin/scp "$@"

7
script/ssh Normal file
View File

@ -0,0 +1,7 @@
#!/bin/bash
#############################################################################
# Copyright (c): 2021-2025, Huawei Tech. Co., Ltd.
# FileName : ssh
# Date : 2023-12-09
#############################################################################
export LD_LIBRARY_PATH=/usr/lib64 && /usr/bin/ssh "$@"

7
script/ssh-add Normal file
View File

@ -0,0 +1,7 @@
#!/bin/bash
#############################################################################
# Copyright (c): 2021-2025, Huawei Tech. Co., Ltd.
# FileName : ssh-copy-id
# Date : 2023-12-09
#############################################################################
export LD_LIBRARY_PATH=/usr/lib64 && /usr/bin/ssh-add "$@"

7
script/ssh-agent Normal file
View File

@ -0,0 +1,7 @@
#!/bin/bash
#############################################################################
# Copyright (c): 2021-2025, Huawei Tech. Co., Ltd.
# FileName : ssh
# Date : 2023-12-09
#############################################################################
export LD_LIBRARY_PATH=/usr/lib64 && /usr/bin/ssh-agent "$@"

7
script/ssh-copy-id Normal file
View File

@ -0,0 +1,7 @@
#!/bin/bash
#############################################################################
# Copyright (c): 2021-2025, Huawei Tech. Co., Ltd.
# FileName : ssh-copy-id
# Date : 2023-12-09
#############################################################################
export LD_LIBRARY_PATH=/usr/lib64 && /usr/bin/ssh-copy-id "$@"

7
script/ssh-keygen Normal file
View File

@ -0,0 +1,7 @@
#!/bin/bash
#############################################################################
# Copyright (c): 2021-2025, Huawei Tech. Co., Ltd.
# FileName : ssh
# Date : 2023-12-09
#############################################################################
export LD_LIBRARY_PATH=/usr/lib64 && /usr/bin/ssh-keygen "$@"