Skip to content

Mac mini

The Mac mini is the host of the three VMs and your daily workstation. This chapter takes it from the box to a machine that never sleeps, encrypts its disk, holds no secret outside 1Password, and can start and unlock its VMs with one command. No service is installed on macOS itself: only UTM, 1Password and this repository.

Set the Mac up as a new computer. Do not use Migration Assistant, so nothing from the old machine comes along unseen. The only things carried over are the ~/infra-migration folder from chapter 2 and what 1Password syncs.

Why. The account that logs in is the one that runs UTM, so the VMs live inside its session. Its password is the first secret of the new machine.

Mac

  1. Plug the Mac into the switch port prepared in step 3.5, with Ethernet only. Skip Wi-Fi in the setup assistant.
  2. Choose Set up as new. Sign in with your Apple Account.
  3. Create the account with the short name macadmin. The LaunchAgent in step 4.11 uses that home folder path.
  4. On your phone, in 1Password, create a login item Mac login in the Infrastructure vault with a generated password you can type (four or five random words), and use it as the account password.
  5. Turn on Touch ID when offered, if your keyboard has it.

Verify. id -un in Terminal prints macadmin.

Rollback. Erase the Mac from System Settings > General > Transfer or Reset > Erase All Content and Settings and start over.

Why. R5. The VM disk images sit in your home folder. FileVault is what protects them, and everything else, if the Mac is stolen. Automatic login cannot coexist with FileVault and would defeat it anyway.

Mac

Terminal window
sudo fdesetup status

If it says FileVault is off: System Settings > Privacy & Security > FileVault > Turn On. Choose Create a recovery key and do not use my iCloud account. Type the key into a new 1Password item FileVault recovery key (vault Infrastructure, category password), then check it character by character.

In System Settings > Users & Groups, confirm Automatically log in as is Off.

Verify. sudo fdesetup status prints FileVault is On. and sudo fdesetup validaterecovery accepts the key copied from 1Password and prints true.

Rollback. sudo fdesetup disable. Not recommended: R5 depends on it.

4.3 A fixed address on the Trusted network

Section titled “4.3 A fixed address on the Trusted network”

Why. Firewall policies name the Mac by address (10.0.5.3), and the address is set on the Mac itself so it never waits on the router at boot.

Mac System Settings > Network > Ethernet > Details > TCP/IP: Configure IPv4: Manually, address 10.0.5.3, subnet mask 255.255.255.0, router 10.0.5.1. Under DNS, add 10.0.5.1 for now. Step 6.11 changes it to the new resolver.

Or from Terminal:

Terminal window
networksetup -setmanual Ethernet 10.0.5.3 255.255.255.0 10.0.5.1
networksetup -setdnsservers Ethernet 10.0.5.1
networksetup -setairportpower Wi-Fi off

Wi-Fi stays off: a Mac on both Wi-Fi and Ethernet sits on two VLANs at once and confuses discovery.

UniFi Client Devices > the Mac mini > Settings: Fixed IP Address 10.0.5.3, and give it the name mac-mini, so the controller never hands that address to another device.

Verify.

Terminal window
ipconfig getifaddr en0 # 10.0.5.3
route -n get default | grep gateway # 10.0.5.1
networksetup -getairportpower Wi-Fi # Off

If the Ethernet port is not en0, networksetup -listallhardwareports shows its name. Use that name wherever this guide writes en0, including the UTM bridge in chapter 5.

Rollback. networksetup -setdhcp Ethernet.

4.4 Never sleep, come back after a power cut

Section titled “4.4 Never sleep, come back after a power cut”

Why. A sleeping host freezes the VMs, and with them DNS and Home Assistant for the house.

Mac

Terminal window
sudo pmset -a sleep 0 disksleep 0 displaysleep 10 womp 1 autorestart 1 powernap 0

Verify. pmset -g | grep -E ' sleep|autorestart|womp' shows sleep 0, autorestart 1 and womp 1.

Rollback. sudo pmset -a restoredefaults.

After a power cut the Mac starts by itself and stops at the FileVault login. Nothing runs until you log in. That is the cost of R5, and the reason for the UPS in chapter 2 and the second DNS server in step 6.11.

Why. A macOS update restarts the Mac, and a restart stops the VMs until you log in and unlock them. You pick the moment.

Mac System Settings > General > Software Update > Automatic Updates: turn Install macOS updates off. Leave Install Security Responses and system files on, and Download new updates when available on.

Verify. defaults read /Library/Preferences/com.apple.SoftwareUpdate AutomaticallyInstallMacOSUpdates prints 0.

Rollback. Turn the option back on.

Why. The Mac runs no service, so it should accept nothing it did not ask for. UTM’s bridge is not affected: the VMs’ traffic does not pass through the macOS firewall.

Mac

Terminal window
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate on
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setstealthmode on

Leave Remote Login and Screen Sharing off in System Settings > General > Sharing unless you administer this Mac from another one. If you turn them on, reach them through the admin VPN of step 10.11 only.

Verify. sudo /usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate prints enabled.

Rollback. --setglobalstate off.

4.7 Homebrew, 1Password and its command line tool

Section titled “4.7 Homebrew, 1Password and its command line tool”

Why. Same as step 2.1, on the new machine. Every later command that needs a secret reads it with op.

Mac

Terminal window
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
eval "$(/opt/homebrew/bin/brew shellenv)" && echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
brew install --cask 1password 1password-cli utm
brew install git jq

Open 1Password and sign in. Settings > Security: Touch ID on. Settings > Developer: Integrate with 1Password CLI on, Use the SSH agent on. In the SSH agent’s settings, allow the Infrastructure vault: Settings > Developer > SSH Agent > Edit Automatically opens ~/.config/1Password/ssh/agent.toml. Make it read:

[[ssh-keys]]
vault = "Infrastructure"

Verify. op whoami prints your account after a Touch ID prompt, and op read "op://Infrastructure/LUKS infra/password" | wc -c prints 41.

Rollback. brew uninstall --cask utm 1password-cli 1password.

Why. The private key made in step 2.4 never leaves 1Password. This file tells SSH to ask the agent, and gives each VM a short name.

Mac

Terminal window
mkdir -p ~/.ssh && chmod 700 ~/.ssh
cat > ~/.ssh/config <<'EOF'
Host *
IdentityAgent "~/Library/Group Containers/2BUA8C4S2C.com.1password/t/agent.sock"
Host home
HostName 10.0.5.2
User admin
Host infra
HostName 10.0.2.5
User admin
Host standby
HostName 10.0.6.2
User admin
EOF
chmod 600 ~/.ssh/config
op read "op://Infrastructure/SSH mac-admin/public key" > ~/.ssh/mac-admin.pub

Verify. SSH_AUTH_SOCK=~/Library/Group\ Containers/2BUA8C4S2C.com.1password/t/agent.sock ssh-add -l lists one ED25519 key after a Touch ID prompt.

Rollback. Delete ~/.ssh/config.

4.9 The repository and the migration folder

Section titled “4.9 The repository and the migration folder”

Why. The repository holds every file this guide installs. It lives on the Mac only: the VMs receive their files by rsync and never hold a GitHub credential.

Mac

  1. Add the public key to GitHub: pbcopy < ~/.ssh/mac-admin.pub, then on github.com Settings > SSH and GPG keys > New SSH key, paste.
  2. Clone, and set the two variables every chapter uses:
Terminal window
mkdir -p ~/PycharmProjects && cd ~/PycharmProjects
git clone git@github.com:OWNER/infrastructure.git
cat >> ~/.zshrc <<'EOF'
export INFRA=~/PycharmProjects/infrastructure
export U=/Applications/UTM.app/Contents/MacOS/utmctl
export PATH="$INFRA/mac/bin:$INFRA/scripts:$PATH"
EOF
source ~/.zshrc
  1. Copy infra-migration from the external disk of step 2.14 to ~/infra-migration.

Verify. ls $INFRA/vm lists common home infra standby, which vm-up prints a path inside the repository, and ls ~/infra-migration/backups lists the files from chapter 2 (restore path only).

Rollback. Delete the folder and the three lines in ~/.zshrc.

Why. macOS asks before an application may reach the local network or control another application. Answering the prompts now, with you at the screen, avoids a VM that silently has no network after the first restart.

Mac

  1. Open UTM once. Accept the prompts.
  2. System Settings > Privacy & Security > Local Network: UTM must be on. The entry appears after the first VM starts with a bridged network (chapter 5). Come back to check it then.
  3. Run $U list. macOS asks whether Terminal may control UTM: Allow.

Verify. $U list prints a header line (and no VM yet) with no error.

Rollback. brew uninstall --cask utm.

Why. UTM has no start-at-login setting for a VM. A LaunchAgent runs vm-up when you log in. It starts infra first, because the others ask it for DNS, then home, then standby, all without a window.

Mac

Terminal window
cp $INFRA/mac/launchd/com.example.vm-up.plist ~/Library/LaunchAgents/
launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.example.vm-up.plist

The first run asks whether bash may control UTM: Allow. The agent skips any VM that does not exist yet, so it is safe to install now.

Verify. launchctl print gui/$(id -u)/com.example.vm-up | grep -E 'state|last exit' shows last exit code = 0, and cat ~/Library/Logs/vm-up.log exists.

Rollback.

Terminal window
launchctl bootout gui/$(id -u)/com.example.vm-up
rm ~/Library/LaunchAgents/com.example.vm-up.plist

Why. J14: each VM’s disk is encrypted with a passphrase that only 1Password holds. After every start of a VM somebody types it. vm-unlock does the typing, into the VM’s serial console, after one Touch ID. This step explains the three commands. You run them for real from chapter 5 on.

Command What it does When
vm-up Starts infra, home, standby in that order, hidden Runs by itself at login
vm-unlock all Reads each passphrase from 1Password and types it at the disk prompt After every login that follows a restart
vm-down Asks each VM to shut down and waits until all are stopped Before a restart, a macOS update, or quitting UTM

A plain utmctl stop, quitting UTM or restarting the Mac cuts a VM’s power in the middle of a write. Always use vm-down first.

Unlocking by hand, if vm-unlock reports no prompt or you want to watch the boot:

Terminal window
vm-tty infra # prints the console device, for example /dev/ttys004
screen "$(vm-tty infra)" # press Return: "Please unlock disk vda3_crypt:"

In a second Terminal tab, op read "op://Infrastructure/LUKS infra/password" | pbcopy, then paste into screen and press Return. Leave screen with Ctrl-A, K, Y. If vm-tty prints nothing, read the path in UTM: select the VM, and look at Serial (TTY) in its details.

vm-unlock and vm-tty are new and were not run on hardware before this guide was written. The manual way above is proven. Step 5.13 tests the script on the first VM.

Verify. vm-unlock with no argument prints its usage line.

Rollback. None needed.

The Mac has an encrypted disk, a fixed address on the Trusted network, no service of its own, and the tools to run VMs: UTM, the repository, 1Password with its SSH agent, and a login agent that will start the VMs. Next comes the base build that every VM shares.