feat: accept client SSH key for Bastion sessions
This commit is contained in:
parent
480a2b9f0b
commit
07381c8158
|
|
@ -2,13 +2,20 @@
|
|||
set -euo pipefail
|
||||
|
||||
print_command=false
|
||||
public_key_material=""
|
||||
private_key_override=""
|
||||
if [[ "${1:-}" == "ssh" ]]; then
|
||||
shift
|
||||
fi
|
||||
if [[ "${1:-}" == "--print-command" ]]; then
|
||||
print_command=true
|
||||
shift
|
||||
fi
|
||||
while (($# > 0)); do
|
||||
case "$1" in
|
||||
--print-command) print_command=true; shift ;;
|
||||
--public-key) public_key_material="${2:-}"; shift 2 ;;
|
||||
--private-key-path) private_key_override="${2:-}"; shift 2 ;;
|
||||
--) shift; break ;;
|
||||
*) break ;;
|
||||
esac
|
||||
done
|
||||
|
||||
oci_bin="${OCI_CLI_BIN:-}"
|
||||
if [[ -z "${oci_bin}" ]]; then
|
||||
|
|
@ -24,6 +31,9 @@ target_id="${2:-${LAB_OCI_TARGET_INSTANCE_ID:-${LAB_OCI_EDGE_INSTANCE_ID:-${LAB_
|
|||
target_user="${3:-${LAB_OCI_BASTION_TARGET_USER:-ubuntu}}"
|
||||
public_key="${4:-${LAB_OCI_SSH_PUBLIC_KEY_PATH:-${HOME}/.ssh/id_ed25519.pub}}"
|
||||
private_key="${5:-${LAB_OCI_SSH_PRIVATE_KEY_PATH:-${public_key%.pub}}}"
|
||||
if [[ -n "${private_key_override}" ]]; then
|
||||
private_key="${private_key_override}"
|
||||
fi
|
||||
session_ttl="${LAB_OCI_BASTION_SESSION_TTL:-3600}"
|
||||
|
||||
if [[ ! -x "${oci_bin}" ]]; then
|
||||
|
|
@ -31,12 +41,22 @@ if [[ ! -x "${oci_bin}" ]]; then
|
|||
exit 2
|
||||
fi
|
||||
if [[ -z "${bastion_id}" || -z "${target_id}" ]]; then
|
||||
echo "Usage: ./jeannie oci bastion ssh [--print-command] [BASTION_OCID] [TARGET_INSTANCE_OCID] [OS_USER] [SSH_PUBLIC_KEY] [SSH_PRIVATE_KEY]" >&2
|
||||
echo "Usage: ./jeannie oci bastion ssh [--print-command] [--public-key 'OPENSSH_PUBLIC_KEY'] [--private-key-path PATH] [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
|
||||
temporary_public_key=""
|
||||
cleanup_public_key() { [[ -n "${temporary_public_key}" ]] && rm -f "${temporary_public_key}"; }
|
||||
trap cleanup_public_key EXIT
|
||||
if [[ -n "${public_key_material}" ]]; then
|
||||
temporary_public_key="$(mktemp)"
|
||||
printf '%s\n' "${public_key_material}" >"${temporary_public_key}"
|
||||
public_key="${temporary_public_key}"
|
||||
fi
|
||||
[[ -f "${public_key}" ]] || { echo "SSH public key not found: ${public_key}" >&2; exit 2; }
|
||||
[[ -f "${private_key}" ]] || { echo "SSH private key not found: ${private_key}" >&2; exit 2; }
|
||||
if [[ "${print_command}" != true ]]; then
|
||||
[[ -f "${private_key}" ]] || { echo "SSH private key not found: ${private_key}" >&2; exit 2; }
|
||||
fi
|
||||
|
||||
session_json="$("${oci_bin}" bastion session create-managed-ssh \
|
||||
--bastion-id "${bastion_id}" \
|
||||
|
|
|
|||
Loading…
Reference in New Issue