|
| 1 | +# Secure Registry Setup for TMT Tests |
| 2 | + |
| 3 | +This document explains how the TMT test registry uses TLS with self-signed certificates for secure communication. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The TMT test infrastructure uses a registry VM to test image push/pull operations. The registry is now configured with TLS using self-signed certificates to ensure secure communication between the registry and test VMs. |
| 8 | + |
| 9 | +## Certificate Architecture |
| 10 | + |
| 11 | +### Components |
| 12 | + |
| 13 | +1. **CA Certificate** (`ca.pem`): A self-signed Certificate Authority used to sign the registry certificate |
| 14 | +2. **Registry Certificate** (`registry-cert.pem`): Server certificate for the registry, signed by the CA |
| 15 | +3. **Registry Private Key** (`registry-key.pem`): Private key for the registry certificate |
| 16 | + |
| 17 | +### Certificate Locations |
| 18 | + |
| 19 | +- **Build-time**: Certificates are generated in `hack/.registry-certs/` at project root (git-ignored) |
| 20 | +- **Registry VM**: Certificates are stored in `/etc/registry/certs/` and served by the registry container |
| 21 | +- **Test VMs**: The CA certificate is installed to `/usr/share/pki/ca-trust-source/anchors/bootc-registry-ca.crt` |
| 22 | + |
| 23 | +## Building Images with TLS Support |
| 24 | + |
| 25 | +### Step 1: Generate Certificates |
| 26 | + |
| 27 | +Before building either the registry image or test images, generate the certificates: |
| 28 | + |
| 29 | +```bash |
| 30 | +./hack/setup-registry-certs.sh |
| 31 | +``` |
| 32 | + |
| 33 | +This script: |
| 34 | +- Creates `hack/.registry-certs/` directory at project root |
| 35 | +- Generates a self-signed CA certificate |
| 36 | +- Generates a registry server certificate signed by the CA |
| 37 | +- Certificates are valid for 10 years |
| 38 | +- Uses hostname `bootc-registry.test` for TLS validation (instead of hardcoded IPs) |
| 39 | +- Test VMs automatically configure `/etc/hosts` to resolve this hostname to the registry's actual IP |
| 40 | + |
| 41 | +The script is idempotent - if certificates already exist, it will skip generation. To regenerate: |
| 42 | + |
| 43 | +```bash |
| 44 | +rm -rf hack/.registry-certs |
| 45 | +./hack/setup-registry-certs.sh |
| 46 | +``` |
| 47 | + |
| 48 | +### Step 2: Build the Registry Image |
| 49 | + |
| 50 | +Build the registry image with: |
| 51 | + |
| 52 | +```bash |
| 53 | +podman build -f hack/Containerfile.registry -t bootc-registry . |
| 54 | +``` |
| 55 | + |
| 56 | +This will: |
| 57 | +- Copy the pre-generated certificates from `hack/.registry-certs/` |
| 58 | +- Install them in `/etc/registry/certs/` |
| 59 | +- Configure the registry Quadlet service to use TLS |
| 60 | +- Install the CA certificate to the system trust store |
| 61 | + |
| 62 | +### Step 3: Build the Test Image |
| 63 | + |
| 64 | +Build the test image with: |
| 65 | + |
| 66 | +```bash |
| 67 | +podman build -f hack/Containerfile -t localhost/bootc-derived . |
| 68 | +``` |
| 69 | + |
| 70 | +This will: |
| 71 | +- Copy the CA certificate from `hack/.registry-certs/ca.pem` |
| 72 | +- Install it to the system trust store at `/usr/share/pki/ca-trust-source/anchors/` |
| 73 | +- Run `update-ca-trust` to add it to the trusted certificates |
| 74 | + |
| 75 | +## How It Works |
| 76 | + |
| 77 | +### Registry VM |
| 78 | + |
| 79 | +The registry VM runs a Podman Quadlet service defined in `/usr/share/containers/systemd/registry.container`: |
| 80 | + |
| 81 | +```ini |
| 82 | +[Container] |
| 83 | +Image=quay.io/libpod/registry:2.8.2 |
| 84 | +PublishPort=5000:5000 |
| 85 | +Volume=/var/lib/registry:/var/lib/registry:Z |
| 86 | +Volume=/etc/registry/certs:/certs:Z,ro |
| 87 | +Environment=REGISTRY_HTTP_TLS_CERTIFICATE=/certs/registry-cert.pem |
| 88 | +Environment=REGISTRY_HTTP_TLS_KEY=/certs/registry-key.pem |
| 89 | +``` |
| 90 | + |
| 91 | +The registry container: |
| 92 | +- Listens on port 5000 with TLS enabled |
| 93 | +- Uses the server certificate and key from `/etc/registry/certs/` |
| 94 | +- Certificate is issued for hostname `bootc-registry.test` |
| 95 | +- Validates client connections using TLS |
| 96 | +- Host uses `--dest-tls-verify=false` when pushing (due to --dest-cert-dir limitations in user namespaces) |
| 97 | + |
| 98 | +### Hostname Resolution |
| 99 | + |
| 100 | +The TLS certificate is issued for hostname `bootc-registry.test` instead of hardcoded IP addresses. |
| 101 | +This avoids certificate validation failures when the registry's IP is dynamically assigned. |
| 102 | + |
| 103 | +Test VMs automatically configure hostname resolution during TMT's prepare phase: |
| 104 | + |
| 105 | +1. TMT sets environment variables: |
| 106 | + - `BOOTC_REGISTRY_IP`: The actual IP address of the registry VM |
| 107 | + - `BOOTC_REGISTRY_HOSTNAME`: `bootc-registry.test` |
| 108 | + - `BOOTC_REGISTRY_URL`: `bootc-registry.test:5000` |
| 109 | + |
| 110 | +2. A prepare script adds an entry to `/etc/hosts`: |
| 111 | + ``` |
| 112 | + 192.168.1.124 bootc-registry.test |
| 113 | + ``` |
| 114 | + |
| 115 | +3. When tests use `BOOTC_REGISTRY_URL`, DNS resolves the hostname to the registry's IP, |
| 116 | + and TLS validates the certificate against the hostname. |
| 117 | + |
| 118 | +### Test VMs |
| 119 | + |
| 120 | +Test VMs: |
| 121 | +- Have the CA certificate installed in their system trust store |
| 122 | +- Automatically configure `/etc/hosts` to resolve `bootc-registry.test` to the registry IP |
| 123 | +- Can connect to the registry using HTTPS without `--tls-verify=false` |
| 124 | +- Podman and Skopeo automatically trust the registry's certificate |
| 125 | + |
| 126 | +## Testing the Setup |
| 127 | + |
| 128 | +To test the secure registry setup: |
| 129 | + |
| 130 | +```bash |
| 131 | +# Generate certificates |
| 132 | +./hack/setup-registry-certs.sh |
| 133 | + |
| 134 | +# Build registry image |
| 135 | +podman build -f hack/Containerfile.registry -t bootc-registry . |
| 136 | + |
| 137 | +# Build test image |
| 138 | +podman build -f hack/Containerfile -t localhost/bootc-derived . |
| 139 | + |
| 140 | +# Run TMT tests with registry |
| 141 | +cargo xtask run-tmt --image localhost/bootc-derived --registry-image bootc-registry |
| 142 | +``` |
| 143 | + |
| 144 | +## Troubleshooting |
| 145 | + |
| 146 | +### Certificate Errors |
| 147 | + |
| 148 | +If you see TLS certificate errors: |
| 149 | + |
| 150 | +1. Ensure certificates were generated before building images: |
| 151 | + ```bash |
| 152 | + ls -la hack/.registry-certs/ |
| 153 | + ``` |
| 154 | + |
| 155 | +2. Verify the CA certificate is in the test image: |
| 156 | + ```bash |
| 157 | + podman run --rm localhost/bootc-derived ls -la /usr/share/pki/ca-trust-source/anchors/ |
| 158 | + ``` |
| 159 | + |
| 160 | +3. Check if the certificate is trusted: |
| 161 | + ```bash |
| 162 | + podman run --rm localhost/bootc-derived trust list | grep -i bootc |
| 163 | + ``` |
| 164 | + |
| 165 | +### Registry Connection Issues |
| 166 | + |
| 167 | +If the registry is unreachable: |
| 168 | + |
| 169 | +1. Verify the registry service is running in the registry VM: |
| 170 | + ```bash |
| 171 | + ssh <registry-vm> systemctl status registry.service |
| 172 | + ``` |
| 173 | + |
| 174 | +2. Check registry logs: |
| 175 | + ```bash |
| 176 | + ssh <registry-vm> podman logs registry |
| 177 | + ``` |
| 178 | + |
| 179 | +3. Verify certificates are mounted correctly: |
| 180 | + ```bash |
| 181 | + ssh <registry-vm> ls -la /etc/registry/certs/ |
| 182 | + ``` |
| 183 | + |
| 184 | +## Security Considerations |
| 185 | + |
| 186 | +### Self-Signed Certificates |
| 187 | + |
| 188 | +These certificates are **self-signed** and intended **only for testing**. They: |
| 189 | +- Are not validated by any external Certificate Authority |
| 190 | +- Should never be used in production |
| 191 | +- Are regenerated for each test environment |
| 192 | +- Are automatically trusted only within the test VMs |
| 193 | + |
| 194 | +### Certificate Validity |
| 195 | + |
| 196 | +- Certificates are valid for 10 years from generation |
| 197 | +- Certificate is issued for hostname `bootc-registry.test` (not IP addresses) |
| 198 | +- Test VMs use `/etc/hosts` to resolve the hostname to the actual registry IP |
| 199 | +- The CA private key is stored in `hack/.registry-certs/ca-key.pem` (git-ignored) |
| 200 | + |
| 201 | +### Network Security |
| 202 | + |
| 203 | +- The registry is only accessible on the test network (libvirt bridge) |
| 204 | +- TLS encryption protects image data in transit |
| 205 | +- No authentication is configured (registry is open to the test network) |
| 206 | + |
| 207 | +## Files Modified |
| 208 | + |
| 209 | +- `hack/setup-registry-certs.sh` - Script to generate certificates |
| 210 | +- `hack/Containerfile.registry` - Registry image with TLS support |
| 211 | +- `hack/Containerfile` - Test image with CA certificate trust |
| 212 | +- `tmt/tests/booted/test-image-pushpull-upgrade.nu` - Removed `--tls-verify=false` |
| 213 | +- `crates/xtask/src/tmt.rs` - Removed `--tls-verify=false` from base image push |
| 214 | +- `.gitignore` - Added `hack/.registry-certs/` to ignore generated certificates |
0 commit comments