Use single string-based proxy declaration
This commit is contained in:
committed by
Chris de Bruin
parent
1fef6ba505
commit
71681cb8be
14
README.md
14
README.md
@@ -75,14 +75,20 @@ ssh:
|
||||
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
|
||||
ssh:
|
||||
proxy_host: 192.168.0.1
|
||||
user_proxy_host: app # defaults to root
|
||||
proxy: "192.168.0.1" # defaults to root as the user
|
||||
```
|
||||
|
||||
Or with specific user:
|
||||
|
||||
```yaml
|
||||
ssh:
|
||||
proxy: "app@192.168.0.1"
|
||||
```
|
||||
|
||||
### Using env variables
|
||||
|
||||
@@ -112,26 +112,15 @@ class Mrsk::Configuration
|
||||
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
|
||||
options = { user: ssh_user, auth_methods: [ "publickey" ] }
|
||||
|
||||
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
|
||||
{ user: ssh_user, proxy: ssh_proxy, auth_methods: [ "publickey" ] }.compact
|
||||
end
|
||||
|
||||
def master_key
|
||||
|
||||
@@ -145,10 +145,15 @@ class ConfigurationTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
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
|
||||
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
|
||||
assert_equal "456", @config.master_key
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user