Use single string-based proxy declaration

This commit is contained in:
David Heinemeier Hansson
2023-01-31 13:59:19 +01:00
committed by Chris de Bruin
parent 1fef6ba505
commit 71681cb8be
3 changed files with 24 additions and 24 deletions

View File

@@ -75,14 +75,20 @@ ssh:
user: app user: app
``` ```
### Using a bastion/proxy/jump SSH host ### Using a proxy SSH host
If you need to connect to server through a bastion host, you can use `ssh/proxy_host`: If you need to connect to server through a proxy host, you can use `ssh/proxy`:
```yaml ```yaml
ssh: ssh:
proxy_host: 192.168.0.1 proxy: "192.168.0.1" # defaults to root as the user
user_proxy_host: app # defaults to root ```
Or with specific user:
```yaml
ssh:
proxy: "app@192.168.0.1"
``` ```
### Using env variables ### Using env variables

View File

@@ -112,26 +112,15 @@ class Mrsk::Configuration
end end
end end
def ssh_proxy
if raw_config.ssh.present? && raw_config.ssh["proxy"]
Net::SSH::Proxy::Jump.new \
raw_config.ssh["proxy"].include?("@") ? raw_config.ssh["proxy"] : "root@#{raw_config.ssh["proxy"]}"
end
end
def ssh_options def ssh_options
options = { user: ssh_user, auth_methods: [ "publickey" ] } { user: ssh_user, proxy: ssh_proxy, auth_methods: [ "publickey" ] }.compact
options[:proxy] = ::Net::SSH::Proxy::Jump.new(ssh_proxy_host) if ssh_proxy_host
options
end
def ssh_proxy_host
if raw_config.ssh && raw_config.ssh["proxy_host"]
"#{ssh_user_proxy_host}@#{raw_config.ssh['proxy_host']}"
end
end
def ssh_user_proxy_host
if raw_config.ssh.present?
raw_config.ssh["user_proxy_host"] || "root"
else
"root"
end
end end
def master_key def master_key

View File

@@ -145,10 +145,15 @@ class ConfigurationTest < ActiveSupport::TestCase
end end
test "ssh options with proxy host" do test "ssh options with proxy host" do
config = Mrsk::Configuration.new(@deploy.tap { |c| c.merge!(ssh: { "proxy_host" => "1.2.3.4" }) }) config = Mrsk::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 "root@1.2.3.4", @config.ssh_options[:proxy].jump_proxies
end end
test "ssh options with proxy host and user" do
config = Mrsk::Configuration.new(@deploy.tap { |c| c.merge!(ssh: { "proxy" => "app@1.2.3.4" }) })
assert_equal "app@1.2.3.4", @config.ssh_options[:proxy].jump_proxies
end
test "master key" do test "master key" do
assert_equal "456", @config.master_key assert_equal "456", @config.master_key
end end