(feature) Add Django-managed SSH credentials
Add SSH credentials as first-class Django data so backup keys can be uploaded through the control panel instead of mounted into containers. Credentials can be selected globally or overridden per host. At runtime the selected key is materialized inside the container with restrictive file permissions and injected into the rsync SSH command via IdentityFile. Known hosts entries are handled the same way when configured. Add control panel views for creating and listing SSH keys, expose the fields in config forms and admin, document the workflow, and cover global and host credential selection with tests.
This commit is contained in:
51
src/pobsync_backend/migrations/0006_ssh_credentials.py
Normal file
51
src/pobsync_backend/migrations/0006_ssh_credentials.py
Normal file
@@ -0,0 +1,51 @@
|
||||
# Generated by Django 5.2.14 on 2026-05-19
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("pobsync_backend", "0005_snapshotrecord_base"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="SshCredential",
|
||||
fields=[
|
||||
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
|
||||
("created_at", models.DateTimeField(auto_now_add=True)),
|
||||
("updated_at", models.DateTimeField(auto_now=True)),
|
||||
("name", models.CharField(max_length=128, unique=True)),
|
||||
("private_key", models.TextField()),
|
||||
("public_key", models.TextField(blank=True)),
|
||||
("known_hosts", models.TextField(blank=True)),
|
||||
("notes", models.TextField(blank=True)),
|
||||
],
|
||||
options={
|
||||
"ordering": ["name"],
|
||||
},
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="globalconfig",
|
||||
name="default_ssh_credential",
|
||||
field=models.ForeignKey(
|
||||
blank=True,
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.SET_NULL,
|
||||
related_name="global_configs",
|
||||
to="pobsync_backend.sshcredential",
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="hostconfig",
|
||||
name="ssh_credential",
|
||||
field=models.ForeignKey(
|
||||
blank=True,
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.SET_NULL,
|
||||
related_name="hosts",
|
||||
to="pobsync_backend.sshcredential",
|
||||
),
|
||||
),
|
||||
]
|
||||
Reference in New Issue
Block a user