running_webservices_openbsd_vmm
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
running_webservices_openbsd_vmm [2025/02/24 11:17] – unfinished ethan | running_webservices_openbsd_vmm [2025/04/20 11:38] (current) – ethan | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | **notice**: I have been having issues with vmm/Alpine Linux, where, after a VM shutdown, Alpine Linux will become somehow be corrupted and I must boot into the installation iso to repair the system. if this happens to you, all I had to do was update Alpine. | ||
+ | |||
======running webservices from OpenBSD' | ======running webservices from OpenBSD' | ||
although it is most likely best to run most things directly on an OpenBSD host, compatibility issues and other pains may arise depending on the service. | although it is most likely best to run most things directly on an OpenBSD host, compatibility issues and other pains may arise depending on the service. | ||
- | this is a guide on how to host web content from a virtual machine running inside [[OpenBSD]]' | + | this is a guide on how to host web content from a virtual machine running inside [[https:// |
- | =====vmd | + | |
+ | in the setup this guide shows, relayd will handle http and https requests to the OpenBSD machine and separate them based on domain (yonderly.org, | ||
+ | =====vmd===== | ||
vmd is the daemon that interacts with vmm to make virtual machine creation and management easy. its config file is at /// | vmd is the daemon that interacts with vmm to make virtual machine creation and management easy. its config file is at /// | ||
Line 70: | Line 74: | ||
vm alpine0 { | vm alpine0 { | ||
owner :vm # allow group vm to control this virtual machine. | owner :vm # allow group vm to control this virtual machine. | ||
- | + | ||
- | boot device cdrom # change to disk after installation. | + | boot device cdrom |
+ | |||
cdrom / | cdrom / | ||
disk / | disk / | ||
+ | |||
memory | memory | ||
+ | |||
local interface | local interface | ||
} | } | ||
Line 96: | Line 100: | ||
</ | </ | ||
if you see nothing, wait, and then press Enter. the login prompt should be visible. | if you see nothing, wait, and then press Enter. the login prompt should be visible. | ||
+ | ====Alpine installation==== | ||
+ | see [[https:// | ||
+ | * the hostname doesn' | ||
+ | * initialize interface " | ||
+ | * you can either use dhcp or figure out a valid IP by looking at the tun device being used by the VM. | ||
+ | * you should still enter secure root and user passwords, as a vulnerability in your web stack could still be present (we will only forward port 80; no other ports will be accessible publicly). | ||
+ | * probably choose openssh as the ssh server. I have little experience with dropbear. you should at a minimum enable an sshd server as it will make interacting with the VM much more convenient, no longer needing to use slow [[https:// | ||
+ | * you can do a crypt install, but it will mean you'll need too cu into the VM and enter the disk password each time it starts up. | ||
+ | |||
+ | ===improving console=== | ||
+ | |||
+ | this is optional, but it is very beneficial in debugging a VM which isn't booting. by default, Alpine Linux' | ||
+ | |||
+ | the installer will have unmounted the installation, | ||
+ | < | ||
+ | # mount /dev/vda3 /mnt | ||
+ | # mount /dev/vda1 /mnt/boot | ||
+ | # mount /proc /mnt/proc | ||
+ | # mount /dev /mnt/dev | ||
+ | </ | ||
+ | chroot into the install. | ||
+ | < | ||
+ | # chroot /mnt | ||
+ | </ | ||
+ | now, edit / | ||
+ | <file bash / | ||
+ | ... | ||
+ | # default_kernel_opts | ||
+ | # default kernel options | ||
+ | default_kernel_opts=" | ||
+ | ... | ||
+ | </ | ||
+ | now, run update-extlinux. | ||
+ | < | ||
+ | # update-extlinux | ||
+ | </ | ||
+ | if it mentions the configuration was unchanged, you did not edit its config properly. | ||
+ | |||
+ | exit the chroot and unmount the installation. | ||
+ | < | ||
+ | # exit | ||
+ | (no longer in chroot) | ||
+ | # cd / | ||
+ | # umount /mnt/dev | ||
+ | # umount /mnt/proc | ||
+ | # umount /mnt/boot | ||
+ | # umount /mnt | ||
+ | </ | ||
+ | after running the commands, press Enter, then ~, then Ctrl+D to exit cu. | ||
+ | |||
+ | power off the virtual machine. | ||
+ | < | ||
+ | # vmctl stop alpine0 | ||
+ | </ | ||
+ | |||
+ | change the VM's configuration so it boots from disk. | ||
+ | <file bash / | ||
+ | vm alpine0 { | ||
+ | ... | ||
+ | boot device disk | ||
+ | ... | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | have vmd reload the configuration. | ||
+ | < | ||
+ | # vmctl reload | ||
+ | </ | ||
+ | ====setting up Alpine==== | ||
+ | start the virtual machine, and, using the -c flag, immediately connect to it. | ||
+ | < | ||
+ | # vmctl start -c alpine0 | ||
+ | </ | ||
+ | look through the output and make sure everything looks correct, then exit cu using the keys earlier. | ||
+ | |||
+ | if you enabled sshd, you can now login to the VM. it should have told you the IP earlier. if it is your first VM, the IP should be 100.64.1.3. your second would be 100.64.2.3, and so on. 100.64.1.3 will be used in this guide. | ||
+ | < | ||
+ | $ ssh 100.64.1.2 | ||
+ | </ | ||
+ | > you cannot login as root. | ||
+ | ===simple nginx setup=== | ||
+ | become root and install nginx (from [[https:// | ||
+ | < | ||
+ | # apk add nginx | ||
+ | # mkdir /www | ||
+ | # chown -R www:www / | ||
+ | # chown -R www:www /www | ||
+ | </ | ||
+ | |||
+ | edit the default server. | ||
+ | <file bash / | ||
+ | server { | ||
+ | listen 80 default_server; | ||
+ | listen [::]:80 default_server; | ||
+ | |||
+ | location / { | ||
+ | index index.html; | ||
+ | root /www; | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | create / | ||
+ | <file html / | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | start nginx. | ||
+ | < | ||
+ | # rc-service nginx start | ||
+ | </ | ||
+ | |||
+ | it should be possible to fetch the html page. | ||
+ | < | ||
+ | # wget localhost | ||
+ | Connecting to localhost ([::1]:80) | ||
+ | saving to ' | ||
+ | # cat index.html | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | on the host, make sure you can access the VM's http server. | ||
+ | < | ||
+ | # ftp http:// | ||
+ | Requesting http:// | ||
+ | </ | ||
+ | =====relayd===== | ||
+ | now that an http server is running inside the virtual machine, we can make it publicly accessible through relayd. | ||
+ | |||
+ | this section will use 10.0.0.4 as the IP of the server running OpenBSD, and alpine0.yonderly.org as the domain meant for the VM. | ||
+ | <file bash / | ||
+ | ext_ip=" | ||
+ | |||
+ | table < | ||
+ | table < | ||
+ | |||
+ | http protocol wwwtls { | ||
+ | tls keypair " | ||
+ | #tls keypair " | ||
+ | | ||
+ | match request header append " | ||
+ | match request header append " | ||
+ | value " | ||
+ | match request header set " | ||
+ | | ||
+ | block | ||
+ | | ||
+ | pass request header " | ||
+ | forward to < | ||
+ | ... | ||
+ | pass request header " | ||
+ | forward to < | ||
+ | } | ||
+ | |||
+ | http protocol www { | ||
+ | match request header append " | ||
+ | match request header append " | ||
+ | value " | ||
+ | match request header set " | ||
+ | | ||
+ | block | ||
+ | | ||
+ | pass request header " | ||
+ | forward to < | ||
+ | ... | ||
+ | pass request header " | ||
+ | forward to < | ||
+ | } | ||
+ | |||
+ | relay www { | ||
+ | listen on $ext_ip port http | ||
+ | protocol www | ||
+ | |||
+ | forward to < | ||
+ | } | ||
+ | |||
+ | relay wwwtls { | ||
+ | listen on $ext_ip port https tls | ||
+ | protocol wwwtls | ||
+ | |||
+ | forward to < | ||
+ | forward to < | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | make sure that the config is sane and start or restart it. | ||
+ | < | ||
+ | # relayd -n | ||
+ | # rcctl restart relayd | ||
+ | </ | ||
+ | |||
+ | =====httpd===== | ||
+ | httpd will serve the acme-challenge directory for TLS certificate generation and redirect http to https. | ||
+ | <file bash / | ||
+ | ... | ||
+ | server " | ||
+ | listen on * port 80 | ||
+ | |||
+ | location "/ | ||
+ | root "/ | ||
+ | request strip 2 | ||
+ | } | ||
+ | |||
+ | location * { | ||
+ | block return 301 " | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | make sure that the config is sane and start or restart it. | ||
+ | < | ||
+ | # httpd -n | ||
+ | # rcctl restart httpd | ||
+ | </ | ||
+ | |||
+ | =====acme-client===== | ||
+ | <file bash / | ||
+ | ... | ||
+ | domain alpine0.yonderly.org { | ||
+ | domain key "/ | ||
+ | domain full chain certificate "/ | ||
+ | sign with letsencrypt | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | generate the certificate. | ||
+ | < | ||
+ | # acme-client -v alpine0.yonderly.org | ||
+ | </ | ||
+ | =====finalizing===== | ||
+ | now that the certificates exist, the " | ||
+ | <file bash / | ||
+ | ... | ||
+ | tls keypair " | ||
+ | ... | ||
+ | </ | ||
+ | < | ||
+ | # rcctl restart relayd | ||
+ | </ | ||
+ | the virtual machine' | ||
+ | {{tag> |
running_webservices_openbsd_vmm.1740395831.txt.gz · Last modified: 2025/02/24 11:17 by ethan