1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 01:16:10 +00:00

feat(migration): encrypt migrations over TLS between hosts that have it

QEMU sends a migrating VM's memory and copied disks in the clear. A
compute gets "Encrypt migrations (TLS)" (edit page, Advanced; API
field migration_tls); a migration between two hosts that both have it
passes VIR_MIGRATE_TLS whenever data moves (not for a shut-off VM's
definition alone), and the log says TLS. The hosts need QEMU's
certificates in /etc/pki/qemu; a host without them refuses before
anything moves. Tried on two AlmaLinux 10 hosts: the TLS stream starts
with a TLS record, the plain one with QEMU's QEVM header.
This commit is contained in:
catborise 2026-11-19 15:19:18 +03:00
parent 2e3ffba851
commit eeae606d08
15 changed files with 409 additions and 309 deletions

View file

@ -61,5 +61,5 @@ class ComputeSerializer(serializers.ModelSerializer):
class Meta:
model = Compute
fields = ["id", "name", "hostname", "login", "password", "type", "details", "migration_address", "gstfsd_key",
"tags"]
fields = ["id", "name", "hostname", "login", "password", "type", "details", "migration_address", "migration_tls",
"gstfsd_key", "tags"]

View file

@ -154,4 +154,4 @@ class SocketComputeForm(ComputeTagsMixin, KeepSecretsMixin, forms.ModelForm):
widgets = SECRET_WIDGETS
labels = DETAILS
help_texts = DETAILS_HELP
fields = ["name", "details", "hostname", "migration_address", "gstfsd_key"]
fields = ["name", "details", "hostname", "migration_address", "migration_tls", "gstfsd_key"]

View file

@ -0,0 +1,18 @@
# Generated by Django 5.2.18 on 2026-11-19 11:56
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('computes', '0013_tag_length'),
]
operations = [
migrations.AddField(
model_name='compute',
name='migration_tls',
field=models.BooleanField(default=False, help_text="A VM migrating between two hosts that both have this sends its memory and disks over TLS; each host needs QEMU's certificates in /etc/pki/qemu", verbose_name='encrypt migrations (TLS)'),
),
]

View file

@ -4,7 +4,7 @@ from ipaddress import ip_address
from django.core.exceptions import ValidationError
from django.core.validators import MaxLengthValidator, RegexValidator
from django.db import IntegrityError, transaction
from django.db.models import CharField, DateTimeField, IntegerField, ManyToManyField, Model, Q, UniqueConstraint
from django.db.models import BooleanField, CharField, DateTimeField, IntegerField, ManyToManyField, Model, Q, UniqueConstraint
from django.utils.functional import cached_property
from django.utils.translation import gettext_lazy as _
from django.utils.translation import gettext_noop
@ -69,6 +69,14 @@ class Compute(Model):
"empty: the address the panel reaches the host at"
),
)
migration_tls = BooleanField(
_("encrypt migrations (TLS)"),
default=False,
help_text=_(
"A VM migrating between two hosts that both have this sends its memory and disks over TLS; "
"each host needs QEMU's certificates in /etc/pki/qemu"
),
)
gstfsd_key = CharField(
_("gstfsd key"),
max_length=64,

View file

@ -33,16 +33,18 @@
</div>
</div>
{# open when one of them is set or refused #}
<details class="border-top pt-3"{% if form.migration_address.value or form.migration_address.errors or form.gstfsd_key.errors %} open{% endif %}>
<details class="border-top pt-3"{% if form.migration_address.value or form.migration_address.errors or form.migration_tls.value or form.gstfsd_key.errors %} open{% endif %}>
<summary>
<span class="fw-semibold">{% trans "Advanced" %}</span>
<span class="d-block small text-body-secondary text-break ms-3">
{% trans "Migration address" %}: {{ form.migration_address.value|default:_("the host name") }}
{% if form.migration_tls.value %}&middot; {% trans "migrations over TLS" %}{% endif %}
&middot; {% trans "gstfsd key" %}: {% if form.instance.gstfsd_key %}{% trans "stored" %}{% else %}{% trans "none" %}{% endif %}
</span>
</summary>
<div class="mt-3">
{% bootstrap_field form.migration_address %}
{% bootstrap_field form.migration_tls %}
{% bootstrap_field form.gstfsd_key %}
</div>
</details>

View file

@ -50,6 +50,13 @@ class MigrationAddressTests(TestCase):
self.client.post(reverse("compute_update", args=[compute.id]), {**data, "migration_address": "tcp://x"})
compute.refresh_from_db()
self.assertEqual(compute.migration_address, "198.51.100.9")
self.assertFalse(compute.migration_tls)
page = self.client.get(reverse("compute_update", args=[compute.id]))
self.assertContains(page, 'name="migration_tls"')
self.client.post(reverse("compute_update", args=[compute.id]), {**data, "migration_tls": "on"})
compute.refresh_from_db()
self.assertTrue(compute.migration_tls)
self.assertContains(self.client.get(reverse("compute_update", args=[compute.id])), "migrations over TLS")
def test_a_migration_uses_the_destination_address(self):
source = Compute.objects.create(name="ma-src", hostname="10.0.0.8", login="root", password="", type=2)