feat: Add SSH public key storage for users

- Add ssh_public_key column to User model for storing SSH keys
- Add database migration for ssh_public_key column
- Add SSH key section in user profile settings with validation
- Auto-inject user's SSH key when deploying VMs from templates
- Auto-inject user's SSH key when creating LXC containers
- Support for both regular and smart LXC creation endpoints
- Add i18n translations for SSH key UI (ru/en)
- Validate SSH key format (ssh-rsa, ssh-ed25519, ecdsa-sha2, ssh-dss)

Users can now save their SSH public key in Settings -> Account,
and it will be automatically added to any VM or LXC container
they create, enabling passwordless SSH access.
This commit is contained in:
2025-12-15 20:22:42 +05:00
parent 2b78d93710
commit 379afd0353
8 changed files with 162 additions and 4 deletions

View File

@@ -875,6 +875,22 @@ def migrate_snapshot_archives(conn):
logger.info("✓ Snapshot archives table created")
# ==================== Migration 12: User SSH Public Key ====================
def migrate_user_ssh_key(conn):
"""Add SSH public key column to users table"""
if column_exists(conn, 'users', 'ssh_public_key'):
logger.info("✓ User SSH public key column already exists")
return
logger.info("Adding SSH public key column to users table...")
add_column_if_not_exists(conn, 'users', 'ssh_public_key', 'TEXT')
logger.info("✓ User SSH public key column added")
# ==================== Main Migration Function ====================
def run_all_migrations(engine, db_session=None):
@@ -978,6 +994,14 @@ def run_all_migrations(engine, db_session=None):
except Exception as e:
logger.warning(f"Snapshot archives migration: {e}")
conn.rollback()
# Migration 12: User SSH Public Key
try:
migrate_user_ssh_key(conn)
conn.commit()
except Exception as e:
logger.warning(f"User SSH key migration: {e}")
conn.rollback()
logger.info("=" * 50)
logger.info("✓ All migrations completed successfully")