From 9227d94037d50c5814ac43148b0f101720b48ccc Mon Sep 17 00:00:00 2001 From: Gregor MacDougall Date: Tue, 7 Feb 2017 10:25:41 -0500 Subject: [PATCH 1/2] Add ability to RemoteForward This adds the ability to set a remote forward option in order to forward ports to a remote server potentially through a bastion host. --- lib/omc/cli.rb | 4 +++- lib/omc/stack_command.rb | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/omc/cli.rb b/lib/omc/cli.rb index d17fccb..a7ddd47 100644 --- a/lib/omc/cli.rb +++ b/lib/omc/cli.rb @@ -9,6 +9,7 @@ class Cli < Thor class_option :account, aliases: '-a' class_option :layer, aliases: '-l' class_option :forward_agent, aliases: "-A", type: :boolean, default: false + class_option :remote_forward, aliases: "-R", type: :string, default: nil desc 'ssh STACK', 'Connect to an instance on a stack on an account' def ssh(stack) @@ -17,7 +18,8 @@ def ssh(stack) user, stack, layer: options[:layer], - forward_agent: options[:forward_agent] + forward_agent: options[:forward_agent], + remote_forward: options[:remote_forward] ) command.ssh end diff --git a/lib/omc/stack_command.rb b/lib/omc/stack_command.rb index 991a217..092e0d7 100644 --- a/lib/omc/stack_command.rb +++ b/lib/omc/stack_command.rb @@ -3,13 +3,14 @@ module Omc class StackCommand - def initialize aws_account, user, stack_name, app: nil, layer: nil, forward_agent: false + def initialize aws_account, user, stack_name, app: nil, layer: nil, forward_agent: false, remote_forward: nil @aws_account = aws_account @user = user @stack_name = stack_name @app_name = app @layer_name = layer @forward_agent = forward_agent + @remote_forward = remote_forward end def ssh @@ -100,8 +101,11 @@ def bastion def default_ssh_args [].tap do |args| - args.push("-o", "ProxyCommand ssh -W %h:%p #{bastion.host}") if bastion + proxy_command = "ProxyCommand ssh -W %h:%p #{bastion.host}" + proxy_command += " -R #{@remote_forward}" if @remote_forward + args.push("-o", proxy_command) if bastion args.push("-A") if @forward_agent + args.push("-R #{@remote_forward}") if @remote_forward end end From 03aeb0d8a0463151121e162edf7771747d8d174c Mon Sep 17 00:00:00 2001 From: Gregor MacDougall Date: Tue, 7 Feb 2017 10:27:57 -0500 Subject: [PATCH 2/2] Bump to 0.0.10 --- README.md | 8 ++++++++ lib/omc/stack_command.rb | 8 +++++--- lib/omc/version.rb | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2412158..6342fde 100644 --- a/README.md +++ b/README.md @@ -34,3 +34,11 @@ secret = "abcd1234" ``` omc help ``` + +Accepted ssh options: +``` +-R 3000:localhost:3001 # Forwards port 3000 on the remote host to port 3001 on the localhost +-A # Forward agent +``` + +Please the the ssh help for more detail. diff --git a/lib/omc/stack_command.rb b/lib/omc/stack_command.rb index 092e0d7..e12656c 100644 --- a/lib/omc/stack_command.rb +++ b/lib/omc/stack_command.rb @@ -101,9 +101,11 @@ def bastion def default_ssh_args [].tap do |args| - proxy_command = "ProxyCommand ssh -W %h:%p #{bastion.host}" - proxy_command += " -R #{@remote_forward}" if @remote_forward - args.push("-o", proxy_command) if bastion + if (bastion) + proxy_command = "ProxyCommand ssh -W %h:%p #{bastion.host}" + proxy_command += " -R #{@remote_forward}" if @remote_forward + args.push("-o", proxy_command) + end args.push("-A") if @forward_agent args.push("-R #{@remote_forward}") if @remote_forward end diff --git a/lib/omc/version.rb b/lib/omc/version.rb index 78fd699..1c7eaa5 100644 --- a/lib/omc/version.rb +++ b/lib/omc/version.rb @@ -1,3 +1,3 @@ module Omc - VERSION = '0.0.9' + VERSION = '0.0.10' end