aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile55
-rw-r--r--README.md44
-rw-r--r--configs/doas.conf2
-rw-r--r--openbsd.pkr.hcl5
-rwxr-xr-x[-rw-r--r--]scripts/harden-root.sh0
-rwxr-xr-xscripts/setup.sh25
6 files changed, 98 insertions, 33 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..1b5c630
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,55 @@
+SHELL := /bin/sh
+
+VARS_FILE := openbsd79-arm64-macos.pkvars.hcl
+BUILD_DIR := build
+DISK := $(BUILD_DIR)/openbsd-7.9-aarch64.qcow2
+EFIVARS_RUN := $(BUILD_DIR)/efivars-run.fd
+EDK2_DIR := /opt/homebrew/share/qemu
+EDK2_CODE := $(EDK2_DIR)/edk2-aarch64-code.fd
+EDK2_VARS := edk2-arm-vars.fd
+SSH_PORT := 2222
+SSH_USER := eugene
+CPU := 1
+MEMORY := 4096M
+PACKER_LOG := 1
+
+export PACKER_LOG
+
+.PHONY: all init build run ssh clean
+
+all: build
+
+init:
+ packer init .
+
+build: init
+ rm -rf $(BUILD_DIR)
+ cp $(EDK2_DIR)/$(EDK2_VARS) ./$(EDK2_VARS)
+ packer build -var-file=$(VARS_FILE) .
+
+# Run the headless VM (SSH via port-forwarded localhost:$(SSH_PORT))
+run:
+ cp ./$(EDK2_VARS) $(EFIVARS_RUN)
+ # If you want to run with a GUI, replace -nographic
+ # with `-display cocoa`.
+ qemu-system-aarch64 \
+ -machine type=virt,accel=hvf \
+ -cpu host \
+ -m $(MEMORY) \
+ -smp $(CPU) \
+ -nographic \
+ -device qemu-xhci,id=xhci \
+ -device usb-kbd,bus=xhci.0 \
+ -device virtio-gpu-pci \
+ -netdev user,id=net0,hostfwd=tcp::$(SSH_PORT)-:22 \
+ -device virtio-net,netdev=net0 \
+ -drive file=$(DISK),if=virtio,cache=writeback,discard=ignore,format=qcow2 \
+ -drive file=$(EDK2_CODE),if=pflash,unit=0,format=raw,readonly=on \
+ -drive file=$(EFIVARS_RUN),if=pflash,unit=1,format=raw
+
+ssh:
+ ssh -p $(SSH_PORT) $(SSH_USER)@127.0.0.1
+
+clean:
+ rm -rf $(BUILD_DIR)
+
diff --git a/README.md b/README.md
index c9e85ab..2a475a8 100644
--- a/README.md
+++ b/README.md
@@ -8,53 +8,33 @@ that is the only configuration that is actively tested.
## Installation
-You can also build the box yourself with the following:
+First, ensure you have QEMU installed:
```sh
brew install qemu
-cp /opt/homebrew/share/qemu/edk2-arm-vars.fd ./edk2-arm-vars.fd
-export PACKER_LOG=1
-packer init
-packer build -var-file=openbsd79-arm64-macos.pkvars.hcl
```
-## Usage
-
-Once your image is built, you can run it.
-
-First, the efivars are stateful. So, make a copy of the ones you used during the
-build to use for your particular run.
+Then, you can build the box with the following:
```sh
-cp build/efivars.fd build/efivars-run.fd
+make
```
-Then, run the following command:
+## Usage
+
+Once your image is built, you can run it:
```sh
-qemu-system-aarch64 \
- -machine type=virt,accel=hvf \
- -cpu host \
- -m 4096M \
- -smp 1 \
- -nographic \
- -device qemu-xhci,id=xhci \
- -device usb-kbd,bus=xhci.0 \
- -device virtio-gpu-pci \
- -netdev user,id=net0,hostfwd=tcp::2222-:22 \
- -device virtio-net,netdev=net0 \
- -drive file=build/openbsd-7.9-aarch64.qcow2,if=virtio,cache=writeback,discard=ignore,format=qcow2 \
- -drive file=/opt/homebrew/share/qemu/edk2-aarch64-code.fd,if=pflash,unit=0,format=raw,readonly=on \
- -drive file=build/efivars-run.fd,if=pflash,unit=1,format=raw
+make run
```
-If you want a display (rather than a headless VM over SSH), replace `-nographic`
-with `-display cocoa`.
-
-Once the system is up, you can SSH in using your admin user and private key:
+Once the system is up, you can SSH in using:
```sh
-> ssh -p 2222 eugene@127.0.0.1
+make ssh
+```
+
+```
The authenticity of host '[127.0.0.1]:2222 ([127.0.0.1]:2222)' can't be established.
ED25519 key fingerprint is: SHA256:GnVug9cxjtROdVCbDsaxG7Co/E1j060B9U+bmY2lqOk
This key is not known by any other names.
diff --git a/configs/doas.conf b/configs/doas.conf
index d2423e7..96cf24d 100644
--- a/configs/doas.conf
+++ b/configs/doas.conf
@@ -1 +1 @@
-permit nopass :wheel
+permit nopass keepenv :wheel
diff --git a/openbsd.pkr.hcl b/openbsd.pkr.hcl
index 9bf7dc0..80cae35 100644
--- a/openbsd.pkr.hcl
+++ b/openbsd.pkr.hcl
@@ -142,6 +142,11 @@ build {
}
provisioner "shell" {
+ script = "scripts/setup.sh"
+ environment_vars = ["ADMIN_USER=${var.admin_user}"]
+ }
+
+ provisioner "shell" {
script = "scripts/harden-root.sh"
}
}
diff --git a/scripts/harden-root.sh b/scripts/harden-root.sh
index c8e267a..c8e267a 100644..100755
--- a/scripts/harden-root.sh
+++ b/scripts/harden-root.sh
diff --git a/scripts/setup.sh b/scripts/setup.sh
new file mode 100755
index 0000000..e4dc169
--- /dev/null
+++ b/scripts/setup.sh
@@ -0,0 +1,25 @@
+#!/bin/sh
+set -e
+
+: "${ADMIN_USER:?ADMIN_USER must be set}"
+
+main() {
+ # Ensure the time in the VM is in sync. If it is not, things like upgrading
+ # the system packages via pkg_add -u fail.
+ rdate -n pool.ntp.org
+ pkg_add -u
+
+ fw_update
+ install_system_maintenance_cron_jobs
+ usermod -G _shutdown "$ADMIN_USER" # Allow the admin user to shutdown the system without root.
+}
+
+install_system_maintenance_cron_jobs() {
+ (
+ echo "MAILTO=$ADMIN_USER" # Send mail about root cron jobs to the admin user.
+ crontab -l 2>/dev/null # Print existing cron file; redirect stderr if empty cron file error.
+ echo "10 12 * * * /usr/sbin/syspatch -c" # Install any outstanding patches everyday at 12:10
+ ) | crontab -
+}
+
+main "$@"