feat: manage OCI backup bucket in foundation

This commit is contained in:
juvenal.diaz 2026-10-27 12:32:29 -06:00
parent 7445cf8782
commit 2f3459a788
7 changed files with 81 additions and 0 deletions

View File

@ -97,3 +97,17 @@ Explicit OCIDs and key paths can also be supplied:
The same operation is available through the remote API as
`./jeannie remote oci bastion ssh`; it executes on the Debian pipeline host,
keeping OCI credentials and the private SSH key off the client.
The foundation also creates a private, versioned Object Storage bucket named
`homelab-backups` by default. Jeannie persists the discovered bucket name,
namespace, and OCID as `LAB_OCI_BACKUP_BUCKET`,
`LAB_OCI_BACKUP_BUCKET_NAMESPACE`, and `LAB_OCI_BACKUP_BUCKET_ID` in the local
foundation inventory. Backup archives are expected to be encrypted with age
before upload. The bucket has a Terraform `prevent_destroy` guard so a normal
foundation destroy cannot remove backup data; reset it only as an explicitly
reviewed backup-reset change. Validate readiness without changing storage with:
```text
./jeannie backup oci status
./jeannie remote backup oci status
```

View File

@ -18,6 +18,28 @@ data "oci_core_subnet" "existing_public" {
subnet_id = var.existing_public_subnet_id
}
data "oci_objectstorage_namespace" "homelab" {
count = var.enabled && var.backup_bucket_enabled ? 1 : 0
compartment_id = var.tenancy_id
}
resource "oci_objectstorage_bucket" "homelab_backups" {
count = var.enabled && var.backup_bucket_enabled ? 1 : 0
compartment_id = local.target_compartment_id
namespace = trimspace(var.backup_bucket_namespace) != "" ? var.backup_bucket_namespace : data.oci_objectstorage_namespace.homelab[0].namespace
name = var.backup_bucket_name
access_type = "NoPublicAccess"
storage_tier = "Standard"
versioning = "Enabled"
freeform_tags = merge(local.base_tags, { purpose = "homelab-encrypted-backups" })
lifecycle {
# Backup data must not disappear during a routine foundation destroy.
# Remove this guard only in an explicitly reviewed backup reset change.
prevent_destroy = true
}
}
resource "oci_identity_compartment" "homelab" {
count = var.enabled && var.create_compartment ? 1 : 0
compartment_id = var.tenancy_id

View File

@ -9,6 +9,9 @@ output "email_instance_id" { value = try(oci_core_instance.email[0].id, null) }
output "email_public_ip" { value = try(oci_core_instance.email[0].public_ip, null) }
output "bastion_id" { value = try(oci_bastion_bastion.homelab[0].id, null) }
output "bastion_target_subnet_id" { value = try(oci_bastion_bastion.homelab[0].target_subnet_id, null) }
output "backup_bucket_id" { value = try(oci_objectstorage_bucket.homelab_backups[0].id, null) }
output "backup_bucket_name" { value = try(oci_objectstorage_bucket.homelab_backups[0].name, null) }
output "backup_bucket_namespace" { value = try(oci_objectstorage_bucket.homelab_backups[0].namespace, null) }
output "next_steps" {
value = [
"Set LAB_EDGE_HOST to edge_public_ip and run ./jeannie edge to configure the edge proxy.",

View File

@ -130,6 +130,24 @@ variable "monitoring_cidr" {
default = ""
}
variable "backup_bucket_enabled" {
description = "Create a private OCI Object Storage bucket for encrypted Jeannie backups."
type = bool
default = true
}
variable "backup_bucket_name" {
description = "Object Storage bucket name for encrypted Jeannie backups."
type = string
default = "homelab-backups"
}
variable "backup_bucket_namespace" {
description = "Optional Object Storage namespace override; normally discovered from the tenancy."
type = string
default = ""
}
variable "bastion_enabled" {
description = "Create an OCI Bastion service for time-limited SSH sessions."
type = bool

View File

@ -3602,6 +3602,7 @@ oci_foundation_config_names=(
LAB_OCI_AUTO_CONFIGURE_EMAIL LAB_OCI_AUTO_UPDATE_DUCKDNS LAB_DUCKDNS_DOMAINS
LAB_OCI_FOUNDATION_STATE_FILE
LAB_OCI_MONITORING_ENABLED LAB_OCI_MONITORING_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_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_INSTANCE_ID
LAB_EMAIL_PUBLIC_IP LAB_OCI_EDGE_METRICS_TARGET LAB_OCI_EMAIL_METRICS_TARGET
@ -3799,11 +3800,17 @@ oci_foundation_manage() {
local discovered_edge_ip
local discovered_email_ip
local discovered_bastion_id
local discovered_backup_bucket_name
local discovered_backup_bucket_namespace
local discovered_backup_bucket_id
local discovered_edge_instance_id
local post_apply_failures=0
discovered_edge_ip="$(tofu -chdir="${stack}" output "${tofu_state_args[@]}" -raw edge_public_ip 2>/dev/null || true)"
discovered_email_ip="$(tofu -chdir="${stack}" output "${tofu_state_args[@]}" -raw email_public_ip 2>/dev/null || true)"
discovered_bastion_id="$(tofu -chdir="${stack}" output "${tofu_state_args[@]}" -raw bastion_id 2>/dev/null || true)"
discovered_backup_bucket_name="$(tofu -chdir="${stack}" output "${tofu_state_args[@]}" -raw backup_bucket_name 2>/dev/null || true)"
discovered_backup_bucket_namespace="$(tofu -chdir="${stack}" output "${tofu_state_args[@]}" -raw backup_bucket_namespace 2>/dev/null || true)"
discovered_backup_bucket_id="$(tofu -chdir="${stack}" output "${tofu_state_args[@]}" -raw backup_bucket_id 2>/dev/null || true)"
discovered_edge_instance_id="$(tofu -chdir="${stack}" output "${tofu_state_args[@]}" -raw edge_instance_id 2>/dev/null || true)"
if [[ -n "${discovered_bastion_id}" && "${discovered_bastion_id}" != "null" ]]; then
export LAB_OCI_BASTION_ID="${discovered_bastion_id}"
@ -3811,6 +3818,16 @@ oci_foundation_manage() {
if [[ -n "${discovered_edge_instance_id}" && "${discovered_edge_instance_id}" != "null" ]]; then
export LAB_OCI_EDGE_INSTANCE_ID="${discovered_edge_instance_id}"
fi
if [[ -n "${discovered_backup_bucket_name}" && "${discovered_backup_bucket_name}" != "null" ]]; then
export LAB_OCI_BACKUP_BUCKET="${discovered_backup_bucket_name}"
export LAB_OCI_BACKUP_BUCKET_NAME="${discovered_backup_bucket_name}"
fi
if [[ -n "${discovered_backup_bucket_namespace}" && "${discovered_backup_bucket_namespace}" != "null" ]]; then
export LAB_OCI_BACKUP_BUCKET_NAMESPACE="${discovered_backup_bucket_namespace}"
fi
if [[ -n "${discovered_backup_bucket_id}" && "${discovered_backup_bucket_id}" != "null" ]]; then
export LAB_OCI_BACKUP_BUCKET_ID="${discovered_backup_bucket_id}"
fi
if truthy "${LAB_OCI_BASTION_ENABLED:-true}"; then
if [[ -n "${discovered_edge_instance_id}" && "${discovered_edge_instance_id}" != "null" ]]; then
printf 'Enabling OCI Bastion plugin on edge instance...\n'

View File

@ -361,6 +361,9 @@ export_oci_foundation_tf_vars() {
export_if_unset TF_VAR_admin_cidr "${LAB_OCI_ADMIN_CIDR:-}"
export_if_unset TF_VAR_monitoring_enabled "${LAB_OCI_MONITORING_ENABLED:-}"
export_if_unset TF_VAR_monitoring_cidr "${LAB_OCI_MONITORING_CIDR:-${LAB_OCI_ADMIN_CIDR:-}}"
export_if_unset TF_VAR_backup_bucket_enabled "${LAB_OCI_BACKUP_BUCKET_ENABLED:-}"
export_if_unset TF_VAR_backup_bucket_name "${LAB_OCI_BACKUP_BUCKET_NAME:-${LAB_OCI_BACKUP_BUCKET:-}}"
export_if_unset TF_VAR_backup_bucket_namespace "${LAB_OCI_BACKUP_BUCKET_NAMESPACE:-}"
export_if_unset TF_VAR_bastion_enabled "${LAB_OCI_BASTION_ENABLED:-}"
export_if_unset TF_VAR_bastion_name "${LAB_OCI_BASTION_NAME:-}"
export_if_unset TF_VAR_bastion_target_subnet_id "${LAB_OCI_BASTION_TARGET_SUBNET_ID:-}"

View File

@ -8,6 +8,7 @@ OCI_CONFIG="${OCI_CONFIG_FILE:-${HOME}/.oci/config}"
OCI_KEY="${OCI_PRIVATE_KEY_PATH:-${HOME}/.oci/oci_api_key.pem}"
OCI_REGION="${LAB_OCI_REGION:-${OCI_REGION:-}}"
BUCKET="${LAB_OCI_BACKUP_BUCKET:-${OCI_OBJECT_STORAGE_BUCKET:-}}"
BUCKET_ID="${LAB_OCI_BACKUP_BUCKET_ID:-}"
PREFIX="${LAB_OCI_BACKUP_PREFIX:-homelab/}"
SOPS_CONFIG="${SOPS_CONFIG:-${REPO_ROOT}/.sops.yaml}"
AGE_KEY_FILE="${SOPS_AGE_KEY_FILE:-${HOME}/.config/sops/age/keys.txt}"
@ -30,6 +31,9 @@ fi
printf 'OCI Object Storage backup %s\n' "${ACTION}"
printf 'region=%s profile=%s bucket=%s prefix=%s\n' \
"${OCI_REGION:-unset}" "${OCI_PROFILE}" "${BUCKET:-unset}" "${PREFIX}"
if [[ -n "${BUCKET_ID}" ]]; then
printf 'bucket_id=%s\n' "${BUCKET_ID}"
fi
printf 'No uploads, deletes, bucket changes, or lifecycle changes are performed.\n'
oci_bin=""