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

This commit is contained in:
Bastian (BaM)
2025-09-15 09:51:43 +02:00
parent c9f5cb673d
commit 4d2c0aebbb
2 changed files with 16 additions and 4 deletions

View File

@@ -36,6 +36,11 @@ function ssh_module.execute(command, user, host, port, identity_file)
-- -oConnectTimeout for faster failure
-- -oStrictHostKeyChecking uses known_hosts; adjust if needed
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 = {
"ssh",
"-p", tostring(port),
@@ -43,8 +48,8 @@ function ssh_module.execute(command, user, host, port, identity_file)
"-o", "ConnectTimeout=30",
"-o", "ServerAliveInterval=5",
"-o", "ServerAliveCountMax=1",
"-o", "UserKnownHostsFile=/root/.ssh/known_hosts",
"-o", "StrictHostKeyChecking=yes",
"-o", "UserKnownHostsFile=" .. known_hosts_file,
"-o", "StrictHostKeyChecking=" .. strict_host_key_checking,
}
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)
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 = {
"ssh",
"-p", tostring(port),
@@ -99,8 +109,8 @@ function ssh_module.execute_with_output(command, user, host, port, identity_file
"-o", "ConnectTimeout=30",
"-o", "ServerAliveInterval=5",
"-o", "ServerAliveCountMax=1",
-- "-o", "UserKnownHostsFile=/root/.ssh/known_hosts",
"-o", "StrictHostKeyChecking=no",
"-o", "UserKnownHostsFile=" .. known_hosts_file,
"-o", "StrictHostKeyChecking=" .. strict_host_key_checking,
}
if identity_file ~= "" then