Bypass Bastion requirements for direct Tailscale edge SSH
This commit is contained in:
parent
6fbbd5ae6a
commit
9d00c558e4
|
|
@ -7994,6 +7994,7 @@ edge_apply() {
|
||||||
fi
|
fi
|
||||||
prepare_oci_edge_bastion || return 1
|
prepare_oci_edge_bastion || return 1
|
||||||
fi
|
fi
|
||||||
|
edge_require_ssh_transport || return 1
|
||||||
edge_ssh_args
|
edge_ssh_args
|
||||||
local ssh_host="${TF_VAR_edge_ssh_host}" ssh_user="${TF_VAR_edge_user:-${LAB_EDGE_USER:-ubuntu}}"
|
local ssh_host="${TF_VAR_edge_ssh_host}" ssh_user="${TF_VAR_edge_user:-${LAB_EDGE_USER:-ubuntu}}"
|
||||||
# One bounded authentication check gives a useful error before OpenTofu
|
# One bounded authentication check gives a useful error before OpenTofu
|
||||||
|
|
@ -8238,10 +8239,37 @@ refresh_oci_edge_host_key() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
edge_require_ssh_transport() {
|
||||||
|
case "${LAB_EDGE_SSH_TRANSPORT:-tailscale}" in
|
||||||
|
tailscale)
|
||||||
|
if [[ -z "${TF_VAR_edge_ssh_host:-}" ||
|
||||||
|
"${TF_VAR_edge_ssh_host}" != "${LAB_EDGE_TAILSCALE_IP:-}" ]]; then
|
||||||
|
echo "The edge Tailscale SSH endpoint has not been resolved." >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
bastion)
|
||||||
|
if [[ -z "${TF_VAR_edge_ssh_host:-}" ||
|
||||||
|
-z "${LAB_OCI_EDGE_BASTION_PROXY_COMMAND:-}" ]]; then
|
||||||
|
echo "Bastion SSH was selected but its private route/session is not ready." >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "LAB_EDGE_SSH_TRANSPORT must be tailscale or bastion." >&2
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
edge_ssh_args() {
|
edge_ssh_args() {
|
||||||
local edge_key="${TF_VAR_edge_ssh_key_path:-${LAB_EDGE_SSH_KEY_PATH:-${LAB_OCI_SSH_PRIVATE_KEY:-${HOME}/.ssh/id_ed25519}}}"
|
local edge_key="${TF_VAR_edge_ssh_key_path:-${LAB_EDGE_SSH_KEY_PATH:-${LAB_OCI_SSH_PRIVATE_KEY:-${HOME}/.ssh/id_ed25519}}}"
|
||||||
EDGE_SSH_ARGS=(-i "${edge_key}" -o BatchMode=yes -o ConnectTimeout="${LAB_EDGE_SSH_PREFLIGHT_SECONDS:-10}" -o ConnectionAttempts=1 -o IdentitiesOnly=yes -o StrictHostKeyChecking=accept-new)
|
EDGE_SSH_ARGS=(-i "${edge_key}" -o BatchMode=yes -o ConnectTimeout="${LAB_EDGE_SSH_PREFLIGHT_SECONDS:-10}" -o ConnectionAttempts=1 -o IdentitiesOnly=yes -o StrictHostKeyChecking=accept-new)
|
||||||
if [[ -n "${LAB_OCI_EDGE_BASTION_PROXY_COMMAND:-}" ]]; then
|
if [[ "${LAB_EDGE_SSH_TRANSPORT:-tailscale}" == "tailscale" ]]; then
|
||||||
|
# Direct tailnet SSH must also bypass ProxyJump/ProxyCommand inherited
|
||||||
|
# from an operator's SSH config or a previous Bastion invocation.
|
||||||
|
EDGE_SSH_ARGS+=( -o ProxyCommand=none -o ProxyJump=none )
|
||||||
|
elif [[ -n "${LAB_OCI_EDGE_BASTION_PROXY_COMMAND:-}" ]]; then
|
||||||
if [[ "${LAB_OCI_EDGE_BASTION_PROXY_COMMAND}" == *'%h:%p'* ]]; then
|
if [[ "${LAB_OCI_EDGE_BASTION_PROXY_COMMAND}" == *'%h:%p'* ]]; then
|
||||||
EDGE_SSH_ARGS+=( -o "ProxyCommand=${LAB_OCI_EDGE_BASTION_PROXY_COMMAND}" )
|
EDGE_SSH_ARGS+=( -o "ProxyCommand=${LAB_OCI_EDGE_BASTION_PROXY_COMMAND}" )
|
||||||
else
|
else
|
||||||
|
|
@ -8349,11 +8377,7 @@ ensure_edge_tailscale_routes() {
|
||||||
echo "LAB_EDGE_HOST or TF_VAR_edge_host is required to configure edge Tailscale routes." >&2
|
echo "LAB_EDGE_HOST or TF_VAR_edge_host is required to configure edge Tailscale routes." >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
if truthy "${LAB_OCI_BASTION_ENABLED:-false}" && [[ -n "${LAB_OCI_BASTION_ID:-}" ]] &&
|
edge_require_ssh_transport || return 1
|
||||||
[[ -z "${TF_VAR_edge_ssh_host:-}" || -z "${LAB_OCI_EDGE_BASTION_PROXY_COMMAND:-}" ]]; then
|
|
||||||
echo "OCI Bastion is enabled but no private edge SSH route/session is ready; refusing public SSH fallback." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
case "${router}" in
|
case "${router}" in
|
||||||
debian)
|
debian)
|
||||||
|
|
@ -8471,7 +8495,7 @@ if ! command -v tailscale >/dev/null 2>&1; then
|
||||||
fi
|
fi
|
||||||
sudo tailscale set --accept-routes=true
|
sudo tailscale set --accept-routes=true
|
||||||
"; then
|
"; then
|
||||||
echo "OCI edge SSH preflight failed via Bastion (${edge_host})." >&2
|
echo "OCI edge SSH preflight failed via ${LAB_EDGE_SSH_TRANSPORT:-tailscale} (${edge_host})." >&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import io
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import subprocess
|
||||||
from types import SimpleNamespace
|
from types import SimpleNamespace
|
||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
|
|
@ -184,6 +185,49 @@ class ResolverTests(unittest.TestCase):
|
||||||
self.assertIn("export TF_VAR_edge_host=192.0.2.10", output.getvalue())
|
self.assertIn("export TF_VAR_edge_host=192.0.2.10", output.getvalue())
|
||||||
self.assertIn("export TF_VAR_edge_ssh_host=100.64.0.10", output.getvalue())
|
self.assertIn("export TF_VAR_edge_ssh_host=100.64.0.10", output.getvalue())
|
||||||
|
|
||||||
|
def test_shell_tailnet_transport_bypasses_enabled_bastion_and_stale_proxy(self):
|
||||||
|
# Exercise the actual guard called by edge_apply and route setup.
|
||||||
|
# Only shell function definitions and argument construction run here.
|
||||||
|
shell = r"""
|
||||||
|
set -euo pipefail
|
||||||
|
source "$1"
|
||||||
|
LAB_OCI_BASTION_ENABLED=true
|
||||||
|
LAB_OCI_BASTION_ID=ocid1.bastion.existing
|
||||||
|
LAB_EDGE_SSH_TRANSPORT=tailscale
|
||||||
|
LAB_EDGE_TAILSCALE_IP=100.122.188.79
|
||||||
|
TF_VAR_edge_ssh_host=100.122.188.79
|
||||||
|
LAB_OCI_EDGE_BASTION_PROXY_COMMAND='ssh stale-bastion'
|
||||||
|
edge_require_ssh_transport
|
||||||
|
edge_ssh_args
|
||||||
|
printf '%s\n' "${EDGE_SSH_ARGS[@]}"
|
||||||
|
"""
|
||||||
|
result = subprocess.run(["bash", "-c", shell, "test",
|
||||||
|
str(SOURCE.parents[1] / "lib/jeannie/pipeline.sh")],
|
||||||
|
capture_output=True, text=True, check=True)
|
||||||
|
self.assertIn("ProxyCommand=none", result.stdout)
|
||||||
|
self.assertIn("ProxyJump=none", result.stdout)
|
||||||
|
self.assertNotIn("stale-bastion", result.stdout)
|
||||||
|
|
||||||
|
def test_shell_bastion_transport_still_requires_a_session(self):
|
||||||
|
shell = r"""
|
||||||
|
set -euo pipefail
|
||||||
|
source "$1"
|
||||||
|
LAB_EDGE_SSH_TRANSPORT=bastion
|
||||||
|
TF_VAR_edge_ssh_host=10.50.10.103
|
||||||
|
unset LAB_OCI_EDGE_BASTION_PROXY_COMMAND
|
||||||
|
if edge_require_ssh_transport; then exit 99; fi
|
||||||
|
LAB_OCI_EDGE_BASTION_PROXY_COMMAND='ssh session@bastion -W %h:%p'
|
||||||
|
edge_require_ssh_transport
|
||||||
|
edge_ssh_args
|
||||||
|
printf '%s\n' "${EDGE_SSH_ARGS[@]}"
|
||||||
|
"""
|
||||||
|
result = subprocess.run(["bash", "-c", shell, "test",
|
||||||
|
str(SOURCE.parents[1] / "lib/jeannie/pipeline.sh")],
|
||||||
|
capture_output=True, text=True, check=True)
|
||||||
|
self.assertIn("route/session is not ready", result.stderr)
|
||||||
|
self.assertIn("ProxyCommand=ssh session@bastion", result.stdout)
|
||||||
|
self.assertNotIn("ProxyCommand=none", result.stdout)
|
||||||
|
|
||||||
def test_plan_rejects_delete_and_replacement(self):
|
def test_plan_rejects_delete_and_replacement(self):
|
||||||
for actions in (["delete"], ["delete", "create"], ["create", "delete"]):
|
for actions in (["delete"], ["delete", "create"], ["create", "delete"]):
|
||||||
with self.subTest(actions=actions), self.assertRaises(ValueError):
|
with self.subTest(actions=actions), self.assertRaises(ValueError):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue