Use Tailscale for internal edge SSH
This commit is contained in:
parent
bbbb71d60f
commit
b8d08045ea
|
|
@ -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" {
|
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
|
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
|
network_security_group_id = oci_core_network_security_group.edge[0].id
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,12 @@ variable "admin_cidr" {
|
||||||
default = ""
|
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" {
|
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."
|
description = "Open SMTP submission, SMTP, and IMAPS ingress in the email NSG. Keep false until DNS/PTR and hardening are complete."
|
||||||
type = bool
|
type = bool
|
||||||
|
|
|
||||||
|
|
@ -790,6 +790,12 @@ else
|
||||||
fi"
|
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() {
|
start_bastion_compose_stack() {
|
||||||
local label="$1" bastion_id="$2" instance_id="$3" user="$4" public_key="$5" private_key="$6" install_dir="$7"
|
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}" ]] || {
|
[[ -n "${bastion_id}" && -n "${instance_id}" ]] || {
|
||||||
|
|
@ -812,10 +818,13 @@ shutdown_rpi_services() {
|
||||||
|
|
||||||
shutdown_oci_edge_services() {
|
shutdown_oci_edge_services() {
|
||||||
local edge_host="${LAB_EDGE_HOST:-${LAB_OCI_EDGE_PUBLIC_IP:-}}"
|
local edge_host="${LAB_EDGE_HOST:-${LAB_OCI_EDGE_PUBLIC_IP:-}}"
|
||||||
|
local edge_tailnet_host
|
||||||
local edge_user="${LAB_EDGE_USER:-ubuntu}"
|
local edge_user="${LAB_EDGE_USER:-ubuntu}"
|
||||||
local edge_key="${LAB_EDGE_SSH_KEY_PATH:-${LAB_OCI_SSH_PRIVATE_KEY:-}}"
|
local edge_key="${LAB_EDGE_SSH_KEY_PATH:-${LAB_OCI_SSH_PRIVATE_KEY:-}}"
|
||||||
local install_dir="${LAB_EDGE_INSTALL_DIR:-/opt/homelab-edge}"
|
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}" ]] || {
|
[[ -n "${edge_host}" ]] || {
|
||||||
echo "OCI edge host is not configured; set LAB_EDGE_HOST or LAB_OCI_EDGE_PUBLIC_IP." >&2
|
echo "OCI edge host is not configured; set LAB_EDGE_HOST or LAB_OCI_EDGE_PUBLIC_IP." >&2
|
||||||
return 1
|
return 1
|
||||||
|
|
@ -896,11 +905,15 @@ start_rpi_services() {
|
||||||
|
|
||||||
start_oci_edge_services() {
|
start_oci_edge_services() {
|
||||||
local edge_host="${LAB_EDGE_HOST:-${LAB_OCI_EDGE_PUBLIC_IP:-}}"
|
local edge_host="${LAB_EDGE_HOST:-${LAB_OCI_EDGE_PUBLIC_IP:-}}"
|
||||||
|
local edge_tailnet_host
|
||||||
local edge_user="${LAB_EDGE_USER:-ubuntu}"
|
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 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}"
|
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
|
edge_tailnet_host="$(tailscale_edge_host || true)"
|
||||||
start_bastion_compose_stack "OCI edge" "${LAB_OCI_BASTION_ID}" "${LAB_OCI_EDGE_INSTANCE_ID}" "${edge_user}" "${edge_key}.pub" "${edge_key}" "${install_dir}"
|
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
|
else
|
||||||
[[ -n "${edge_host}" ]] || { echo "OCI edge host is not configured." >&2; return 1; }
|
[[ -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}"
|
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_rpi_services || failures=$((failures + 1))
|
||||||
start_oci_edge_services || failures=$((failures + 1))
|
start_oci_edge_services || failures=$((failures + 1))
|
||||||
start_oci_email_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
|
if systemctl is-active --quiet jeannie-server.service 2>/dev/null; then
|
||||||
echo "PASS jeannie-server.service is active."
|
echo "PASS jeannie-server.service is active."
|
||||||
else
|
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_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_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_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_AUTO_CONFIGURE_EMAIL LAB_OCI_AUTO_UPDATE_DUCKDNS LAB_DUCKDNS_DOMAINS
|
||||||
LAB_OCI_FOUNDATION_STATE_FILE
|
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_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_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
|
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
|
||||||
|
|
|
||||||
|
|
@ -267,6 +267,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_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_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_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_user "${LAB_EDGE_USER:-}"
|
||||||
export_if_unset TF_VAR_edge_install_dir "${LAB_EDGE_INSTALL_DIR:-}"
|
export_if_unset TF_VAR_edge_install_dir "${LAB_EDGE_INSTALL_DIR:-}"
|
||||||
local edge_tailscale_auth_key="${LAB_EDGE_TAILSCALE_AUTH_KEY:-}"
|
local edge_tailscale_auth_key="${LAB_EDGE_TAILSCALE_AUTH_KEY:-}"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue