100 lines
4.6 KiB
Markdown
100 lines
4.6 KiB
Markdown
# OCI foundation
|
|
|
|
This independent, opt-in stack creates the OCI foundation for the learning
|
|
environment: a child compartment (or uses an existing one), VCN, internet and
|
|
NAT gateways, public/private subnets, NSGs, and separate edge and email VMs.
|
|
It does not configure the operating systems, install a mail server, create DNS
|
|
records, or open mail ingress unless `open_mail_ports=true` is explicitly set.
|
|
|
|
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.
|
|
|
|
The foundation plan/apply path installs OCI CLI into
|
|
`~/.local/share/homelab/venvs/oci-cli` on Debian by default. Set
|
|
`LAB_OCI_CLI_AUTO_INSTALL=false` to disable that behavior, or install it
|
|
explicitly with `./jeannie oci-auth install`.
|
|
|
|
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.
|
|
|
|
The defaults use the Always Free `VM.Standard.E2.1.Micro` shape and the
|
|
Canonical Ubuntu 24.04 Minimal image in `us-ashburn-1` supplied for this lab.
|
|
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
|
|
`LAB_OCI_CREATE_COMPARTMENT=false` with `LAB_OCI_COMPARTMENT_ID` when the
|
|
tenancy policy does not allow creating child compartments.
|
|
|
|
To test a complete compartment/network foundation without consuming another
|
|
Always Free compute slot, set `LAB_OCI_COMPUTE_ENABLED=false`. Edge/email
|
|
subnets and security groups are still created; the VM resources are deferred
|
|
until the variable is set back to `true`.
|
|
|
|
If the tenancy has exhausted its NAT gateway quota, set
|
|
`LAB_OCI_NAT_ENABLED=false` for a public-only foundation test. The private
|
|
subnet remains available but does not receive a NAT route until this is
|
|
enabled later.
|
|
|
|
For a deliberate clean-slate infrastructure reset, use the guarded OCI
|
|
cleanup command from Debian. It never deletes the tenancy, root compartment,
|
|
IAM users, groups, policies, or API keys:
|
|
|
|
```text
|
|
./jeannie oci cleanup plan
|
|
./jeannie oci cleanup apply --confirm TENANCY-CLEANUP
|
|
```
|
|
|
|
The first command inventories infrastructure only. The second deletes
|
|
instances, volumes, networking, and empty child compartments. Re-run `plan`
|
|
after OCI termination completes; IAM remains available for the next Jeannie
|
|
foundation run.
|
|
|
|
For a test alongside an existing foundation, also set
|
|
`LAB_OCI_FOUNDATION_STATE_FILE` to a new local state path. This prevents the
|
|
test plan from treating the production foundation as resources to destroy.
|
|
|
|
After a successful apply, Jeannie persists the discovered edge IP and uses it
|
|
as the next-run edge target instead of the static inventory value. To update
|
|
DuckDNS automatically when OCI assigns a replacement public IP, provide the
|
|
token outside Git and list the DuckDNS subdomain labels to update:
|
|
|
|
```bash
|
|
export LAB_DUCKDNS_TOKEN='REDACTED_DUCKDNS_TOKEN'
|
|
export LAB_DUCKDNS_DOMAINS='lab2025,api,auth,grafana,office,docs'
|
|
```
|
|
|
|
The update is enabled by default when a token is present. Set
|
|
`LAB_OCI_AUTO_UPDATE_DUCKDNS=false` to disable it. The email VM baseline
|
|
(Postfix, Dovecot, fail2ban, UFW, and node-exporter) is also installed
|
|
automatically after the new VM accepts SSH; set
|
|
`LAB_OCI_AUTO_CONFIGURE_EMAIL=false` to defer that step.
|
|
|
|
The foundation also creates an OCI Bastion service by default. It is a
|
|
service-managed, time-limited SSH entry point and does not consume a compute
|
|
VM. Its client allow-list defaults to `LAB_OCI_ADMIN_CIDR`. For a new VCN,
|
|
Jeannie permits SSH from the Bastion target subnet to the managed edge and
|
|
email instances. When reusing an existing VCN, set
|
|
`LAB_OCI_BASTION_SSH_SOURCE_CIDR` if its NSGs do not already allow that
|
|
subnet. Set `LAB_OCI_BASTION_TARGET_SUBNET_ID` to use a private target subnet.
|
|
|
|
After `oci-foundation apply`, the Bastion and discovered edge instance OCIDs
|
|
are persisted in the local OCI config. Open a managed SSH session with:
|
|
|
|
```text
|
|
./jeannie oci bastion ssh
|
|
```
|
|
|
|
Explicit OCIDs and key paths can also be supplied:
|
|
|
|
```text
|
|
./jeannie oci bastion ssh BASTION_OCID INSTANCE_OCID ubuntu ~/.ssh/id_ed25519.pub ~/.ssh/id_ed25519
|
|
```
|
|
|
|
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.
|