Add SSH key authentication to proxmox. Not tested yet.
This commit is contained in:
@@ -20,22 +20,26 @@ Options:
|
||||
-c, --cores CORES Nombre de cœurs CPU.
|
||||
-m, --memory MEMORY RAM en Mo.
|
||||
-s, --swap SWAP Swap en Mo.
|
||||
-p, --password PASSWORD Mot de passe root.
|
||||
-p, --password PASSWORD Mot de passe root du conteneur.
|
||||
-b, --bridge BRIDGE Bridge réseau (ex: vmbr0).
|
||||
-v, --vlan VLAN VLAN (ex: tag=10).
|
||||
-d, --domain DOMAIN Domaine DNS.
|
||||
-u, --unprivileged UNPRIV Conteneur non privilégié (0 ou 1).
|
||||
-i, --ip IP IP statique (ex: 192.168.1.100/24).
|
||||
--pve-host HOST Hôte Proxmox (ex: pve).
|
||||
--pve-user USER Utilisateur Proxmox (ex: root).
|
||||
--pve-user USER Utilisateur Proxmox (ex: admin).
|
||||
--pve-port PORT Port SSH Proxmox (ex: 22).
|
||||
--pve-password PASSWORD Mot de passe pour l'authentification SSH sur Proxmox.
|
||||
--pve-ssh-key KEY Fichier de clé SSH pour l'authentification (ex: ~/.ssh/id_admin).
|
||||
"
|
||||
|
||||
# --- Paramètres par défaut (variables d'environnement) ---
|
||||
# Serveur Proxmox
|
||||
PVE_HOST="${PVE_HOST:-pve}"
|
||||
PVE_USER="${PVE_USER:-root}"
|
||||
PVE_HOST="${PVE_HOST:-}"
|
||||
PVE_USER="${PVE_USER:-admin}"
|
||||
PVE_PORT="${PVE_PORT:-22}"
|
||||
PVE_PASSWORD="${PVE_PASSWORD:-}"
|
||||
PVE_SSH_KEY="${PVE_SSH_KEY:-}"
|
||||
|
||||
# Conteneur LXC
|
||||
TEMPLATE="${TEMPLATE:-local:vztmpl/nixos-unstable-amd64-default_20260428_0830-rootfs.tar.gz}"
|
||||
@@ -79,9 +83,15 @@ if [ -f "./$SHORT_NAME" ]; then
|
||||
fi
|
||||
|
||||
# --- Application des arguments de la ligne de commande (priorité la plus haute) ---
|
||||
# On réapplique les valeurs de docopts pour écraser les fichiers de configuration
|
||||
eval "$args"
|
||||
|
||||
# --- Gestion de la clé SSH par défaut ---
|
||||
if [ "$PVE_SSH_KEY" = "default" ]; then
|
||||
PVE_SSH_KEY="${HOME}/.ssh/id_${PVE_USER}"
|
||||
elif [ -z "$PVE_SSH_KEY" ] && [ -z "$PVE_PASSWORD" ]; then
|
||||
PVE_SSH_KEY="${HOME}/.ssh/id_${PVE_USER}"
|
||||
fi
|
||||
|
||||
# --- Vérification des paramètres critiques ---
|
||||
if [ -z "$TEMPLATE" ] || [ -z "$ROOTFS_SIZE" ] || [ -z "$CORES" ] || \
|
||||
[ -z "$MEMORY" ] || [ -z "$SWAP" ] || [ -z "$PASSWORD" ] || \
|
||||
@@ -91,9 +101,28 @@ if [ -z "$TEMPLATE" ] || [ -z "$ROOTFS_SIZE" ] || [ -z "$CORES" ] || \
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Vérification de l'authentification
|
||||
if [ -z "$PVE_PASSWORD" ]; then
|
||||
if [ -z "$PVE_SSH_KEY" ]; then
|
||||
echo "❌ Erreur : Aucun paramètre d'authentification (mot de passe ou clé SSH) n'est défini." >&2
|
||||
exit 1
|
||||
elif [ ! -f "$PVE_SSH_KEY" ]; then
|
||||
echo "❌ Erreur : Le fichier de clé SSH '$PVE_SSH_KEY' n'existe pas." >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# --- Connexion SSH au serveur Proxmox ---
|
||||
run_proxmox() {
|
||||
ssh -p "$PVE_PORT" "$PVE_USER@$PVE_HOST" "$1"
|
||||
local ssh_cmd="ssh -p $PVE_PORT"
|
||||
# Priorité à la clé SSH si elle est fournie et existe
|
||||
if [ -n "$PVE_SSH_KEY" ] && [ -f "$PVE_SSH_KEY" ]; then
|
||||
ssh_cmd="$ssh_cmd -i $PVE_SSH_KEY"
|
||||
else
|
||||
# Utiliser le mot de passe si la clé SSH n'est pas disponible
|
||||
ssh_cmd="$ssh_cmd -o PreferredAuthentications=password -o StrictHostKeyChecking=no"
|
||||
fi
|
||||
$ssh_cmd "$PVE_USER@$PVE_HOST" "$1"
|
||||
}
|
||||
|
||||
# --- Construction des options réseau ---
|
||||
|
||||
Reference in New Issue
Block a user