Hostile 100% github Download

osac-project/osac-test-infra main

Legitimate CI test infrastructure

“Ansible-based test infrastructure for OSAC end-to-end testing”

nsenter into PID 1 then spawn shellApplies wraps to nested Python function

Evidence

PREFIX build variable reference lines 1–29
1#!/usr/bin/env bash
2#
3# Deploy containerlab topology, configure switches, attach mgmt VM
4# to the fabric, configure BGP peering.
5# Corresponds to setup-lab.sh steps 11-18.
6# Idempotent — safe to re-run.
7#
8set -euo pipefail
9
10SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
11INFRA_DIR="${SCRIPT_DIR}/.."
12
13# shellcheck source=/dev/null
14source "${INFRA_DIR}/.mgmt-network"
15
16export KUBECONFIG
17
18OSAC_NAMESPACE="${OSAC_NAMESPACE:-osac-e2e-ci}"
19
20LAB_NAME="agentless-net-lab"
21PREFIX="clab-${LAB_NAME}"
22CONTAINERLAB="${CONTAINERLAB:-containerlab}"
23SWITCHES=("${PREFIX}-leaf-1" "${PREFIX}-leaf-2")
⋯6 lines
SSH known-hosts null-device option text lines 35–71
35:38… ------
36
37TOPO_FILE="${INFRA_DIR}/agentless-net-lab.clab.yml"
38
39if docker ps --format '{{.Names}}' | grep -q "^${PREFIX}-leaf-1$"; then
40 info "Containerlab already running — skipping deploy"
41else
42 info "Deploying containerlab topology..."
43 sudo MGMT_BRIDGE="$MGMT_BRIDGE" MGMT_CIDR="$MGMT_CIDR" MGMT_GW="$MGMT_GW" MGMT_PREFIX="$MGMT_PREFIX" \
44 ${CONTAINERLAB} deploy -t "$TOPO_FILE"
45fi
46
47# ---------- wait for switches ----------
48
49wait_for_switch() {
50 local sw="$1"
51 local elapsed=0
52 while ! docker exec "$sw" nv show system 2>/dev/null | grep -q "hostname"; do
53 sleep 3; elapsed=$((elapsed + 3))
54 [ "$elapsed" -ge 90 ] && break
55 done
56 local mgmt_ip
57 mgmt_ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$sw")
58 while ! sshpass -p cumulus ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=2 cumulus@"$mgmt_ip" true &>/dev/null; do
59 sleep 3; elapsed=$((elapsed + 3))
60 [ "$elapsed" -ge 120 ] && break
⋯11 lines
nsenter into PID 1 then spawn shell lines 73–105
73:18… permissions on switches..."
74for sw in "${SWITCHES[@]}"; do
75 docker exec "$sw" bash -c \
76 "echo 'cumulus ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/cumulus && chmod 440 /etc/sudoers.d/cumulus"
77done
78
79# ---------- attach mgmt VM to switch fabric ----------
80
81if ip link show br-mgmt &>/dev/null; then
82 info "br-mgmt already exists — skipping"
83else
84 info "Creating br-mgmt and attaching mgmt VM to switch fabric..."
85 sudo ip link add br-mgmt type bridge
86 sudo ip link set leaf1-swp4 master br-mgmt
87 sudo ip link set br-mgmt up
88 virsh attach-interface "$MGMT_VM_NAME" bridge br-mgmt --model virtio --live --persistent
89fi
90
91FABRIC_MAC=$(virsh domiflist "$MGMT_VM_NAME" | grep br-mgmt | awk '{print $5}')
92MGMT_NODE=$(KUBECONFIG="$KUBECONFIG" oc get nodes -o name | head -1 | cut -d/ -f2)
93FABRIC_NIC=$(KUBECONFIG="$KUBECONFIG" oc debug "node/$MGMT_NODE" -- \
94 nsenter -t 1 -n ip -o link show 2>&1 | grep "$FABRIC_MAC" | awk -F'[ :]+' '{print $2}')
95
96info "Configuring mgmt VM fabric NIC ($FABRIC_NIC) with net-node as gateway..."
97KUBECONFIG="$KUBECONFIG" oc debug "node/$MGMT_NODE" -- \
98 nsenter -a -t 1 -- bash -c "
99 if nmcli connection show fabric-native &>/dev/null; then
100 nmcli connection modify fabric-native \
101 ipv4.gateway 10.0.0.30 ipv4.route-metric 10
102 nmcli connection up fabric-native 2>/dev/null
103 else
104 nmcli connection add type ethernet ifname $FABRIC_NIC con-name fabric-native \
105 ipv4.me …
Shell command-substitution syntax lines 119–124
119:5… NTORY="${INFRA_DIR}/inventory/inventory.yml"
120RESOLVED_INVENTORY=$(mktemp --suffix=.yml)
121MGMT_PREFIX="$MGMT_PREFIX" envsubst < "$INVENTORY" > "$RESOLVED_INVENTORY"
122
123info "Configuring trunk ports on switches..."
124ansib …
References PermitRootLogin configuration lines 125–144
125:19… INVENTORY" \
126 "${INFRA_DIR}/playbooks/configure_network.yml"
127rm -f "$RESOLVED_INVENTORY"
128
129# ---------- install packages on network node ----------
130
131info "Preparing network node..."
132docker exec "$NET_NODE" apk add --no-cache iptables iproute2 python3 openssh frr >/dev/null 2>&1
133docker exec "$NET_NODE" ssh-keygen -A >/dev/null 2>&1
134docker exec "$NET_NODE" sh -c "echo 'root:root' | chpasswd"
135docker exec "$NET_NODE" sh -c "echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config"
136docker exec "$NET_NODE" /usr/sbin/sshd
137echo " Installed iptables, iproute2, python3, openssh, frr on net-node"
138
139docker exec "$NET_NODE" ip addr replace 10.0.0.30/24 dev eth1
140echo " net-node:eth1 = 10.0.0.30/24 (native VLAN)"
141
142docker exec "$NET_NODE" iptables -t nat -C POSTROUTING -s 10.0.0.0/24 -o eth2 -j MASQUERADE 2>/dev/null || \
143 docker exec "$NET_NODE" iptables -t nat -A POSTROUTING -s 10.0.0.0/24 -o eth2 -j MASQUERADE
144echo " net-no …

Showing the top 5 files — 3 more files (34 regions) not shown.

No evidence locations were recorded for this file. Raw result

Keyboard shortcuts on this page: j for the next sample, k for the previous one, x to go back to the feed, d to download the original bytes, r to re-queue the sample for analysis.