feat: add OCI authentication bootstrap helper
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

This commit is contained in:
juvenal.diaz 2026-10-23 16:48:14 -06:00
parent c06ef5e0b7
commit 1f1bcbff72
5 changed files with 115 additions and 0 deletions

View File

@ -10,6 +10,12 @@ Credentials come from the standard OCI CLI configuration (`~/.oci/config`);
private keys are not stored in the repository. Use `./jeannie oci-foundation
plan` first, inspect the plan, then apply from the Debian pipeline host.
Prepare the config with `./jeannie oci-auth init`. The command creates the
private key locally, prints the public key for the one-time OCI user upload,
and writes the config with restrictive permissions. It never sends the private
key to the API or stores it in Git. Run `./jeannie oci-auth check` after the
public key has been uploaded.
At minimum, set `LAB_OCI_FOUNDATION_ENABLED=true`, `LAB_OCI_REGION`,
`LAB_OCI_TENANCY_ID`, `LAB_OCI_ADMIN_CIDR`, `LAB_OCI_SSH_PUBLIC_KEY`, and
the image and availability-domain variables for both VMs. Use

View File

@ -65,6 +65,7 @@ var allowedCommands = map[string]bool{
"pimox": true,
"email-vm": true,
"oci-foundation": true,
"oci-auth": true,
"secrets-init": true, "secrets-check": true, "tailnet-policy-check": true,
"secrets": true,
"ai-index": true, "ai-check": true, "ask": true, "ai-evals": true,

View File

@ -125,6 +125,7 @@ Observability And GitOps
email-vm {status|plan|apply|destroy --yes} Manage the independent OCI email learning VM.
oci-foundation {status|plan|apply|destroy --yes}
Create the opt-in OCI compartment, network, edge VM, and email VM.
oci-auth {init [--force]|check} Prepare/check OCI API-key authentication on Debian.
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.
@ -296,6 +297,9 @@ case "${1:-}" in
oci-foundation)
oci_foundation_manage "${@:2}"
;;
oci-auth)
oci_auth_manage "${@:2}"
;;
edge-cache-flush)
edge_flush_caches
;;

View File

@ -3368,6 +3368,11 @@ oci_foundation_manage() {
esac
}
oci_auth_manage() {
require_debian_server "oci-auth"
"${REPO_ROOT}/scripts/oci-auth" "$@"
}
storage_status() {
require_debian_server "storage"
local kubeconfig="${KUBECONFIG_PATH}"

99
scripts/oci-auth Executable file
View File

@ -0,0 +1,99 @@
#!/usr/bin/env bash
set -euo pipefail
action="${1:-check}"
if [[ "${JEANNIE_REMOTE_SERVER:-false}" == "true" && "${action}" == "init" ]]; then
echo "oci-auth init requires an interactive Debian session; run it directly on the Debian host." >&2
exit 2
fi
profile="${OCI_CLI_PROFILE:-${OCI_CONFIG_PROFILE:-DEFAULT}}"
config_file="${OCI_CONFIG_FILE:-${HOME}/.oci/config}"
key_file="${OCI_PRIVATE_KEY_PATH:-${HOME}/.oci/oci_api_key.pem}"
public_key_file="${key_file}.pub"
fingerprint_for_key() {
openssl rsa -in "$1" -pubout -outform DER 2>/dev/null \
| openssl md5 -c 2>/dev/null \
| awk '{print $2}'
}
check_auth() {
local fingerprint
[[ -r "${config_file}" ]] || { echo "OCI config missing: ${config_file}" >&2; return 1; }
[[ -r "${key_file}" ]] || { echo "OCI private key missing: ${key_file}" >&2; return 1; }
fingerprint="$(fingerprint_for_key "${key_file}")"
[[ -n "${fingerprint}" ]] || { echo "Unable to calculate key fingerprint." >&2; return 1; }
echo "OCI config: ${config_file}"
echo "OCI profile: ${profile}"
echo "Key fingerprint: ${fingerprint}"
if command -v oci >/dev/null 2>&1; then
OCI_CONFIG_FILE="${config_file}" OCI_CLI_PROFILE="${profile}" \
oci iam region list --query 'data[0].name' --raw-output >/dev/null
echo "OCI API authentication: OK"
else
echo "OCI CLI not installed; local config/key validation passed."
fi
}
init_auth() {
local tenancy user region fingerprint force="false"
if [[ "${2:-}" == "--force" ]]; then
force="true"
elif [[ -e "${config_file}" && "${profile}" == "DEFAULT" ]]; then
echo "Refusing to overwrite ${config_file}; use --force only if you intend to replace the profile." >&2
return 2
fi
mkdir -p "$(dirname "${config_file}")"
chmod 700 "$(dirname "${config_file}")"
if [[ ! -e "${key_file}" ]]; then
echo "Generating RSA API signing key at ${key_file}..."
openssl genrsa -out "${key_file}" 2048 >/dev/null 2>&1
chmod 600 "${key_file}"
elif [[ "${force}" == "true" ]]; then
chmod 600 "${key_file}"
fi
openssl rsa -in "${key_file}" -pubout -out "${public_key_file}" 2>/dev/null
chmod 644 "${public_key_file}"
read -r -p "OCI tenancy OCID: " tenancy
read -r -p "OCI user OCID: " user
read -r -p "OCI region [${OCI_REGION:-us-phoenix-1}]: " region
region="${region:-${OCI_REGION:-us-phoenix-1}}"
fingerprint="$(fingerprint_for_key "${key_file}")"
CONFIG_FILE="${config_file}" PROFILE="${profile}" TENANCY="${tenancy}" USER_OCID="${user}" \
REGION="${region}" FINGERPRINT="${fingerprint}" KEY_FILE="${key_file}" \
python3 - <<'PY'
import configparser, os
path = os.environ["CONFIG_FILE"]
profile = os.environ["PROFILE"]
parser = configparser.ConfigParser(interpolation=None)
parser.optionxform = str
if os.path.exists(path):
parser.read(path)
parser[profile] = {
"user": os.environ["USER_OCID"],
"fingerprint": os.environ["FINGERPRINT"],
"tenancy": os.environ["TENANCY"],
"region": os.environ["REGION"],
"key_file": os.environ["KEY_FILE"],
}
with open(path, "w", encoding="utf-8") as handle:
parser.write(handle)
os.chmod(path, 0o600)
PY
echo "Wrote ${config_file} profile ${profile}."
echo "Upload this public key to the OCI user before running the check:"
cat "${public_key_file}"
echo "Fingerprint: ${fingerprint}"
echo "Run: ./jeannie oci-auth check"
}
case "${action}" in
init) init_auth "$@" ;;
check) check_auth ;;
*) echo "Usage: ./jeannie oci-auth {init [--force]|check}" >&2; exit 2 ;;
esac