Compare commits

..

4 Commits

Author SHA1 Message Date
juvenal.diaz 0079a89a6c Track current OCI edge Tailscale address
Homelab Main / validate (push) Waiting to run Details
Homelab Main / running-update (push) Blocked by required conditions Details
Homelab Main / debian-ops (push) Blocked by required conditions Details
2026-10-29 10:32:50 -06:00
juvenal.diaz f3cb08ecad Make API deployment idempotent on staged repository 2026-10-29 09:27:13 -06:00
juvenal.diaz fed3c21d68 Fallback OCI edge alarm compartment 2026-10-29 09:05:33 -06:00
juvenal.diaz b8d08045ea Use Tailscale for internal edge SSH 2026-10-29 08:53:02 -06:00
6 changed files with 51 additions and 8 deletions

View File

@ -16,8 +16,8 @@ locals {
base_tags = merge(var.freeform_tags, { managed_by = "jeannie", purpose = "homelab-learning" })
edge_monitoring_instance_id = trimspace(var.edge_monitoring_instance_id) != "" ? var.edge_monitoring_instance_id : try(oci_core_instance.edge[0].id, try(data.oci_core_instance.monitoring_edge[0].id, try(data.oci_core_instance.existing_edge[0].id, null)))
email_monitoring_instance_id = trimspace(var.email_monitoring_instance_id) != "" ? var.email_monitoring_instance_id : try(oci_core_instance.email[0].id, try(data.oci_core_instance.monitoring_email[0].id, null))
edge_monitoring_compartment_id = try(data.oci_core_instance.monitoring_edge[0].compartment_id, try(data.oci_core_instance.existing_edge[0].compartment_id, local.target_compartment_id))
email_monitoring_compartment_id = try(data.oci_core_instance.monitoring_email[0].compartment_id, local.email_compartment_id)
edge_monitoring_compartment_id = coalesce(try(data.oci_core_instance.monitoring_edge[0].compartment_id, null), try(data.oci_core_instance.existing_edge[0].compartment_id, null), local.target_compartment_id)
email_monitoring_compartment_id = coalesce(try(data.oci_core_instance.monitoring_email[0].compartment_id, null), local.email_compartment_id)
}
data "oci_core_subnet" "existing_public" {
@ -253,6 +253,21 @@ resource "oci_core_network_security_group_security_rule" "edge_ssh" {
}
}
resource "oci_core_network_security_group_security_rule" "edge_tailnet_ssh" {
count = var.enabled && var.edge_enabled && trimspace(var.edge_tailnet_ssh_cidr) != "" ? 1 : 0
network_security_group_id = oci_core_network_security_group.edge[0].id
direction = "INGRESS"
protocol = "6"
source = var.edge_tailnet_ssh_cidr
source_type = "CIDR_BLOCK"
tcp_options {
destination_port_range {
min = 22
max = 22
}
}
}
resource "oci_core_network_security_group_security_rule" "edge_bastion_ssh" {
count = var.enabled && var.edge_enabled && var.bastion_enabled && trimspace(local.bastion_ssh_source_cidr) != "" ? 1 : 0
network_security_group_id = oci_core_network_security_group.edge[0].id

View File

@ -112,6 +112,12 @@ variable "admin_cidr" {
default = ""
}
variable "edge_tailnet_ssh_cidr" {
description = "Tailscale CGNAT range allowed to SSH directly to the edge VM from the homelab tailnet."
type = string
default = "100.64.0.0/10"
}
variable "open_mail_ports" {
description = "Open SMTP submission, SMTP, and IMAPS ingress in the email NSG. Keep false until DNS/PTR and hardening are complete."
type = bool

View File

@ -117,7 +117,7 @@ hosts:
role: public-edge
user: ubuntu
public_ip: 132.145.170.74
tailscale_ip: 100.118.255.19
tailscale_ip: 100.122.188.79
install_dir: /opt/homelab-edge
services:

View File

@ -17,7 +17,13 @@ command -v go >/dev/null 2>&1 || { echo 'Go is required on Debian' >&2; exit 1;
sudo install -d -m 0755 "${install_dir}" "${repo_root}" /etc/jeannie
sudo cp infra/jeannie-temporal/docker-compose.yml "${install_dir}/docker-compose.yml"
sudo cp -R . "${repo_root}/"
current_repo="$(pwd -P)"
target_repo="$(cd "${repo_root}" && pwd -P)"
if [[ "${current_repo}" != "${target_repo}" ]]; then
sudo cp -R . "${repo_root}/"
else
echo "Repository already staged at ${repo_root}; skipping self-copy."
fi
sudo chown -R "$(id -u):$(id -g)" "${repo_root}"
if command -v ss >/dev/null 2>&1 &&

View File

@ -790,6 +790,12 @@ else
fi"
}
tailscale_edge_host() {
[[ -n "${LAB_EDGE_TAILSCALE_IP:-}" ]] && { printf '%s\n' "${LAB_EDGE_TAILSCALE_IP}"; return 0; }
command -v tailscale >/dev/null 2>&1 || return 1
tailscale status 2>/dev/null | awk '$2 == "homelab-oci-edge" || $2 == "homelab-oci-edge.tail767cd.ts.net" { print $1; exit }'
}
start_bastion_compose_stack() {
local label="$1" bastion_id="$2" instance_id="$3" user="$4" public_key="$5" private_key="$6" install_dir="$7"
[[ -n "${bastion_id}" && -n "${instance_id}" ]] || {
@ -812,10 +818,13 @@ shutdown_rpi_services() {
shutdown_oci_edge_services() {
local edge_host="${LAB_EDGE_HOST:-${LAB_OCI_EDGE_PUBLIC_IP:-}}"
local edge_tailnet_host
local edge_user="${LAB_EDGE_USER:-ubuntu}"
local edge_key="${LAB_EDGE_SSH_KEY_PATH:-${LAB_OCI_SSH_PRIVATE_KEY:-}}"
local install_dir="${LAB_EDGE_INSTALL_DIR:-/opt/homelab-edge}"
edge_tailnet_host="$(tailscale_edge_host || true)"
[[ -n "${edge_tailnet_host}" ]] && edge_host="${edge_tailnet_host}"
[[ -n "${edge_host}" ]] || {
echo "OCI edge host is not configured; set LAB_EDGE_HOST or LAB_OCI_EDGE_PUBLIC_IP." >&2
return 1
@ -896,11 +905,15 @@ start_rpi_services() {
start_oci_edge_services() {
local edge_host="${LAB_EDGE_HOST:-${LAB_OCI_EDGE_PUBLIC_IP:-}}"
local edge_tailnet_host
local edge_user="${LAB_EDGE_USER:-ubuntu}"
local edge_key="${LAB_EDGE_SSH_KEY_PATH:-${LAB_OCI_SSH_PRIVATE_KEY:-${HOME}/.ssh/id_ed25519}}"
local install_dir="${LAB_EDGE_INSTALL_DIR:-/opt/homelab-edge}"
if truthy "${LAB_OCI_BASTION_ENABLED:-true}" && [[ -n "${LAB_OCI_BASTION_ID:-}" && -n "${LAB_OCI_EDGE_INSTANCE_ID:-}" ]]; then
start_bastion_compose_stack "OCI edge" "${LAB_OCI_BASTION_ID}" "${LAB_OCI_EDGE_INSTANCE_ID}" "${edge_user}" "${edge_key}.pub" "${edge_key}" "${install_dir}"
edge_tailnet_host="$(tailscale_edge_host || true)"
if [[ -n "${edge_tailnet_host}" ]]; then
export LAB_EDGE_TAILSCALE_IP="${edge_tailnet_host}"
echo "--> Starting OCI edge services over the homelab tailnet (${edge_tailnet_host})..."
start_remote_compose_stack "OCI edge" "${edge_user}@${edge_tailnet_host}" "${install_dir}" "${edge_key}"
else
[[ -n "${edge_host}" ]] || { echo "OCI edge host is not configured." >&2; return 1; }
start_remote_compose_stack "OCI edge" "${edge_user}@${edge_host}" "${install_dir}" "${edge_key}"
@ -961,6 +974,7 @@ EOF
start_rpi_services || failures=$((failures + 1))
start_oci_edge_services || failures=$((failures + 1))
start_oci_email_services || failures=$((failures + 1))
oci_foundation_save_config
if systemctl is-active --quiet jeannie-server.service 2>/dev/null; then
echo "PASS jeannie-server.service is active."
else
@ -3747,10 +3761,10 @@ oci_foundation_config_names=(
LAB_OCI_EXISTING_VCN_ID LAB_OCI_EXISTING_PUBLIC_SUBNET_ID LAB_OCI_EXISTING_EMAIL_SUBNET_ID
LAB_OCI_EMAIL_CREATE_COMPARTMENT LAB_OCI_EMAIL_COMPARTMENT_ID LAB_OCI_EMAIL_COMPARTMENT_NAME
LAB_OCI_EMAIL_SUBNET_CIDR LAB_OCI_EDGE_AVAILABILITY_DOMAIN LAB_OCI_EMAIL_AVAILABILITY_DOMAIN
LAB_OCI_OPEN_MAIL_PORTS LAB_OCI_AUTO_CONFIGURE_EDGE LAB_EDGE_HOST
LAB_OCI_OPEN_MAIL_PORTS LAB_OCI_AUTO_CONFIGURE_EDGE LAB_EDGE_HOST LAB_EDGE_TAILSCALE_IP
LAB_OCI_AUTO_CONFIGURE_EMAIL LAB_OCI_AUTO_UPDATE_DUCKDNS LAB_DUCKDNS_DOMAINS
LAB_OCI_FOUNDATION_STATE_FILE
LAB_OCI_MONITORING_ENABLED LAB_OCI_MONITORING_CIDR LAB_OCI_MONITORING_ALARMS_ENABLED LAB_OCI_MONITORING_TOPIC_NAME LAB_OCI_MONITORING_TOPIC_ID LAB_OCI_MONITORING_NOTIFICATION_EMAIL
LAB_OCI_MONITORING_ENABLED LAB_OCI_MONITORING_CIDR LAB_OCI_MONITORING_ALARMS_ENABLED LAB_OCI_MONITORING_TOPIC_NAME LAB_OCI_MONITORING_TOPIC_ID LAB_OCI_MONITORING_NOTIFICATION_EMAIL LAB_OCI_EDGE_TAILNET_SSH_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_COMPARTMENT_ID LAB_OCI_EDGE_INSTANCE_ID LAB_OCI_EMAIL_INSTANCE_ID LAB_OCI_EDGE_INSTANCE_MANAGED

View File

@ -41,6 +41,7 @@ mapping = {
"hosts.opi5_pimox.worker_storage": "LAB_PIMOX_WORKER_STORAGE",
"hosts.oci_edge.user": "LAB_EDGE_USER",
"hosts.oci_edge.public_ip": "LAB_EDGE_HOST",
"hosts.oci_edge.tailscale_ip": "LAB_EDGE_TAILSCALE_IP",
"hosts.oci_edge.install_dir": "LAB_EDGE_INSTALL_DIR",
"services.gitea.http_port": "LAB_GITEA_HTTP_PORT",
"services.gitea.ssh_port": "LAB_GITEA_SSH_PORT",
@ -267,6 +268,7 @@ export_homelab_inventory_tf_vars() {
export_if_unset TF_VAR_pimox_template_build_user "${LAB_CLUSTER_PROVISIONING_USER:-${LAB_DEBIAN_USER:-}}"
export_if_unset TF_VAR_pimox_template_guest_ip_prefix "${LAB_LAN_IP_PREFIX:-}"
export_if_unset TF_VAR_edge_host "${LAB_EDGE_HOST:-}"
export_if_unset TF_VAR_edge_tailnet_ssh_cidr "${LAB_OCI_EDGE_TAILNET_SSH_CIDR:-${LAB_TAILSCALE_CGNAT_CIDR:-100.64.0.0/10}}"
export_if_unset TF_VAR_edge_user "${LAB_EDGE_USER:-}"
export_if_unset TF_VAR_edge_install_dir "${LAB_EDGE_INSTALL_DIR:-}"
local edge_tailscale_auth_key="${LAB_EDGE_TAILSCALE_AUTH_KEY:-}"