mirror of
https://github.com/Kiritow/wg-ops.git
synced 2024-03-22 13:11:37 +08:00
fix rootless network host-container communication
This commit is contained in:
parent
045fc93c01
commit
130ce3318b
27
generate.py
27
generate.py
|
@ -9,6 +9,7 @@ import base64
|
|||
|
||||
path_get_gateway = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), 'tools/get-gateway.py')
|
||||
path_get_ip = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), 'tools/get-ip.py')
|
||||
path_get_lan_ip = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), 'tools/get-lan-ip.py')
|
||||
path_bin_dir = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), 'bin')
|
||||
path_app_dir = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), 'app')
|
||||
|
||||
|
@ -401,16 +402,21 @@ class Parser:
|
|||
|
||||
self.result_postup.extend(self.result_container_prebootstrap)
|
||||
|
||||
if not self.flag_container_must_host:
|
||||
self.result_postup.append('PostUp={}'.format(
|
||||
self.get_podman_cmd_with('CT_GATEWAY=$(/usr/bin/python3 {} {}); podman exec -t -e GATEWAY_IP=$CT_GATEWAY -e WG_PORT={} {} /usr/bin/python3 /root/app/bootstrap.py'.format(
|
||||
path_get_gateway, self.get_container_network_name(), self.wg_port, self.get_container_name()))
|
||||
))
|
||||
else:
|
||||
if self.flag_container_must_host:
|
||||
self.result_postup.append('PostUp={}'.format(
|
||||
self.get_podman_cmd_with('podman exec -t -e GATEWAY_IP=127.0.0.1 -e WG_PORT={} {} /usr/bin/python3 /root/app/bootstrap.py'.format(
|
||||
self.wg_port, self.get_container_name()))
|
||||
))
|
||||
elif self.podman_user:
|
||||
self.result_postup.append('PostUp={}'.format(
|
||||
self.get_podman_cmd_with('CT_GATEWAY=$(/usr/bin/python3 {}); podman exec -t -e GATEWAY_IP=$CT_GATEWAY -e WG_PORT={} {} /usr/bin/python3 /root/app/bootstrap.py'.format(
|
||||
path_get_lan_ip, self.wg_port, self.get_container_name()))
|
||||
))
|
||||
else:
|
||||
self.result_postup.append('PostUp={}'.format(
|
||||
self.get_podman_cmd_with('CT_GATEWAY=$(/usr/bin/python3 {} {}); podman exec -t -e GATEWAY_IP=$CT_GATEWAY -e WG_PORT={} {} /usr/bin/python3 /root/app/bootstrap.py'.format(
|
||||
path_get_gateway, self.get_container_network_name(), self.wg_port, self.get_container_name()))
|
||||
))
|
||||
|
||||
self.result_postup.extend(self.result_container_postbootstrap)
|
||||
|
||||
|
@ -450,13 +456,14 @@ class Parser:
|
|||
|
||||
if addr_host == "gateway":
|
||||
tunnel_addr = ""
|
||||
if not self.flag_container_must_host:
|
||||
if self.flag_container_must_host or self.podman_user:
|
||||
self.result_postup.append("PostUp=wg set {} peer {} endpoint 127.0.0.1:{}".format(
|
||||
self.wg_name, current_pubkey, addr_port))
|
||||
else:
|
||||
self.result_postup.append("PostUp=CT_IP=$({}); wg set {} peer {} endpoint $CT_IP:{}".format(
|
||||
self.get_podman_cmd_with('/usr/bin/python3 {} {} {}'.format(path_get_ip, self.get_container_network_name(), self.get_container_name())),
|
||||
self.wg_name, current_pubkey, addr_port))
|
||||
else:
|
||||
self.result_postup.append("PostUp=wg set {} peer {} endpoint 127.0.0.1:{}".format(
|
||||
self.wg_name, current_pubkey, addr_port))
|
||||
|
||||
elif tunnel_addr:
|
||||
tunnel_addr = "127.0.0.1:{}".format(tunnel_addr)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user