0 Star 0 Fork 24

兰清程/openstack-nova

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
nova-migration-wrapper 2.01 KB
一键复制 编辑 原始数据 按行查看 历史
zhangy1317 提交于 2021-01-15 15:51 . add spec and source packages
#!/usr/bin/python2
import os
import sys
import syslog
command = os.environ.get('SSH_ORIGINAL_COMMAND')
ssh_connection = os.environ.get('SSH_CONNECTION')
if command is None:
sys.stderr.write('This command must be run via SSH ForceCommand (see man 5 sshd_config).\n')
sys.exit(1)
syslog.openlog('nova_migration_wrapper')
def allow_command(user, args):
syslog.syslog(syslog.LOG_INFO, "Allowing connection='{}' command={} ".format(
ssh_connection,
repr(args)
))
os.execlp('sudo', 'sudo', '-u', user, *args)
def deny_command(args):
syslog.syslog(syslog.LOG_ERR, "Denying connection='{}' command={}".format(
ssh_connection,
repr(args)
))
sys.stderr.write('Forbidden\n')
sys.exit(1)
# Handle libvirt ssh tunnel script snippet
# https://github.com/libvirt/libvirt/blob/f0803dae93d62a4b8a2f67f4873c290a76d978b3/src/rpc/virnetsocket.c#L890
libvirt_sock = '/var/run/libvirt/libvirt-sock'
live_migration_tunnel_cmd = "sh -c 'if 'nc' -q 2>&1 | grep \"requires an argument\" >/dev/null 2>&1; then " \
"ARG=-q0;" \
"else " \
"ARG=;" \
"fi;" \
"'nc' $ARG -U {}'".format(libvirt_sock)
cold_migration_root = '/var/lib/nova/instances/'
cold_migration_cmds = [
['mkdir', '-p'],
['rm', '-rf'],
['touch'],
['rm'],
['scp', '-r', '-t'],
['scp', '-r', '-f'],
['scp', '-t'],
['scp', '-f'],
]
rootwrap_args = ['/usr/bin/nova-rootwrap', '/etc/nova/migration/rootwrap.conf']
def validate_cold_migration_cmd(args):
target_path = os.path.normpath(args[-1])
cmd = args[:-1]
return cmd in cold_migration_cmds and target_path.startswith(cold_migration_root)
# Rules
args = command.split(' ')
if command == live_migration_tunnel_cmd:
args = ['nc', '-U', libvirt_sock]
allow_command('nova', args)
if validate_cold_migration_cmd(args):
args = rootwrap_args + args
allow_command('root', args)
deny_command(args)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/lan-qingcheng/openstack-nova.git
[email protected]:lan-qingcheng/openstack-nova.git
lan-qingcheng
openstack-nova
openstack-nova
master

搜索帮助