Browse Source

Add SSH configuration options to support environment variables for strict host key checking and known hosts file path in ssh.lua and compose.yaml

main
Bastian (BaM) 3 months ago
parent
commit
4d2c0aebbb
  1. 2
      compose.yaml
  2. 18
      scripts/ssh.lua

2
compose.yaml

@ -22,6 +22,8 @@ services:
WOL_PORT: "${WOL_PORT:-9}" # optional WOL_PORT: "${WOL_PORT:-9}" # optional
USE_LUAJIT: "${USE_LUAJIT:-true}" # optional: use LuaJIT for better performance (default: true) USE_LUAJIT: "${USE_LUAJIT:-true}" # optional: use LuaJIT for better performance (default: true)
DEBUG: "${DEBUG:-false}" DEBUG: "${DEBUG:-false}"
SSH_STRICT_HOST_KEY_CHECKING: "${SSH_STRICT_HOST_KEY_CHECKING:-no}" # optional: SSH host key verification (default: no)
SSH_KNOWN_HOSTS_FILE: "${SSH_KNOWN_HOSTS_FILE:-/root/.ssh/known_hosts}" # optional: SSH known hosts file path (default: /root/.ssh/known_hosts)
restart: unless-stopped restart: unless-stopped
volumes: volumes:
- /etc/localtime:/etc/localtime:ro - /etc/localtime:/etc/localtime:ro

18
scripts/ssh.lua

@ -36,6 +36,11 @@ function ssh_module.execute(command, user, host, port, identity_file)
-- -oConnectTimeout for faster failure -- -oConnectTimeout for faster failure
-- -oStrictHostKeyChecking uses known_hosts; adjust if needed -- -oStrictHostKeyChecking uses known_hosts; adjust if needed
local dest = (user ~= "" and (user .. "@" .. host) or host) local dest = (user ~= "" and (user .. "@" .. host) or host)
-- Get SSH configuration from environment variables
local strict_host_key_checking = utils.getenv("SSH_STRICT_HOST_KEY_CHECKING", "yes")
local known_hosts_file = utils.getenv("SSH_KNOWN_HOSTS_FILE", "/root/.ssh/known_hosts")
local pieces = { local pieces = {
"ssh", "ssh",
"-p", tostring(port), "-p", tostring(port),
@ -43,8 +48,8 @@ function ssh_module.execute(command, user, host, port, identity_file)
"-o", "ConnectTimeout=30", "-o", "ConnectTimeout=30",
"-o", "ServerAliveInterval=5", "-o", "ServerAliveInterval=5",
"-o", "ServerAliveCountMax=1", "-o", "ServerAliveCountMax=1",
"-o", "UserKnownHostsFile=/root/.ssh/known_hosts", "-o", "UserKnownHostsFile=" .. known_hosts_file,
"-o", "StrictHostKeyChecking=yes", "-o", "StrictHostKeyChecking=" .. strict_host_key_checking,
} }
if identity_file ~= "" then if identity_file ~= "" then
@ -92,6 +97,11 @@ function ssh_module.execute_with_output(command, user, host, port, identity_file
-- Build base ssh command (run locally) -- Build base ssh command (run locally)
local dest = (user ~= "" and (user .. "@" .. host) or host) local dest = (user ~= "" and (user .. "@" .. host) or host)
-- Get SSH configuration from environment variables
local strict_host_key_checking = utils.getenv("SSH_STRICT_HOST_KEY_CHECKING", "yes")
local known_hosts_file = utils.getenv("SSH_KNOWN_HOSTS_FILE", "/root/.ssh/known_hosts")
local pieces = { local pieces = {
"ssh", "ssh",
"-p", tostring(port), "-p", tostring(port),
@ -99,8 +109,8 @@ function ssh_module.execute_with_output(command, user, host, port, identity_file
"-o", "ConnectTimeout=30", "-o", "ConnectTimeout=30",
"-o", "ServerAliveInterval=5", "-o", "ServerAliveInterval=5",
"-o", "ServerAliveCountMax=1", "-o", "ServerAliveCountMax=1",
-- "-o", "UserKnownHostsFile=/root/.ssh/known_hosts", "-o", "UserKnownHostsFile=" .. known_hosts_file,
"-o", "StrictHostKeyChecking=no", "-o", "StrictHostKeyChecking=" .. strict_host_key_checking,
} }
if identity_file ~= "" then if identity_file ~= "" then

Loading…
Cancel
Save