feat: support API-managed OCI Bastion SSH sessions
This commit is contained in:
parent
b998b5bbab
commit
480a2b9f0b
3
jeannie
3
jeannie
|
|
@ -135,7 +135,8 @@ Observability And GitOps
|
|||
oci-foundation {status|plan|apply|destroy --yes}
|
||||
Create the opt-in OCI compartment, network, edge VM, and email VM.
|
||||
oci-auth {install|init [--force]|check} Install/check OCI CLI and API-key authentication on Debian.
|
||||
oci {status|doctor|bastion ssh|cleanup} Inspect OCI resources, open Bastion SSH, or clean up infrastructure.
|
||||
oci {status|doctor|bastion ssh [--print-command]|cleanup}
|
||||
Inspect OCI resources, open Bastion SSH, or clean up infrastructure.
|
||||
edge-cache-flush Clear Nginx, Varnish, and Squid edge caches.
|
||||
promote {plan|validate|rollback APP} Run canary promotion gates and rollback plan.
|
||||
cert-check Check public DNS, TLS, and edge URL health.
|
||||
|
|
|
|||
|
|
@ -3992,6 +3992,15 @@ oci_auth_manage() {
|
|||
oci_bastion_ssh() {
|
||||
require_debian_server "oci bastion ssh"
|
||||
oci_foundation_load_config
|
||||
local target_id=""
|
||||
local -a bastion_args=("$@")
|
||||
[[ "${bastion_args[0]:-}" == "ssh" ]] && bastion_args=("${bastion_args[@]:1}")
|
||||
[[ "${bastion_args[0]:-}" == "--print-command" ]] && bastion_args=("${bastion_args[@]:1}")
|
||||
target_id="${bastion_args[1]:-${LAB_OCI_TARGET_INSTANCE_ID:-${LAB_OCI_EDGE_INSTANCE_ID:-${LAB_OCI_EDGE_EXISTING_INSTANCE_ID:-}}}}"
|
||||
if [[ -n "${target_id}" ]]; then
|
||||
printf 'Ensuring OCI Bastion plugin is enabled on %s...\n' "${target_id}" >&2
|
||||
oci_enable_bastion_plugin "${target_id}" || return 1
|
||||
fi
|
||||
"${REPO_ROOT}/scripts/oci-bastion-ssh" "$@"
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,14 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
print_command=false
|
||||
if [[ "${1:-}" == "ssh" ]]; then
|
||||
shift
|
||||
fi
|
||||
if [[ "${1:-}" == "--print-command" ]]; then
|
||||
print_command=true
|
||||
shift
|
||||
fi
|
||||
|
||||
oci_bin="${OCI_CLI_BIN:-}"
|
||||
if [[ -z "${oci_bin}" ]]; then
|
||||
|
|
@ -26,7 +31,7 @@ if [[ ! -x "${oci_bin}" ]]; then
|
|||
exit 2
|
||||
fi
|
||||
if [[ -z "${bastion_id}" || -z "${target_id}" ]]; then
|
||||
echo "Usage: ./jeannie oci bastion ssh [BASTION_OCID] [TARGET_INSTANCE_OCID] [OS_USER] [SSH_PUBLIC_KEY] [SSH_PRIVATE_KEY]" >&2
|
||||
echo "Usage: ./jeannie oci bastion ssh [--print-command] [BASTION_OCID] [TARGET_INSTANCE_OCID] [OS_USER] [SSH_PUBLIC_KEY] [SSH_PRIVATE_KEY]" >&2
|
||||
echo "Set LAB_OCI_BASTION_ID and LAB_OCI_EDGE_INSTANCE_ID to omit the OCIDs." >&2
|
||||
exit 2
|
||||
fi
|
||||
|
|
@ -47,5 +52,10 @@ ssh_command="$("${oci_bin}" bastion session get \
|
|||
--query 'data."ssh-metadata".command' \
|
||||
--raw-output)"
|
||||
ssh_command="${ssh_command//<privateKey>/${private_key}}"
|
||||
if [[ "${print_command}" == true ]]; then
|
||||
printf 'session_id=%s\n' "${session_id}"
|
||||
printf 'ssh_command=%s\n' "${ssh_command}"
|
||||
exit 0
|
||||
fi
|
||||
printf 'Connecting through OCI Bastion session %s...\n' "${session_id}" >&2
|
||||
exec bash -c "${ssh_command}"
|
||||
|
|
|
|||
Loading…
Reference in New Issue