Skip to content

Commit a917cec

Browse files
committed
Add Debian 7 backend
1 parent 473954c commit a917cec

File tree

5 files changed

+58
-4
lines changed

5 files changed

+58
-4
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
debian1:
2+
image: "bento/debian-7.11"
3+
version: "201806.08.0"
4+
type: "linux"
5+
net_backend: ifupdown
6+
debian2:
7+
image: "bento/debian-7.11"
8+
version: "201806.08.0"
9+
type: "linux"
10+
net_backend: ifupdown

src/cvex/cvex.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ def _read_cvex(self, cve_dir: Path):
9292
data['type'],
9393
trace,
9494
playbooks,
95-
command))
95+
command,
96+
data.get('net_backend')))
9697
if not self.vm_templates:
9798
self.log.critical("%s: configuration mismatch", blueprint_yml)
9899
sys.exit(1)

src/cvex/linuxvm.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def get_ansible_inventory(self) -> Path:
5656
f"ansible_port={self.vag.port()} "
5757
f"ansible_user={self.vag.user()} "
5858
f"ansible_ssh_private_key_file={self.vag.keyfile()} "
59-
f"ansible_ssh_common_args='-o StrictHostKeyChecking=no'")
59+
f"ansible_ssh_common_args='-o StrictHostKeyChecking=no -oHostKeyAlgorithms=+ssh-rsa'")
6060
f.write(data)
6161
return inventory
6262

@@ -70,7 +70,7 @@ def _update_netplan_config(self, netcfg: dict, netcfg_dest: str):
7070
self.ssh.run_command("sudo netplan apply")
7171
self.network_interface_initialized = True
7272

73-
def set_network_interface_ip(self, router: VM | None = None):
73+
def set_network_interface_ip_netplan(self, router: VM | None = None):
7474
if self.network_interface_initialized:
7575
return
7676
yamls = self.ssh.run_command("ls /etc/netplan")
@@ -114,6 +114,33 @@ def set_routing(self, router: VM):
114114
self.ssh.run_command("sudo sysctl net.ipv4.conf.all.accept_redirects=0")
115115
self.ssh.run_command("sudo sysctl net.ipv4.conf.default.accept_redirects=0")
116116

117+
def set_network_interface_ip_ifupdown(self, router: VM | None = None):
118+
# Download existing config
119+
netcfg_local = tempfile.NamedTemporaryFile()
120+
self.ssh.download_file(netcfg_local.name, "/etc/network/interfaces")
121+
122+
with open(netcfg_local.name, "r") as f:
123+
netcfg = f.read()
124+
125+
netcfg = re.sub('(iface eth1[^\r]*address[ ]*)([0-9.]*)',
126+
f'\\g<1>{self.ip}', netcfg, flags=re.MULTILINE)
127+
128+
with open(netcfg_local.name, "w") as f:
129+
f.write(netcfg)
130+
self.ssh.upload_file(netcfg_local.name, "/tmp/interfaces")
131+
self.ssh.run_command("sudo mv /tmp/interfaces /etc/network/interfaces")
132+
self.ssh.run_command("sudo ifdown eth1; sudo ifup eth1")
133+
134+
135+
def set_network_interface_ip(self, router: VM | None = None):
136+
if self.net_backend is None or self.net_backend == 'netplan':
137+
self.set_network_interface_ip_netplan(router)
138+
elif self.net_backend == 'ifupdown':
139+
self.set_network_interface_ip_ifupdown(router)
140+
else:
141+
self.log.critical("Unknown net backend %s", self.net_backend)
142+
sys.exit(1)
143+
117144
def start_api_tracing(self):
118145
if not self.trace:
119146
return

src/cvex/ssh.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
from cvex.logger import get_logger
1010

11+
# Fix bug in paramiko ssh key selection
12+
paramiko.transport.Transport._preferred_pubkeys = ('ssh-rsa', *paramiko.transport.Transport._preferred_pubkeys)
1113

1214
class SSH:
1315
log: logging.Logger

src/cvex/vm.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class VMTemplate:
1717
VM_TYPE_WINDOWS = "windows"
1818
VM_TYPE_UNKNOWN = "unknown"
1919

20+
NET_BACKEND_NETPLAN = "netplan"
21+
NET_BACKEND_IFUPDOWN = "ifupdown"
22+
2023
log: logging.Logger
2124
vm_name: str
2225
image: str
@@ -25,6 +28,7 @@ class VMTemplate:
2528
trace: str | None
2629
playbooks: list[Path]
2730
command: list[str]
31+
net_backend: str
2832

2933
def __init__(self,
3034
vm_name: str,
@@ -33,7 +37,8 @@ def __init__(self,
3337
vm_type: str,
3438
trace: str | None = None,
3539
playbooks: list[Path] = [],
36-
command: list[str] = []):
40+
command: list[str] = [],
41+
net_backend: str = None):
3742
self.log = get_logger(vm_name)
3843
self.vm_name = vm_name
3944
self.image = image
@@ -55,6 +60,14 @@ def __init__(self,
5560
sys.exit(1)
5661
self.playbooks = playbooks
5762
self.command = command
63+
if net_backend is not None:
64+
if vm_type != self.VM_TYPE_LINUX:
65+
self.log.critical("net_backend only valid for %s", self.VM_TYPE_LINUX)
66+
sys.exit(1)
67+
elif net_backend != self.NET_BACKEND_NETPLAN and net_backend != self.NET_BACKEND_IFUPDOWN:
68+
self.log.critical("Unknown net backend %s", net_backend)
69+
sys.exit(1)
70+
self.net_backend = net_backend
5871

5972

6073
current_ip = 2
@@ -132,6 +145,7 @@ def __init__(self,
132145
self.trace = template.trace
133146
self.playbooks = template.playbooks
134147
self.command = template.command
148+
self.net_backend = template.net_backend
135149
self.cve = cve
136150
global current_ip
137151
self.ip = f"192.168.56.{current_ip}"

0 commit comments

Comments
 (0)