Keystone

Self-sovereign infrastructure platform with secure, encrypted NixOS deployments


Project maintained by ncrmro Hosted on GitHub Pages — Theme by mattgraham

Keystone Testing Procedure

Version: 1.0 Date: 2025-11-03

Overview

Keystone uses a VM-based testing workflow for validating deployments and testing features. This document describes the automated testing scripts and common workflows.


Testing Scripts

bin/test-deployment

Purpose: Full VM deployment testing (fresh install)

What it does:

  1. Stops/resets existing test VM
  2. Optionally rebuilds ISO with SSH keys
  3. Creates/starts VM from ISO (TPM emulation enabled)
  4. Waits for VM boot and SSH access
  5. Deploys via nixos-anywhere to .#test-server
  6. Unlocks disk via initrd SSH (password: “keystone”)
  7. Runs Secure Boot provisioning
  8. Verifies deployment (SSH, ZFS, Secure Boot)

Usage:

./bin/test-deployment                    # Normal test run
./bin/test-deployment --rebuild-iso      # Rebuild ISO first
./bin/test-deployment --hard-reset       # Force VM cleanup
./bin/test-deployment --debug            # Show full output

Time: 10-15 minutes (full redeploy)

Use when: Testing fresh installations, major changes, Secure Boot changes


bin/update-test-vm

Purpose: Incremental configuration updates (fast iteration)

What it does:

  1. Verifies VM is running and accessible
  2. Builds configuration locally (or on VM with --build-host)
  3. Copies closure to VM via nixos-rebuild
  4. Activates new configuration
  5. Optionally reboots VM

Usage:

./bin/update-test-vm                    # Quick update (no reboot)
./bin/update-test-vm --reboot           # Update and reboot
./bin/update-test-vm --build-host       # Build on VM (slow network)

Time: 1-3 minutes

Use when: Iterating on module changes, testing configuration updates

Preserves: All VM state (enrolled keys, data, TPM enrollment)


bin/virtual-machine

Purpose: VM lifecycle management

What it does:

Usage:

./bin/virtual-machine --name test-vm --start          # Create and start
./bin/virtual-machine --post-install-reboot test-vm   # Post-install cleanup
./bin/virtual-machine --reset test-vm                 # Complete removal
./bin/virtual-machine --reset-setup-mode test-vm      # Reset Secure Boot

Network: VMs connect to keystone-net with static IP 192.168.100.99


bin/build-iso

Purpose: Build Keystone installer ISO with optional SSH keys

What it does:

Usage:

./bin/build-iso                                      # No SSH keys
./bin/build-iso --ssh-key ~/.ssh/id_ed25519.pub     # With SSH key
./bin/build-iso --ssh-key "ssh-ed25519 AAA..."      # Direct key string

Common Testing Workflows

Workflow 1: Fresh Deployment Testing

# Deploy fresh system
./bin/test-deployment

# SSH in
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@192.168.100.99

# Test feature (e.g., TPM enrollment)
sudo keystone-enroll-recovery --auto

# Verify
sudo reboot
# System should unlock automatically via TPM

Workflow 2: Iterative Development

# Make changes to module
vim modules/tpm-enrollment/default.nix

# Quick update to VM (preserves state)
./bin/update-test-vm

# SSH and test
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@192.168.100.99
sudo keystone-enroll-recovery --auto

# Repeat as needed

Workflow 3: Testing Boot Changes

# Make boot-related changes
vim modules/disko-single-disk-root/default.nix

# Update and reboot
./bin/update-test-vm --reboot

# Verify boot behavior
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@192.168.100.99

Workflow 4: Complete Reset and Redeploy

# Clean slate
./bin/test-deployment --hard-reset --rebuild-iso

# Fresh deployment with latest changes

VM Configuration

Test Server Details

Enabled Modules


SSH Access

Standard SSH (ignores host key changes)

ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@192.168.100.99

Why These Options?

Test VMs are recreated frequently, causing:

These options:


Testing Checklist

Before Committing Changes

After Major Changes


Troubleshooting

VM Won’t Start

# Check VM status
virsh list --all | grep keystone-test-vm

# Check libvirt network
virsh net-list | grep keystone-net

# View serial console
virsh console keystone-test-vm

# Check logs
virsh dumpxml keystone-test-vm

SSH Connection Failed

# Check VM IP
virsh domifaddr keystone-test-vm

# Verify network
virsh net-dhcp-leases keystone-net

# Try serial console instead
virsh console keystone-test-vm

Deployment Hangs

# Check if waiting for disk unlock
virsh console keystone-test-vm
# Look for password prompt

# Manually unlock via serial console
# Enter: keystone

Update Failed

# Rollback on VM
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@192.168.100.99
sudo nixos-rebuild switch --rollback

# Or reset and redeploy
./bin/virtual-machine --reset keystone-test-vm
./bin/test-deployment

Script Maintenance

IMPORTANT: When modifying testing scripts, update this document to reflect:

Testing scripts to keep in sync:



Document Version: 1.0 Last Updated: 2025-11-03 Maintainer: Keystone Project