Add OpenSSH client installation and SSH key handling in Dockerfile

This commit is contained in:
Bastian (BaM)
2025-09-14 13:13:43 +02:00
parent 59a19551fe
commit 57b20df159
2 changed files with 52 additions and 38 deletions

View File

@@ -76,45 +76,45 @@ end
-- return false
-- end
local function createSSHKeyFilesFromEnv()
if SSH_PRIVATE_KEY == "" or SSH_PUBLIC_KEY == "" then
log("SSH_PRIVATE_KEY or SSH_PUBLIC_KEY env var is empty, skipping SSH key file creation.")
return
end
-- Ensure .ssh directory exists
local ssh_dir = SSH_IDENTITY_FILE:match("^(.*)/[^/]+$")
if ssh_dir then
os.execute(("mkdir -p %q && chmod 700 %q"):format(ssh_dir, ssh_dir))
end
local priv_fh = io.open(SSH_IDENTITY_FILE, "w")
if not priv_fh then
log("Failed to open SSH identity file for writing: " .. SSH_IDENTITY_FILE)
return
end
priv_fh:write(SSH_PRIVATE_KEY)
priv_fh:close()
os.execute(("chmod 600 %q"):format(SSH_IDENTITY_FILE))
log("Wrote SSH private key to " .. SSH_IDENTITY_FILE)
local pub_fh = io.open(SSH_IDENTITY_FILE .. ".pub", "w")
if not pub_fh then
log("Failed to open SSH public key file for writing: " .. SSH_IDENTITY_FILE .. ".pub")
return
end
pub_fh:write(SSH_PUBLIC_KEY)
pub_fh:close()
os.execute(("chmod 644 %q"):format(SSH_IDENTITY_FILE .. ".pub"))
log("Wrote SSH public key to " .. SSH_IDENTITY_FILE .. ".pub")
-- Unset the env vars for security
os.setenv("SSH_PRIVATE_KEY", "")
os.setenv("SSH_PUBLIC_KEY", "")
end
--local function createSSHKeyFilesFromEnv()
-- if SSH_PRIVATE_KEY == "" or SSH_PUBLIC_KEY == "" then
-- log("SSH_PRIVATE_KEY or SSH_PUBLIC_KEY env var is empty, skipping SSH key file creation.")
-- return
-- end
--
-- -- Ensure .ssh directory exists
-- local ssh_dir = SSH_IDENTITY_FILE:match("^(.*)/[^/]+$")
-- if ssh_dir then
-- os.execute(("mkdir -p %q && chmod 700 %q"):format(ssh_dir, ssh_dir))
-- end
--
-- local priv_fh = io.open(SSH_IDENTITY_FILE, "w")
-- if not priv_fh then
-- log("Failed to open SSH identity file for writing: " .. SSH_IDENTITY_FILE)
-- return
-- end
-- priv_fh:write(SSH_PRIVATE_KEY)
-- priv_fh:close()
-- os.execute(("chmod 600 %q"):format(SSH_IDENTITY_FILE))
-- log("Wrote SSH private key to " .. SSH_IDENTITY_FILE)
--
-- local pub_fh = io.open(SSH_IDENTITY_FILE .. ".pub", "w")
-- if not pub_fh then
-- log("Failed to open SSH public key file for writing: " .. SSH_IDENTITY_FILE .. ".pub")
-- return
-- end
-- pub_fh:write(SSH_PUBLIC_KEY)
-- pub_fh:close()
-- os.execute(("chmod 644 %q"):format(SSH_IDENTITY_FILE .. ".pub"))
-- log("Wrote SSH public key to " .. SSH_IDENTITY_FILE .. ".pub")
--
-- -- Unset the env vars for security
-- os.setenv("SSH_PRIVATE_KEY", "")
-- os.setenv("SSH_PUBLIC_KEY", "")
--end
local function main()
createSSHKeyFilesFromEnv()
-- createSSHKeyFilesFromEnv()
log(("Watching container='%s' since='%s'"):format(CONTAINER_NAME, SINCE))
log(("Looking for pattern: %q"):format(ERROR_PATTERN))