跳到正文
DEV Community· Farhan Hamid Lubis·· 1 小時前AI 評分56

從想取消 iCloud 訂閲到打造零信任家庭伺服器:一個簡單目標如何演變

I Only Wanted to Cancel iCloud: How One Simple Goal Turned Into a Zero-Trust Home Server

AI 導讀

作者為降低家庭照片、影片及密碼對雲端服務的依賴,在一部配備 8 GB RAM 和 1 TB SSD 的二手迷你電腦上,以 Proxmox VE 建立自行託管的家庭伺服器,運行 Immich 和 Vaultwarden。

正文

This project did not start with a grand architecture plan. It started with a pretty simple goal: I wanted to stop paying monthly fees for cloud storage for my family's photos and videos.

I also wasn't particularly comfortable keeping family photos, personal videos, and passwords entirely in third-party services. I wanted to have more control over where that data was stored, how it was accessed, and what happened to it.

So I bought a used mini PC with a 7th-gen 4-core CPU, integrated graphics, 8 GB of RAM, and a 1 TB SSD. I installed Proxmox VE and started setting up two services: Immich for family photos and Vaultwarden for passwords.

The initial setup was pretty straightforward. But as I started using the server regularly, I found myself thinking about things I hadn't considered when I first built it. How would I recover everything if the SSD failed? Would I remember why I configured certain things six months from now? And how much access should an AI coding agent have if I wanted it to help maintain the server?

Those questions gradually shaped the homelab into what it is today.


Five-step escalation diagram from canceling iCloud with Immich and Vaultwarden to Terraform and Ansible, a RAG-ready knowledge base, AI agent skills, and a zero-trust kernel firewall with Infisical on an 8 GB mini PC

How the Homelab Evolved

1. Starting with Immich and Vaultwarden

The first two services were Immich and Vaultwarden.

Immich handles photo and video backups from our phones, while Vaultwarden keeps our passwords in a self-hosted vault. Both solved the problems I originally had, and running them locally meant I no longer had to depend entirely on cloud subscriptions for these services.

At this point, the setup was mostly manual. I configured everything directly on the server, and as long as it worked, I didn't think much about documenting the process.

That changed when I started thinking about what would happen if I had to rebuild the entire server.

2. Making the Infrastructure Reproducible

I didn't want to spend another weekend manually rebuilding containers, configuring permissions, setting up networking, and trying to remember all the little things I had done previously.

I moved the infrastructure configuration to Terraform and Ansible. Terraform handles provisioning the Proxmox containers, while Ansible takes care of their configuration and service setup.

I also added automated encrypted daily backups. The goal was to make recovery less dependent on memory and manual steps, whether I was replacing a failed SSD or rebuilding the server from scratch.

3. Documenting the Decisions Behind the Configuration

Having infrastructure code is helpful, but it doesn't explain every decision behind it.

Looking at a configuration several months later, I might understand what it does but not remember why I chose that particular approach. Why is Terraform limited to a single parallel job? Why is GPU device configuration handled by Ansible? Why does a particular service have a specific restriction?

To address that, I created a structured Knowledge Base (kb/) alongside the infrastructure code.

It contains short decision records, service documentation, and recovery runbooks. I keep the documents relatively concise and structured, so they're easy to search, maintain, and use as context for AI tools later.

4. Using an AI Agent to Navigate the Homelab

Once the infrastructure code and documentation were organized in the same Git repository, I started experimenting with AI coding agents to help maintain the server.

Instead of manually searching through Terraform files, Ansible playbooks, and documentation every time I needed to troubleshoot something, I wanted to be able to ask questions directly.

For example:

  • Why is Immich's video transcoding behaving differently than expected?
  • What needs to be changed to add a new service?
  • Which containers are allowed to access a particular resource?
  • How do I recover a service after a failed update?

With the infrastructure code and Knowledge Base available as context, the agent could provide answers based on my actual configuration rather than generic instructions from the internet.

But giving an AI agent access to infrastructure code is something I wanted to be careful about.

5. Restricting What the AI Agent Can Actually Do

An AI agent can be useful, but I didn't want it to have unrestricted access to the machine managing my infrastructure.

Even with a well-written prompt, an agent can misunderstand instructions, generate incorrect commands, or be manipulated by malicious content in files it reads. I didn't want a mistake to turn into an infrastructure outage or expose private data on my network.

So I separated the AI agent from the human-operated infrastructure management workflow and put several restrictions in place:

  • No sudo: The agent runs without root privileges.
  • Network isolation: An OS-level firewall blocks access to my home LAN.
  • Limited commands: The agent can only use three predefined read-only wrapper commands.
  • Secrets separation: Secrets are stored in Infisical, outside the agent's accessible environment, and loaded into RAM by the human operator when needed.
  • Hypervisor protection: Critical containers and data are protected against accidental destructive operations.

The idea isn't to make the agent perfectly safe. It's to limit what it can do if it makes a mistake or behaves in an unexpected way.


The Resulting Layout

All of this still runs on the same 8 GB mini PC.

I organized the containers into security zones based on their data sensitivity and potential impact, rather than assigning IDs arbitrarily. I also use the same IP-to-Proxmox-ID convention for both VMs and containers:

Proxmox ID = 100 + last IP octet

The management environment runs in a separate disposable control VM with NAT, keeping the AI agent and human-operated tools away from the Proxmox host itself.

Disposable Control VM (NAT)
├── homelab-agent (AI)
│   ├── No sudo
│   ├── LAN blocked by kernel firewall
│   └── 3 read-only wrapper commands
│
└── homelab-ops (Human)
    ├── Fetches secrets into RAM (/dev/shm)
    └── Runs mutating infrastructure applies
             │
             ▼
Proxmox VE (8 GB RAM · 1 TB SSD)
│
├── Zone 1 (.10)
│   └── CT 110 Infisical
│       Immutable · protection=1
│
├── Zone 2 (.20 to .21) — Protected Data
│   ├── CT 120 Vaultwarden
│   │   Protected · protection=1 · no destroy
│   │
│   └── CT 121 Immich
│       500 GB thin disk · /dev/dri GPU passthrough
│
├── Zone 3 (.30 to .32) — Network & Security
│   ├── CT 130 Pi-hole
│   │   Wildcard *.haytham.internal DNS
│   │
│   ├── CT 131 Nginx Proxy Manager
│   │   Local HTTPS termination
│   │
│   └── CT 132 Tailscale
│       WireGuard subnet router
│
└── Zone 4 (.40 to .41) — Management
    ├── CT 140 Homepage
    │   Root dashboard
    │
    └── CT 141 Uptime Kuma
        Service monitoring

The IP-to-ID convention makes it easy to identify services without looking them up elsewhere.

If I see 192.168.100.21 in a log, I immediately know it's CT 121, which runs Immich. I also know it's part of Zone 2, the protected data zone, and that its configuration is maintained in zone2_protected.yml.

It's a small convention, but it makes the infrastructure much easier to navigate.


Four Decisions That Helped Keep Everything Within 8 GB

1. Using Unprivileged LXCs Instead of KVM VMs

For a single-node server with only 8 GB of RAM, I wanted to avoid running a separate guest OS for every service.

Most of my services run inside unprivileged Ubuntu 24.04 LXCs. They share the host kernel, which keeps the overhead relatively low compared to running a full VM for each service.

Immich is the exception in terms of resource allocation. It has a 4 GB memory limit and 2 GB of swap available for upload and machine-learning workloads, but typically uses around 1.3 to 1.8 GB when idle.

The entire active stack, including the Proxmox host and all eight containers, usually sits around 3.5 to 4.2 GB of RAM at steady state.

Passing the integrated GPU through /dev/dri to an LXC is also much simpler than configuring PCIe GPU passthrough to a VM, and it works well for my use case.

2. Keeping One Service per LXC

I considered putting Pi-hole, Nginx Proxy Manager, Homepage, and Uptime Kuma inside a single shared container to reduce memory usage.

It would have saved roughly 250 to 350 MB, but it would also make the services more tightly coupled. Updates, troubleshooting, snapshots, and access control would become harder to manage independently.

I'd rather have a little more overhead and keep each service isolated. With the IP-to-ID convention, I also get a predictable mapping that makes managing the containers easier.

3. Keeping Future Services Ready Without Running Them Yet

There are a few services I'd like to run in the future, including Home Assistant OS, a shared PostgreSQL instance, Redis, and pgAdmin.

Instead of removing their configurations or provisioning them prematurely, I keep their definitions in terraform/locals.tf and toggle them using enabled = false.

That way, when the hardware gets an upgrade to 16 GB of RAM, I can bring them online without having to redesign the infrastructure.

4. Organizing the Dashboard Around How I Use It

My first Homepage dashboard was organized according to the security zones. That made sense from an infrastructure perspective, but it wasn't particularly useful for daily navigation.

For example, Immich and Uptime Kuma ended up in the same section even though they serve completely different purposes.

I reorganized the dashboard around what I actually use each service for:

  • Apps & Media: Immich, Vaultwarden
  • Infrastructure & Security: Proxmox VE, Infisical, Pi-hole, Nginx Proxy Manager
  • Monitoring & Admin Tools: Uptime Kuma

The security zones still exist underneath, but the dashboard is now organized for day-to-day use.


All 8 Active Services at a Glance

Zone CTID IP Service Role
Zone 1 110 .10 Infisical Out-of-band secrets vault
Zone 2 120 .20 Vaultwarden Self-hosted password manager
Zone 2 121 .21 Immich Family photos & videos
Zone 3 130 .30 Pi-hole Local DNS & ad blocking
Zone 3 131 .31 Nginx Proxy Manager Local HTTPS reverse proxy
Zone 3 132 .32 Tailscale Private subnet routing
Zone 4 140 .40 Homepage Service dashboard
Zone 4 141 .41 Uptime Kuma Service monitoring

What's Coming in Part 2

In Part 2, I'll go deeper into how Terraform and Ansible work together on a single-node Proxmox setup, some Proxmox API quirks I ran into, and how I structured the Knowledge Base and Agent Skills to make the infrastructure easier to maintain and understand.

Repository: zero-trust-homelab on GitHub

來源:DEV Community · dev.to