diff --git a/.github/workflows/cluster.yml b/.github/workflows/cluster.yml index 0667352d..5f43d062 100644 --- a/.github/workflows/cluster.yml +++ b/.github/workflows/cluster.yml @@ -1,9 +1,9 @@ name: Cluster Run - Minimega on: - #pull_request: - # branches: - # - '*' + # pull_request: + # branches: + # - '*' workflow_dispatch: inputs: azure_region: @@ -37,10 +37,13 @@ jobs: LS1_IP: "" elastic: "" AZURE_IP: "" - MINIMEGA_IP: "" + LINUX_IP: "" + WINDOWS_IP: "" ENROLLMENT_TOKEN: "" ES_PASSWORD: "" KIBANA_PASSWORD: "" + ELASTIC_AGENT_VERSION: "8.15.3" + MINIMEGA_PASSWORD: ${{ secrets.MINIMEGA_PASSWORD }} steps: - name: Checkout repository @@ -104,7 +107,7 @@ jobs: python3 ./azure/build_azure_linux_network.py \ -g pipe-${{ env.UNIQUE_ID }} \ -s ${{ env.IP_ADDRESS }}/32 \ - -vs Standard_D8_v4 \ + -vs Standard_E8_v4 \ -l ${{ inputs.azure_region || 'centralus' }} \ -ast 23:00 \ -y @@ -119,7 +122,7 @@ jobs: IP_ADDRESS=\$(cat pipe-${{ env.UNIQUE_ID }}.ip.txt) && \ ./minimega/install.sh lme-user \$IP_ADDRESS "pipe-${{ env.UNIQUE_ID }}.password.txt" " - + - name: Install Linux in minimega run: | cd testing/v2/development @@ -128,6 +131,27 @@ jobs: IP_ADDRESS=\$(cat pipe-${{ env.UNIQUE_ID }}.ip.txt) && \ ./ubuntu_qcow_maker/install.sh lme-user \$IP_ADDRESS "pipe-${{ env.UNIQUE_ID }}.password.txt" " + + - name: Install windows minimega on Azure instance + env: + AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} + AZURE_CLIENT_SECRET: ${{ secrets.AZURE_SECRET }} + AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT }} + AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + run: | + cd testing/v2/development + sleep 30 + docker compose -p ${{ env.UNIQUE_ID }} exec -T \ + -e AZURE_CLIENT_ID \ + -e AZURE_CLIENT_SECRET \ + -e AZURE_TENANT_ID \ + -e AZURE_SUBSCRIPTION_ID \ + pipeline bash -c " + cd /home/lme-user/LME/testing/v2/installers && \ + IP_ADDRESS=\$(cat pipe-${{ env.UNIQUE_ID }}.ip.txt) && \ + ./windows_qcow/pipeline_install.sh lme-user \$IP_ADDRESS "pipe-${{ env.UNIQUE_ID }}.password.txt" + " + - name: Check if linux is running in minimega run: | @@ -139,33 +163,50 @@ jobs: ssh lme-user@\$IP_ADDRESS 'sudo /opt/minimega/bin/minimega -e vm info' " - - name: Get Azure and Minimega IP addresses + - name: Get Azure, Windows, and Linux IP addresses run: | cd testing/v2/development AZURE_IP=$(docker compose -p ${{ env.UNIQUE_ID }} exec -T pipeline bash -c "cat /home/lme-user/LME/testing/v2/installers/pipe-${{ env.UNIQUE_ID }}.ip.txt") echo "AZURE_IP=$AZURE_IP" >> $GITHUB_ENV echo "Azure IP:$AZURE_IP" - MINIMEGA_IP=$(docker compose -p ${{ env.UNIQUE_ID }} exec -T pipeline bash -c " - ssh lme-user@$AZURE_IP 'sudo /opt/minimega/bin/minimega -e .json true .filter name=\"linux-runner\" vm info | jq -r \".[].Data[].Networks[].IP4\"' - " ) + LINUX_IP=$(docker compose -p ${{ env.UNIQUE_ID }} exec -T pipeline bash -c " + ssh lme-user@$AZURE_IP 'sudo /opt/minimega/bin/minimega -e .json true vm info | jq -r --arg name \"ubuntu-runner\" \".[].Data[] | select(.Name == \\\$name) | .Networks[0].IP4\"' + ") EXIT_CODE=$? if [ $EXIT_CODE -ne 0 ]; then - echo "Failed to get Minimega IP. Exit code: $EXIT_CODE" >&2 + echo "Failed to get Linux IP. Exit code: $EXIT_CODE" >&2 exit 1 fi - if [ -z "$MINIMEGA_IP" ]; then - echo "Minimega IP is empty" >&2 + if [ -z "$LINUX_IP" ]; then + echo "Linux IP is empty" >&2 exit 1 fi - echo "MINIMEGA_IP=$MINIMEGA_IP" >> $GITHUB_ENV - echo "Azure IP:$AZURE_IP Minimega IP:$MINIMEGA_IP" + echo "LINUX_IP=$LINUX_IP" >> $GITHUB_ENV + echo "Linux IP:$LINUX_IP" + WINDOWS_IP=$(docker compose -p ${{ env.UNIQUE_ID }} exec -T pipeline bash -c " + ssh lme-user@$AZURE_IP 'sudo /opt/minimega/bin/minimega -e .json true vm info | jq -r --arg name \"windows-runner\" \".[].Data[] | select(.Name == \\\$name) | .Networks[0].IP4\"' + ") + EXIT_CODE=$? + if [ $EXIT_CODE -ne 0 ]; then + echo "Failed to get Windows IP. Exit code: $EXIT_CODE" >&2 + exit 1 + fi + if [ -z "$WINDOWS_IP" ]; then + echo "Windows IP is empty" >&2 + exit 1 + fi + echo "WINDOWS_IP=$WINDOWS_IP" >> $GITHUB_ENV + echo "Windows IP:$WINDOWS_IP" - - name: Run a command in Minimega + echo "Azure_IP:$AZURE_IP LINUX_IP:$LINUX_IP WINDOWS_IP:$WINDOWS_IP" + + + - name: Run a command in Linux Minimega run: | cd testing/v2/development docker compose -p ${{ env.UNIQUE_ID }} exec -T pipeline bash -c " - ssh -o StrictHostKeyChecking=no lme-user@${{ env.AZURE_IP }} 'sudo ssh -o StrictHostKeyChecking=no vmuser@${{ env.MINIMEGA_IP }} ls -la' + ssh -o StrictHostKeyChecking=no lme-user@${{ env.AZURE_IP }} 'sudo ssh -o StrictHostKeyChecking=no vmuser@${{ env.LINUX_IP }} ls -la' " - name: Install LME on Azure instance @@ -239,36 +280,44 @@ jobs: ' ") echo "Retrieved enrollment token: $ENROLLMENT_TOKEN" - + # Mask the enrollment token in logs and set it as an environment variable echo "::add-mask::$ENROLLMENT_TOKEN" echo "ENROLLMENT_TOKEN=$ENROLLMENT_TOKEN" >> $GITHUB_ENV echo "Policy ID and Enrollment Token retrieved successfully" - - name: Copy the Elastic Agent installer to Minimega + - name: Copy the Elastic Agent installer to Linux Minimega run: | cd testing/v2/development docker compose -p ${{ env.UNIQUE_ID }} exec -T pipeline bash -c " ssh -o StrictHostKeyChecking=no lme-user@${{ env.AZURE_IP }} \ - 'sudo scp -p -o StrictHostKeyChecking=no /home/lme-user/LME/testing/v2/installers/lib/install_agent_linux.sh vmuser@${{ env.MINIMEGA_IP }}:~' + 'sudo scp -p -o StrictHostKeyChecking=no /home/lme-user/LME/testing/v2/installers/lib/install_agent_linux.sh vmuser@${{ env.LINUX_IP }}:~' " - - name: Run a command in Minimega + - name: Run a command in Linux Minimega run: | cd testing/v2/development docker compose -p ${{ env.UNIQUE_ID }} exec -T pipeline bash -c " - ssh lme-user@${{ env.AZURE_IP }} 'sudo ssh -o StrictHostKeyChecking=no vmuser@${{ env.MINIMEGA_IP }} ls -la' + ssh lme-user@${{ env.AZURE_IP }} 'sudo ssh -o StrictHostKeyChecking=no vmuser@${{ env.LINUX_IP }} ls -la' " - - name: Install the Elastic Agent in Minimega + - name: Install the Elastic Agent in Linux Minimega run: | cd testing/v2/development docker compose -p ${{ env.UNIQUE_ID }} exec -T pipeline bash -c " - ssh lme-user@${{ env.AZURE_IP }} 'sudo ssh -o StrictHostKeyChecking=no vmuser@${{ env.MINIMEGA_IP }} chmod +x ./install_agent_linux.sh ' && \ - ssh lme-user@${{ env.AZURE_IP }} 'sudo ssh -o StrictHostKeyChecking=no vmuser@${{ env.MINIMEGA_IP }} ./install_agent_linux.sh --token ${{ env.ENROLLMENT_TOKEN }}' + ssh lme-user@${{ env.AZURE_IP }} 'sudo ssh -o StrictHostKeyChecking=no vmuser@${{ env.LINUX_IP }} chmod +x ./install_agent_linux.sh ' && \ + ssh lme-user@${{ env.AZURE_IP }} 'sudo ssh -o StrictHostKeyChecking=no vmuser@${{ env.LINUX_IP }} ./install_agent_linux.sh --token ${{ env.ENROLLMENT_TOKEN }} --version ${{ env.ELASTIC_AGENT_VERSION }}' " - - name: Check if the Elastic agent is reporting + - name: Install the Elastic Agent in Windows Minimega + run: | + set +H + cd testing/v2/development + docker compose -p ${{ env.UNIQUE_ID }} exec -T pipeline bash -c ' + ssh lme-user@${{ env.AZURE_IP }} "export SSHPASS='\''${{ env.MINIMEGA_PASSWORD }}'\'' && export WINDOWS_HOST=${{ env.WINDOWS_IP }} && cd /home/lme-user/LME/testing/v2/installers/lib/ && sudo -E ./install_agent_windows.sh --token ${{ env.ENROLLMENT_TOKEN }} --version ${{ env.ELASTIC_AGENT_VERSION }} --clientip ${{ env.WINDOWS_IP }}" + ' + + - name: Check if the Linux Elastic agent is reporting env: ES_PASSWORD: ${{ env.ES_PASSWORD }} run: | @@ -279,6 +328,17 @@ jobs: 'export ES_PASSWORD=\"$ES_PASSWORD\" && /home/lme-user/LME/testing/v2/installers/lib/check_agent_reporting.sh' " + - name: Check if the Windows Elastic agent is reporting + env: + ES_PASSWORD: ${{ env.ES_PASSWORD }} + run: | + sleep 360 + cd testing/v2/development + docker compose -p ${{ env.UNIQUE_ID }} exec -T pipeline bash -c " + ssh -o StrictHostKeyChecking=no lme-user@${{ env.AZURE_IP }} \ + 'export ES_PASSWORD=\"$ES_PASSWORD\" && /home/lme-user/LME/testing/v2/installers/lib/check_agent_reporting.sh windows' + " + - name: Run api tests on Azure instance env: ES_PASSWORD: ${{ env.ES_PASSWORD }} diff --git a/ansible/post_install_local.yml b/ansible/post_install_local.yml index 7c162ff7..eb6e474a 100644 --- a/ansible/post_install_local.yml +++ b/ansible/post_install_local.yml @@ -212,6 +212,9 @@ body: hosts: ["https://{{ ipvar }}:9200"] register: fleet_output_hosts_result + until: fleet_output_hosts_result.status == 200 + retries: 12 + delay: 30 no_log: "{{ not debug_mode }}" ignore_errors: yes @@ -233,6 +236,9 @@ body: ca_trusted_fingerprint: "{{ ca_fingerprint.stdout }}" register: fleet_output_fingerprint_result + until: fleet_output_fingerprint_result.status == 200 + retries: 12 + delay: 30 no_log: "{{ not debug_mode }}" - name: Set Fleet default output SSL verification mode @@ -250,7 +256,12 @@ register: fleet_output_ssl_result no_log: "{{ not debug_mode }}" + - name: Wait for Kibana to be fully ready + pause: + seconds: 180 + - name: Create Endpoint Policy + # TODO: This might need to check if the system is running before creating the policy uri: url: "{{ local_kbn_url }}/api/fleet/agent_policies?sys_monitoring=true" method: POST @@ -333,6 +344,10 @@ state: touch when: not installed_file_check.stat.exists + - name: Wait for Fleet to be fully initialized + pause: + seconds: 120 + - name: Install LME Dashboards hosts: localhost become: yes @@ -723,6 +738,7 @@ clone_directory: "{{clone_directory | expanduser }}" - name: fix wazuh password + # TODO: This might need to check if the container is running. It has failed before. ansible.builtin.expect: #source + podman exec command: "{{ clone_directory }}/scripts/wazuh_rbac.sh" @@ -731,7 +747,7 @@ - "{{ wazuh_password }}" ".*'wazuh-wui'.*": - "{{ wazuh_api_password }}" - timeout: 30 + timeout: 60 become: yes - name: Create Read Only User diff --git a/testing/v2/installers/lib/check_agent_reporting.sh b/testing/v2/installers/lib/check_agent_reporting.sh index 6e206f1a..0a4329f5 100755 --- a/testing/v2/installers/lib/check_agent_reporting.sh +++ b/testing/v2/installers/lib/check_agent_reporting.sh @@ -11,22 +11,29 @@ if [ -z "$ES_PASSWORD" ]; then handle_error "ES_PASSWORD environment variable is not set" fi +# Set default type and allow override via argument +TYPE="linux" +if [ "$1" = "windows" ]; then + TYPE="windows" +fi + # Initialize retry variables MAX_ATTEMPTS=100 ATTEMPT=1 WAIT_TIME=15 while [ $ATTEMPT -le $MAX_ATTEMPTS ]; do - echo "Attempt $ATTEMPT of $MAX_ATTEMPTS to check agent reporting..." + echo "Attempt $ATTEMPT of $MAX_ATTEMPTS to check agent reporting for $TYPE type..." if [ $ATTEMPT -gt 1 ]; then echo "Waiting before next attempt..." sleep $WAIT_TIME - ATTEMPT=$((ATTEMPT + 1)) fi + ATTEMPT=$((ATTEMPT + 1)) + # Run the curl command and capture the output - output=$(curl -kL -s -X GET "https://localhost:9200/.ds-metrics-system.cpu-default-*/_search" \ + output=$(curl -kL -s -X GET "https://localhost:9200/metrics-endpoint.metadata-*/_search" \ -H 'Content-Type: application/json' \ -H "kbn-xsrf: true" \ -u "elastic:$ES_PASSWORD" \ @@ -36,17 +43,7 @@ while [ $ATTEMPT -le $MAX_ATTEMPTS ]; do "must": [ { "term": { - "host.name": "ubuntu-vm" - } - }, - { - "term": { - "event.module": "system" - } - }, - { - "term": { - "event.dataset": "system.cpu" + "host.os.type": "'$TYPE'" } } ] @@ -77,17 +74,16 @@ while [ $ATTEMPT -le $MAX_ATTEMPTS ]; do continue fi - echo "Hit count: $output" echo "Hit count: $hit_count" # Check the hit count and exit if successful if [ "$hit_count" -gt 0 ]; then - echo "ubuntu-vm is reporting" + echo "$TYPE type agent is reporting" exit 0 fi - echo "No recent data from ubuntu-vm, retrying..." + echo "No recent data from $TYPE type, retrying..." done -echo "No recent data from ubuntu-vm after $MAX_ATTEMPTS attempts" +echo "No recent data from $TYPE type after $MAX_ATTEMPTS attempts" exit 1 \ No newline at end of file diff --git a/testing/v2/installers/lib/get_ip_of_machine.sh b/testing/v2/installers/lib/get_ip_of_machine.sh index 350de841..e0a642da 100755 --- a/testing/v2/installers/lib/get_ip_of_machine.sh +++ b/testing/v2/installers/lib/get_ip_of_machine.sh @@ -5,7 +5,7 @@ MAX_ATTEMPTS=30 SLEEP_INTERVAL=10 get_ip() { - /opt/minimega/bin/minimega -e .json true .filter name="$VM_NAME" vm info | jq -r '.[].Data[].Networks[].IP4' + /opt/minimega/bin/minimega -e ".json true vm info" | jq -r --arg name "$VM_NAME" '.[].Data[] | select(.Name == $name) .Networks[0].IP4' } echo "Waiting for IP assignment for VM: $VM_NAME" >&2 diff --git a/testing/v2/installers/lib/install_agent_windows.sh b/testing/v2/installers/lib/install_agent_windows.sh new file mode 100755 index 00000000..758cf9e5 --- /dev/null +++ b/testing/v2/installers/lib/install_agent_windows.sh @@ -0,0 +1,92 @@ +#!/usr/bin/env bash + +# Default values +VERSION="8.15.3" +ARCHITECTURE="windows-x86_64" +HOST_IP="10.1.0.5" +CLIENT_IP="10.0.0.100" +USER="Test" +PORT="8220" +ENROLLMENT_TOKEN="" + +# Parse command line arguments +while [[ $# -gt 0 ]]; do + case $1 in + --version) + VERSION="$2" + shift 2 + ;; + --arch) + ARCHITECTURE="$2" + shift 2 + ;; + --hostip) + HOST_IP="$2" + shift 2 + ;; + --clientip) + CLIENT_IP="$2" + shift 2 + ;; + --user) + USER="$2" + shift 2 + ;; + --port) + PORT="$2" + shift 2 + ;; + --token) + ENROLLMENT_TOKEN="$2" + shift 2 + ;; + *) + echo "Unknown option: $1" + exit 1 + ;; + esac +done + +# Download Elastic Agent +echo "Downloading file" +curl -L -O "https://artifacts.elastic.co/downloads/beats/elastic-agent/elastic-agent-${VERSION}-${ARCHITECTURE}.zip" + +# Copy the file to windows +echo "Copying the file to windows..." +sshpass -e scp elastic-agent-${VERSION}-${ARCHITECTURE}.zip ${USER}@${CLIENT_IP}:elastic-agent-${VERSION}-${ARCHITECTURE}.zip + +## Extract the archive +echo "Extracting windows archive..." +#./run_elevated_powershell.sh "New-Item -ItemType Directory -Path ./elastic-agent-${VERSION}-${ARCHITECTURE}; Expand-Archive -Path ./elastic-agent-${VERSION}-${ARCHITECTURE}.zip -DestinationPath ./" +./run_elevated_powershell.sh "Expand-Archive -Path ./elastic-agent-${VERSION}-${ARCHITECTURE}.zip -Force" + +## Install Elastic Agent with automatic "yes" response +echo "Installing elastic agent" +#./run_elevated_powershell.sh "elastic-agent-8.15.3-windows-x86_64/elastic-agent-8.15.3-windows-x86_64/elastic-agent install --non-interactive " +#./run_elevated_powershell.sh "elastic-agent-8.15.3-windows-x86_64/elastic-agent-8.15.3-windows-x86_64/elastic-agent install --force " +./run_elevated_powershell.sh "elastic-agent-8.15.3-windows-x86_64/elastic-agent-8.15.3-windows-x86_64/elastic-agent install --non-interactive --force --url=https://${HOST_IP}:$PORT --insecure --enrollment-token=${ENROLLMENT_TOKEN}" + +echo "Waiting for service to start..." +sleep 60 + +echo "Checking agent service status" +./run_elevated_powershell.sh "Get-Service Elastic\` Agent" + +# +## Enroll the Elastic Agent and capture the output +#enrollment_output=$(./run_elevated_powershell.sh "./elastic-agent-8.15.3-windows-x86_64/elastic-agent-8.15.3-windows-x86_64/elastic-agent enroll --force --insecure --url=https://${HOST_IP}:$PORT --enrollment-token=${ENROLLMENT_TOKEN} ") +# +## Check if enrollment was successful +#if echo "$enrollment_output" | grep -q "Successfully enrolled"; then +# echo "Agent enrollment successful" +#else +# echo "Agent enrollment failed" +# echo "Enrollment output: $enrollment_output" +# exit 1 +#fi + +## Restart the agent service +#sudo service elastic-agent restart +# +## Remove the downloaded archive +rm -f "elastic-agent-${VERSION}-${ARCHITECTURE}.zip" \ No newline at end of file diff --git a/testing/v2/installers/lib/run_elevated_powershell.sh b/testing/v2/installers/lib/run_elevated_powershell.sh new file mode 100755 index 00000000..0f21fbbc --- /dev/null +++ b/testing/v2/installers/lib/run_elevated_powershell.sh @@ -0,0 +1,30 @@ +#!/bin/bash +#set -ex + +# Check if command argument is provided +if [ $# -lt 1 ]; then + echo "Usage: $0 [host]" + echo "Example: $0 'Get-Service sshd' 10.0.0.180" + echo "Note: Set SSHPASS and/or WINDOWS_HOST environment variables if needed" + exit 1 +fi + +command="$1" +host_arg="$2" + +# Check if SSHPASS is set +if [ -z "$SSHPASS" ]; then + echo "Error: SSHPASS environment variable must be set" + echo "Example: export SSHPASS='windowspassword'" + exit 1 +fi + +# Use passed host, environment variable, or default value +HOST=${host_arg:-${WINDOWS_HOST:-"10.0.0.180"}} +USER="Test" + +# Add host key if not already present +ssh-keyscan -H $HOST >> ~/.ssh/known_hosts 2>/dev/null + +# Run the command +sshpass -e ssh $USER@$HOST "powershell -NoProfile -Command \"Start-Process PowerShell -ArgumentList '-NoProfile', '-ExecutionPolicy', 'Bypass', '-Command', '${command} *>&1 > C:\\Users\\Test\\service.txt' -Verb RunAs -Wait -PassThru; Get-Content C:\\Users\\Test\\service.txt\"" \ No newline at end of file diff --git a/testing/v2/installers/ubuntu_qcow_maker/get_ip_of_machine.sh b/testing/v2/installers/ubuntu_qcow_maker/get_ip_of_machine.sh index 2716b38c..d0314dc5 100755 --- a/testing/v2/installers/ubuntu_qcow_maker/get_ip_of_machine.sh +++ b/testing/v2/installers/ubuntu_qcow_maker/get_ip_of_machine.sh @@ -5,7 +5,7 @@ MAX_ATTEMPTS=30 SLEEP_INTERVAL=10 get_ip() { - /opt/minimega/bin/minimega -e .json true .filter name="$VM_NAME" vm info | jq -r '.[].Data[].Networks[].IP4' + /opt/minimega/bin/minimega -e ".json true vm info" | jq -r --arg name "$VM_NAME" '.[].Data[] | select(.Name == $name) .Networks[0].IP4' } echo "Waiting for IP assignment for VM: $VM_NAME" diff --git a/testing/v2/installers/windows_qcow/.env.example b/testing/v2/installers/windows_qcow/.env.example index 51b8e08b..b08f7879 100644 --- a/testing/v2/installers/windows_qcow/.env.example +++ b/testing/v2/installers/windows_qcow/.env.example @@ -3,11 +3,12 @@ #export AZURE_CLIENT_ID='your_client_id_here' #export AZURE_CLIENT_SECRET='your_client_secret_here' #export AZURE_TENANT_ID='your_tenant_id_here' +#export AZURE_SUBSCRIPTION_ID='your_subscription_id_here' # Pre-configured storage settings - do not modify export AZURE_RESOURCE_GROUP='LME-cbaxley-blob' -export AZURE_SUBSCRIPTION_ID='1c838bbe-dea0-42ce-a0a8-13e997b65bde' +#export AZURE_SUBSCRIPTION_ID='1c838bbe-dea0-42ce-a0a8-13e997b65bde' export AZURE_STORAGE_ACCOUNT='stb6lavjxzn5h3tsi2fqp70g' export AZURE_STORAGE_CONTAINER='containerkxvobwelmipgsuh' export AZURE_STORAGE_BLOB='win11_ccc.qcow2' diff --git a/testing/v2/installers/windows_qcow/download_blob_file.sh b/testing/v2/installers/windows_qcow/download_blob_file.sh index 808c908b..18901af4 100755 --- a/testing/v2/installers/windows_qcow/download_blob_file.sh +++ b/testing/v2/installers/windows_qcow/download_blob_file.sh @@ -59,8 +59,8 @@ download_file() { local output_path="$2" echo "Downloading file to: $output_path" - curl -L -o "$output_path" "$url" - + curl -sS -L -o "$output_path" "$url" + if [ $? -eq 0 ]; then echo "File downloaded successfully to: $output_path" else diff --git a/testing/v2/installers/windows_qcow/get_windows_ip.sh b/testing/v2/installers/windows_qcow/get_windows_ip.sh new file mode 100755 index 00000000..f6c49c38 --- /dev/null +++ b/testing/v2/installers/windows_qcow/get_windows_ip.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# Check if VM name argument is provided +if [ $# -eq 0 ]; then + echo "Usage: $0 " + exit 1 +fi + +VM_NAME="$1" + +# Use jq to find ip for a specific VM +/opt/minimega/bin/minimega -e ".json true vm info" | jq -r --arg name "$VM_NAME" '.[].Data[] | select(.Name == $name) .Networks[0].IP4' \ No newline at end of file diff --git a/testing/v2/installers/windows_qcow/install.sh b/testing/v2/installers/windows_qcow/install.sh index d8d5be6d..6124a84d 100755 --- a/testing/v2/installers/windows_qcow/install.sh +++ b/testing/v2/installers/windows_qcow/install.sh @@ -27,15 +27,16 @@ ORIGINAL_DIR="$(pwd)" # Get the directory of the script SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +# TODO: Need to set up the env file and source it for other scripts +cd "$SCRIPT_DIR" +cp .env.example .env + # Change to the parent directory of the script cd "$SCRIPT_DIR/.." # Copy the SSH key to the remote machine ./lib/copy_ssh_key.sh $user $hostname $password_file -# TODO: Need to set up the env file and source it for other scripts -cp .env.example .env - # Copy the windows qcow directory to the remote machine scp -r ./windows_qcow $user@$hostname:/home/$user @@ -45,36 +46,5 @@ scp -r ./ubuntu_qcow_maker $user@$hostname:/home/$user # Run the install_local.sh script on the remote machine ssh $user@$hostname "cd /home/$user/windows_qcow && sudo ./install_local.sh" - -#echo -e "\n>>>>>>>>>>>> Installing Azure" -#ssh $user@$hostname "cd /home/$user/windows_qcow && sudo ./install_azure.sh" -# -#echo -e "\n>>>>>>>>>>>> Getting Storage Key" -#ssh $user@$hostname "cd /home/$user/windows_qcow && sudo ./get_storage_key.sh" -# -#echo -e "\n>>>>>>>>>>>> Downloading Blob File" -#ssh $user@$hostname "cd /home/$user/windows_qcow && sudo ./download_blob_file.sh" - -#echo -e "\n>>>>>>>>>>>> Starting Networking ..." -#ssh $user@$hostname "cd /home/$user/windows_qcow && sudo ./start_networking.sh" -# -#echo -e "\n>>>>>>>>>>>> Starting Minimega ..." -#ssh $user@$hostname "sudo /opt/minimega/bin/minimega -e 'read /home/$user/windows_qcow/windows-runner.mm'" -# -#echo -e "\n>>>>>>>>>>>> Waiting for CC ..." -#ssh $user@$hostname "cd /home/$user/windows_qcow && sudo ./wait_for_cc.sh windows-runner" -# -#echo -e "\n>>>>>>>>>>>> Setting DNS ..." -#ssh $user@$hostname "cd /home/$user/windows_qcow && sudo ./set_dns.sh" -# -#echo -e "\n>>>>>>>>>>>> Setting up SSH ..." -#ssh $user@$hostname "cd /home/$user/windows_qcow && sudo ./setup_ssh.sh" -# -#echo -e "\n>>>>>>>>>>>> Starting SSH Service ..." -#ssh $user@$hostname "cd /home/$user/windows_qcow && sudo ./start_ssh_service.sh" -# -#echo -e "\n>>>>>>>>>>>> Setting up RDP ..." -#ssh $user@$hostname "cd /home/$user/windows_qcow && sudo ./setup_rdp.sh" - # Change back to the original directory cd "$ORIGINAL_DIR" diff --git a/testing/v2/installers/windows_qcow/install_azure.sh b/testing/v2/installers/windows_qcow/install_azure.sh index cf5538f6..d2892553 100755 --- a/testing/v2/installers/windows_qcow/install_azure.sh +++ b/testing/v2/installers/windows_qcow/install_azure.sh @@ -4,7 +4,7 @@ echo "Installing Azure CLI..." # Install prerequisites sudo apt-get update -sudo apt-get install -y ca-certificates curl apt-transport-https lsb-release gnupg +sudo apt-get install -y ca-certificates curl apt-transport-https lsb-release gnupg sshpass # Download and install the Microsoft signing key sudo mkdir -p /etc/apt/keyrings diff --git a/testing/v2/installers/windows_qcow/install_local.sh b/testing/v2/installers/windows_qcow/install_local.sh index b95b7c2b..bd20438c 100755 --- a/testing/v2/installers/windows_qcow/install_local.sh +++ b/testing/v2/installers/windows_qcow/install_local.sh @@ -5,6 +5,8 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" . "$SCRIPT_DIR/.env" +# rm -rf "$SCRIPT_DIR/.env" + "$SCRIPT_DIR/install_azure.sh" . "$SCRIPT_DIR/get_storage_key.sh" @@ -25,3 +27,9 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" "$SCRIPT_DIR/setup_rdp.sh" +WINDOWS_IP="$("$SCRIPT_DIR/get_windows_ip.sh" windows-runner)" + +echo "Windows IP: $WINDOWS_IP" + +ssh-keyscan -H $WINDOWS_IP >> ~/.ssh/known_hosts + diff --git a/testing/v2/installers/windows_qcow/pipeline_install.sh b/testing/v2/installers/windows_qcow/pipeline_install.sh new file mode 100755 index 00000000..c8abc469 --- /dev/null +++ b/testing/v2/installers/windows_qcow/pipeline_install.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash +#!/usr/bin/env bash +set -e + +# Function to print usage +print_usage() { + echo "Usage: $0 " + echo "Required parameters:" + echo " : The username for the remote server" + echo " : The hostname or IP address of the remote server" + echo " : The file containing the password for the remote server" +} + +# Check if all required arguments are provided +if [ $# -lt 3 ]; then + print_usage + exit 1 +fi + +# Set the remote server details from the command-line arguments +user=$1 +hostname=$2 +password_file=$3 + +# Store the original working directory +ORIGINAL_DIR="$(pwd)" + +# Get the directory of the script +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +# Change to the parent directory of the script +cd "$SCRIPT_DIR/.." + +echo "$SCRIPT_DIR" + +# Copy the SSH key to the remote machine +./lib/copy_ssh_key.sh $user $hostname $password_file + +cp "windows_qcow/.env.example" "windows_qcow/.env" + +echo "AZURE_CLIENT_ID: $AZURE_CLIENT_ID" + +if [[ ! -z "$AZURE_CLIENT_ID" ]] && [[ ! -z "$AZURE_CLIENT_SECRET" ]] && [[ ! -z "$AZURE_TENANT_ID" ]]; then + echo "" >> "windows_qcow/.env" + echo "export AZURE_CLIENT_ID=$AZURE_CLIENT_ID" >> "windows_qcow/.env" + echo "export AZURE_CLIENT_SECRET=$AZURE_CLIENT_SECRET" >> "windows_qcow/.env" + echo "export AZURE_TENANT_ID=$AZURE_TENANT_ID" >> "windows_qcow/.env" + echo "export AZURE_SUBSCRIPTION_ID=$AZURE_SUBSCRIPTION_ID" >> "windows_qcow/.env" +fi + +scp -r windows_qcow "ubuntu_qcow_maker" $user@$hostname:/home/$user + +rm -rf windows_qcow/.env + +ssh $user@$hostname "cd /home/${user}/windows_qcow && sudo ./install_local.sh"