fix: restrict OCI edge discovery to managed instances

This commit is contained in:
juvenal.diaz 2026-10-28 11:52:39 -06:00
parent 0d3e0537f0
commit dc13b19893
2 changed files with 21 additions and 5 deletions

View File

@ -3604,7 +3604,7 @@ oci_foundation_config_names=(
LAB_OCI_MONITORING_ENABLED LAB_OCI_MONITORING_CIDR
LAB_OCI_BACKUP_BUCKET_ENABLED LAB_OCI_BACKUP_BUCKET LAB_OCI_BACKUP_BUCKET_NAME LAB_OCI_BACKUP_BUCKET_NAMESPACE LAB_OCI_BACKUP_BUCKET_ID
LAB_OCI_BASTION_ENABLED LAB_OCI_BASTION_NAME LAB_OCI_BASTION_TARGET_SUBNET_ID LAB_OCI_BASTION_SSH_SOURCE_CIDR
LAB_OCI_BASTION_CLIENT_CIDRS_JSON LAB_OCI_BASTION_MAX_SESSION_TTL LAB_OCI_BASTION_ID LAB_OCI_EDGE_INSTANCE_ID
LAB_OCI_BASTION_CLIENT_CIDRS_JSON LAB_OCI_BASTION_MAX_SESSION_TTL LAB_OCI_BASTION_ID LAB_OCI_EDGE_INSTANCE_ID LAB_OCI_EDGE_INSTANCE_MANAGED
LAB_EMAIL_PUBLIC_IP LAB_OCI_EDGE_METRICS_TARGET LAB_OCI_EMAIL_METRICS_TARGET
)
@ -3976,6 +3976,11 @@ oci_foundation_manage() {
fi
if [[ -n "${discovered_edge_instance_id}" && "${discovered_edge_instance_id}" != "null" ]]; then
export LAB_OCI_EDGE_INSTANCE_ID="${discovered_edge_instance_id}"
if [[ "${LAB_OCI_COMPUTE_ENABLED:-true}" == "true" && -z "${LAB_OCI_EDGE_EXISTING_INSTANCE_ID:-}" ]]; then
export LAB_OCI_EDGE_INSTANCE_MANAGED=true
else
export LAB_OCI_EDGE_INSTANCE_MANAGED=false
fi
fi
if [[ -n "${discovered_backup_bucket_name}" && "${discovered_backup_bucket_name}" != "null" ]]; then
export LAB_OCI_BACKUP_BUCKET="${discovered_backup_bucket_name}"

View File

@ -7994,6 +7994,7 @@ refresh_oci_edge_endpoint() {
local discovered_edge_instance_id=""
local oci_bin=""
local vnic_id=""
local instance_compartment="${LAB_OCI_COMPARTMENT_ID:-}"
# A recreated OCI instance can receive a new public IP. Prefer the
# foundation output over inventory so a standalone `edge` run is
@ -8010,14 +8011,19 @@ refresh_oci_edge_endpoint() {
# Existing-instance mode can retain an old/null public_ip in state. Query
# OCI directly from the instance OCID and read the attached VNIC instead.
if [[ -z "${discovered_edge_instance_id}" || "${discovered_edge_instance_id}" == "null" ]]; then
discovered_edge_instance_id="${LAB_OCI_EDGE_INSTANCE_ID:-${LAB_OCI_EDGE_EXISTING_INSTANCE_ID:-}}"
if [[ "${LAB_OCI_EDGE_INSTANCE_MANAGED:-false}" != "true" ]]; then
discovered_edge_instance_id=""
else
discovered_edge_instance_id="${LAB_OCI_EDGE_INSTANCE_ID:-}"
fi
fi
if [[ -n "${discovered_edge_instance_id}" && "${discovered_edge_instance_id}" != "null" ]] &&
if [[ "${LAB_OCI_EDGE_INSTANCE_MANAGED:-false}" == "true" &&
-n "${discovered_edge_instance_id}" && "${discovered_edge_instance_id}" != "null" ]] &&
declare -F oci_cli_resolve >/dev/null 2>&1; then
oci_bin="$(oci_cli_resolve 2>/dev/null || true)"
if [[ -n "${oci_bin}" && -n "${LAB_OCI_COMPARTMENT_ID:-}" ]]; then
if [[ -n "${oci_bin}" && -n "${instance_compartment}" ]]; then
vnic_id="$("${oci_bin}" compute vnic-attachment list \
--compartment-id "${LAB_OCI_COMPARTMENT_ID}" \
--compartment-id "${instance_compartment}" \
--instance-id "${discovered_edge_instance_id}" \
--query 'data[0]."vnic-id"' --raw-output 2>/dev/null || true)"
if [[ -n "${vnic_id}" && "${vnic_id}" != "null" ]]; then
@ -8027,7 +8033,12 @@ refresh_oci_edge_endpoint() {
fi
fi
fi
if [[ -z "${discovered_edge_ip}" || "${discovered_edge_ip}" == "null" ]]; then
if [[ "${LAB_OCI_EDGE_INSTANCE_MANAGED:-false}" == "true" ]]; then
echo "Jeannie-managed OCI edge instance has no resolvable public IP; refusing stale LAB_EDGE_HOST." >&2
return 1
fi
return 0
fi
if [[ "${LAB_EDGE_HOST:-}" != "${discovered_edge_ip}" ]]; then