adapt ova build changes

This commit is contained in:
Carlos Anguita López 2025-10-30 16:24:29 +01:00
parent 4510a40c60
commit 1670bb0e7a
No known key found for this signature in database
GPG Key ID: FA3E2896D509F5AE
3 changed files with 65 additions and 2 deletions

View File

@ -27,7 +27,7 @@ def add_vagrant_box(box_path: str = VAGRANT_BOX_PATH) -> None:
run_command(f"vagrant box add --name al2023 {box_path}")
def run_vagrant_up(max_retries: int = 100, vagrantfile: Path | None = None) -> bool | None:
def run_vagrant_up(max_retries: int = 10, vagrantfile: Path | None = None) -> bool | None:
"""
Attempts to start a Vagrant virtual machine by running the 'vagrant up' command.
If it fails, it destroys the Vagrant machine and retries the operation up to a specified number of times.

View File

@ -1,5 +1,6 @@
import os
import shutil
import sys
from configurer.utils.helpers import run_command
@ -97,7 +98,56 @@ def install_guest_additions() -> None:
commands = [f"/etc/kernel/postinst.d/vboxadd {kernel_version}", f"/sbin/depmod {kernel_version}"]
run_command(commands)
commands = [
"/sbin/modprobe vboxguest",
"/sbin/modprobe vboxsf",
"/sbin/modprobe vboxvideo",
]
run_command(commands)
stdout, stderr, return_code = run_command("lsmod | grep -q vboxguest", check=False, output=True)
if return_code[0] != 0:
vboxguest_path = f"/lib/modules/{kernel_version}/misc/vboxguest.ko"
if not os.path.isfile(vboxguest_path):
sys.exit(1)
has_vboxadd_service = (
os.path.isfile("/etc/init.d/vboxadd")
or os.path.isfile("/usr/lib/systemd/system/vboxadd.service")
)
if not has_vboxadd_service:
sys.exit(1)
if os.path.isfile("/usr/lib/systemd/system/vboxadd.service"):
commands = [
"mkdir -p /etc/systemd/system/multi-user.target.wants",
"ln -sf /usr/lib/systemd/system/vboxadd.service /etc/systemd/system/multi-user.target.wants/vboxadd.service",
"ln -sf /usr/lib/systemd/system/vboxadd-service.service /etc/systemd/system/multi-user.target.wants/vboxadd-service.service",
]
run_command(commands)
if not os.path.isfile("/etc/rc.d/rc.local"):
commands = [
"touch /etc/rc.d/rc.local",
"chmod +x /etc/rc.d/rc.local",
]
run_command(commands)
rc_local_block = (
"# VirtualBox Guest Additions - ensure modules are loaded\n"
"if [ -f /etc/init.d/vboxadd ]; then\n"
" /etc/init.d/vboxadd start || true\n"
"fi\n"
)
with open("/etc/rc.d/rc.local", "a+", encoding="utf-8") as rc_file:
rc_file.seek(0)
content = rc_file.read()
if "# VirtualBox Guest Additions - ensure modules are loaded" not in content:
rc_file.write(rc_local_block)
run_command("chmod +x /etc/rc.d/rc.local")
if os.path.isfile("/usr/lib/systemd/system/rc-local.service"):
run_command("ln -sf /usr/lib/systemd/system/rc-local.service /etc/systemd/system/multi-user.target.wants/rc-local.service")
def configure_ssh() -> None:
"""
@ -116,6 +166,19 @@ def configure_ssh() -> None:
file.write("PasswordAuthentication yes\n")
else:
file.write(line)
sshd_override_dir = "/etc/ssh/sshd_config.d"
sshd_override_file = os.path.join(sshd_override_dir, "50-vagrant-password-auth.conf")
if not os.path.isdir(sshd_override_dir):
run_command(f"mkdir -p {sshd_override_dir}")
override_content = (
"PasswordAuthentication yes\n"
"PubkeyAuthentication yes\n"
"ChallengeResponseAuthentication no\n"
)
with open(sshd_override_file, "w", encoding="utf-8") as f:
f.write(override_content)
run_command(f"chmod 600 {sshd_override_file}")
run_command("systemctl restart sshd")

View File

@ -10,7 +10,7 @@ Vagrant.configure("2") do |config|
config.vm.synced_folder ".", "/vagrant/", disabled: true
config.ssh.username = "wazuh-user"
config.ssh.password = "wazuh"
config.vm.boot_timeout = 120 # 2 minutes
config.vm.boot_timeout = 420 # 7 minutes
# Create a private network, which allows host-only access to the machine
# using a specific IP.