From 46e30850527758f2d4f39a8ad296201be8e16e52 Mon Sep 17 00:00:00 2001 From: Jeremy Daer Date: Thu, 3 Oct 2024 09:24:29 -0700 Subject: [PATCH] SSH proxy: allow using a bare hostname without root@ Otherwise we can't connect to the proxy as the local user and we can't use ~/.ssh/config to set User directives. Defaulting to root@ is hard to deprecate without introducing new config. A clean break is probably clearest. --- lib/kamal/configuration/docs/ssh.yml | 4 ++-- lib/kamal/configuration/ssh.rb | 6 +++--- test/commands/app_test.rb | 4 ++-- test/configuration/ssh_test.rb | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/kamal/configuration/docs/ssh.yml b/lib/kamal/configuration/docs/ssh.yml index 8d1033521..291c9c9f1 100644 --- a/lib/kamal/configuration/docs/ssh.yml +++ b/lib/kamal/configuration/docs/ssh.yml @@ -29,8 +29,8 @@ ssh: # Proxy host # - # Specified in the form or @: - proxy: root@proxy-host + # Specified in the form or @ + proxy: proxy-host # Proxy command # diff --git a/lib/kamal/configuration/ssh.rb b/lib/kamal/configuration/ssh.rb index dc88367e2..993c746e6 100644 --- a/lib/kamal/configuration/ssh.rb +++ b/lib/kamal/configuration/ssh.rb @@ -19,9 +19,9 @@ def port end def proxy - if (proxy = ssh_config["proxy"]) - Net::SSH::Proxy::Jump.new(proxy.include?("@") ? proxy : "root@#{proxy}") - elsif (proxy_command = ssh_config["proxy_command"]) + if proxy = ssh_config["proxy"] + Net::SSH::Proxy::Jump.new(proxy) + elsif proxy_command = ssh_config["proxy_command"] Net::SSH::Proxy::Command.new(proxy_command) end end diff --git a/test/commands/app_test.rb b/test/commands/app_test.rb index 182c1bb0b..522518421 100644 --- a/test/commands/app_test.rb +++ b/test/commands/app_test.rb @@ -294,7 +294,7 @@ class CommandsAppTest < ActiveSupport::TestCase test "run over ssh with proxy" do @config[:ssh] = { "proxy" => "2.2.2.2" } - assert_equal "ssh -J root@2.2.2.2 -t root@1.1.1.1 -p 22 'ls'", new_command.run_over_ssh("ls", host: "1.1.1.1") + assert_equal "ssh -J 2.2.2.2 -t root@1.1.1.1 -p 22 'ls'", new_command.run_over_ssh("ls", host: "1.1.1.1") end test "run over ssh with proxy user" do @@ -304,7 +304,7 @@ class CommandsAppTest < ActiveSupport::TestCase test "run over ssh with custom user with proxy" do @config[:ssh] = { "user" => "app", "proxy" => "2.2.2.2" } - assert_equal "ssh -J root@2.2.2.2 -t app@1.1.1.1 -p 22 'ls'", new_command.run_over_ssh("ls", host: "1.1.1.1") + assert_equal "ssh -J 2.2.2.2 -t app@1.1.1.1 -p 22 'ls'", new_command.run_over_ssh("ls", host: "1.1.1.1") end test "run over ssh with proxy_command" do diff --git a/test/configuration/ssh_test.rb b/test/configuration/ssh_test.rb index 76d1ae9a7..987335197 100644 --- a/test/configuration/ssh_test.rb +++ b/test/configuration/ssh_test.rb @@ -30,7 +30,7 @@ class ConfigurationSshTest < ActiveSupport::TestCase test "ssh options with proxy host" do config = Kamal::Configuration.new(@deploy.tap { |c| c.merge!(ssh: { "proxy" => "1.2.3.4" }) }) - assert_equal "root@1.2.3.4", config.ssh.options[:proxy].jump_proxies + assert_equal "1.2.3.4", config.ssh.options[:proxy].jump_proxies end test "ssh options with proxy host and user" do