From 1b4dabd37c9aa04a19ef4d677fab6daf33fe0c17 Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Mon, 18 Dec 2017 11:36:58 +0100 Subject: [PATCH 1/5] Add ssh option for direct host OS access Use the `--host` (short `-H`) option in the ssh command to access the host OS of the device. Direct host OS is enabled for devices with Resin OS >= 2.7.5. Change-Type: minor Connects-To: #736 Signed-off-by: Andreas Fitzek --- doc/cli.markdown | 5 +++++ lib/actions/ssh.coffee | 15 +++++++++++++-- package.json | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/doc/cli.markdown b/doc/cli.markdown index a0fb4668..cf811622 100644 --- a/doc/cli.markdown +++ b/doc/cli.markdown @@ -808,6 +808,7 @@ Examples: $ resin ssh 7cf02a6 $ resin ssh 7cf02a6 --port 8080 $ resin ssh 7cf02a6 -v + $ resin ssh 7cf02a6 -H ### Options @@ -819,6 +820,10 @@ ssh gateway port increase verbosity +#### --host, -H + +access host OS + #### --noproxy don't use the proxy configuration for this connection. Only makes sense if you've configured proxy globally. diff --git a/lib/actions/ssh.coffee b/lib/actions/ssh.coffee index e403090f..436f1ffb 100644 --- a/lib/actions/ssh.coffee +++ b/lib/actions/ssh.coffee @@ -31,6 +31,7 @@ module.exports = $ resin ssh 7cf02a6 $ resin ssh 7cf02a6 --port 8080 $ resin ssh 7cf02a6 -v + $ resin ssh 7cf02a6 -H ''' permission: 'user' primary: true @@ -44,6 +45,11 @@ module.exports = boolean: true description: 'increase verbosity' alias: 'v' + , + signature: 'host' + boolean: true + description: 'access host OS' + alias: 'H' , signature: 'noproxy' boolean: true @@ -109,7 +115,7 @@ module.exports = username: resin.auth.whoami() uuid: device.uuid # get full uuid - containerId: resin.models.device.getApplicationInfo(device.uuid).get('containerId') + containerId: if options.host then '' else resin.models.device.getApplicationInfo(device.uuid).get('containerId') proxyUrl: resin.settings.get('proxyUrl') hasTunnelBin: if useProxy then hasbin('proxytunnel') else null @@ -117,12 +123,17 @@ module.exports = throw new Error('Did not find running application container') if not containerId? Promise.try -> sshProxyCommand = getSshProxyCommand(hasTunnelBin) + + accessCommand = "enter #{uuid} #{containerId}" + if options.host + accessCommand = "host #{uuid}" + command = "ssh #{verbose} -t \ -o LogLevel=ERROR \ -o StrictHostKeyChecking=no \ -o UserKnownHostsFile=/dev/null \ #{sshProxyCommand} \ - -p #{options.port} #{username}@ssh.#{proxyUrl} enter #{uuid} #{containerId}" + -p #{options.port} #{username}@ssh.#{proxyUrl} #{accessCommand}" subShellCommand = getSubShellCommand(command) child_process.spawn subShellCommand.program, subShellCommand.args, diff --git a/package.json b/package.json index 07f261e0..edea3537 100644 --- a/package.json +++ b/package.json @@ -143,4 +143,4 @@ "optionalDependencies": { "removedrive": "^1.0.0" } -} \ No newline at end of file +} From ee124671d897dc171f3b15fbae0e97162e1d07a6 Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Mon, 18 Dec 2017 12:51:27 +0100 Subject: [PATCH 2/5] mention Resin OS version requirement --- doc/cli.markdown | 2 +- lib/actions/ssh.coffee | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/cli.markdown b/doc/cli.markdown index cf811622..408ac040 100644 --- a/doc/cli.markdown +++ b/doc/cli.markdown @@ -822,7 +822,7 @@ increase verbosity #### --host, -H -access host OS +access host OS (for devices with Resin OS >= 2.7.5) #### --noproxy diff --git a/lib/actions/ssh.coffee b/lib/actions/ssh.coffee index 436f1ffb..eb824cff 100644 --- a/lib/actions/ssh.coffee +++ b/lib/actions/ssh.coffee @@ -48,7 +48,7 @@ module.exports = , signature: 'host' boolean: true - description: 'access host OS' + description: 'access host OS (for devices with Resin OS >= 2.7.5)' alias: 'H' , signature: 'noproxy' From 3ed319872a67cbe9827d098027b8aad50a08ad04 Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Mon, 18 Dec 2017 14:31:07 +0100 Subject: [PATCH 3/5] refactored --- doc/cli.markdown | 2 +- lib/actions/command-options.coffee | 6 ++++++ lib/actions/local/ssh.coffee | 12 +++++++----- lib/actions/ssh.coffee | 12 +++++------- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/doc/cli.markdown b/doc/cli.markdown index 408ac040..b0d5fbe4 100644 --- a/doc/cli.markdown +++ b/doc/cli.markdown @@ -820,7 +820,7 @@ ssh gateway port increase verbosity -#### --host, -H +#### --host, -s access host OS (for devices with Resin OS >= 2.7.5) diff --git a/lib/actions/command-options.coffee b/lib/actions/command-options.coffee index 108a6f9d..4b78cc31 100644 --- a/lib/actions/command-options.coffee +++ b/lib/actions/command-options.coffee @@ -98,3 +98,9 @@ exports.advancedConfig = description: 'show advanced configuration options' boolean: true alias: 'v' + +exports.hostOSAccess = + signature: 'host' + boolean: true + description: 'access host OS (for devices with Resin OS >= 2.7.5)' + alias: 's' diff --git a/lib/actions/local/ssh.coffee b/lib/actions/local/ssh.coffee index 1908728f..594d5f47 100644 --- a/lib/actions/local/ssh.coffee +++ b/lib/actions/local/ssh.coffee @@ -14,6 +14,12 @@ See the License for the specific language governing permissions and limitations under the License. ### +{ hostOSAccess } = require('../command-options') +_ = require('lodash') + +localHostOSAccessOption = _.cloneDeep(hostOSAccess) +localHostOSAccessOption.description = 'get a shell into the host OS' + module.exports = signature: 'local ssh [deviceIp]' description: 'Get a shell into a resinOS device' @@ -43,11 +49,7 @@ module.exports = description: 'increase verbosity' alias: 'v' , - signature: 'host' - boolean: true - description: 'get a shell into the host OS' - alias: 's' - , + localHostOSAccessOption, signature: 'container' parameter: 'container' default: null diff --git a/lib/actions/ssh.coffee b/lib/actions/ssh.coffee index eb824cff..8258172f 100644 --- a/lib/actions/ssh.coffee +++ b/lib/actions/ssh.coffee @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. ### +commandOptions = require('./command-options') + module.exports = signature: 'ssh [uuid]' description: '(beta) get a shell into the running app container of a device' @@ -45,12 +47,7 @@ module.exports = boolean: true description: 'increase verbosity' alias: 'v' - , - signature: 'host' - boolean: true - description: 'access host OS (for devices with Resin OS >= 2.7.5)' - alias: 'H' - , + commandOptions.hostOSAccess, signature: 'noproxy' boolean: true description: "don't use the proxy configuration for this connection. @@ -124,9 +121,10 @@ module.exports = Promise.try -> sshProxyCommand = getSshProxyCommand(hasTunnelBin) - accessCommand = "enter #{uuid} #{containerId}" if options.host accessCommand = "host #{uuid}" + else + accessCommand = "enter #{uuid} #{containerId}" command = "ssh #{verbose} -t \ -o LogLevel=ERROR \ From 0653769156f36121740f85459c76f0ce0f1eb463 Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Mon, 18 Dec 2017 17:00:07 +0100 Subject: [PATCH 4/5] fixed example --- doc/cli.markdown | 2 +- lib/actions/ssh.coffee | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/cli.markdown b/doc/cli.markdown index b0d5fbe4..3cb7a2cc 100644 --- a/doc/cli.markdown +++ b/doc/cli.markdown @@ -808,7 +808,7 @@ Examples: $ resin ssh 7cf02a6 $ resin ssh 7cf02a6 --port 8080 $ resin ssh 7cf02a6 -v - $ resin ssh 7cf02a6 -H + $ resin ssh 7cf02a6 -s ### Options diff --git a/lib/actions/ssh.coffee b/lib/actions/ssh.coffee index 8258172f..6d2d04fe 100644 --- a/lib/actions/ssh.coffee +++ b/lib/actions/ssh.coffee @@ -33,7 +33,7 @@ module.exports = $ resin ssh 7cf02a6 $ resin ssh 7cf02a6 --port 8080 $ resin ssh 7cf02a6 -v - $ resin ssh 7cf02a6 -H + $ resin ssh 7cf02a6 -s ''' permission: 'user' primary: true From 15b877f0050545ecf3bb6ed7b8efcdbf244ab428 Mon Sep 17 00:00:00 2001 From: "resin-io-versionbot[bot]" Date: Tue, 19 Dec 2017 08:37:19 +0000 Subject: [PATCH 5/5] v6.12.0 --- CHANGELOG.md | 4 ++++ package.json | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aee6d247..e2330644 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY! This project adheres to [Semantic Versioning](http://semver.org/). +## v6.12.0 - 2017-12-19 + +* Add ssh option for direct host OS access #737 [Andreas Fitzek] + ## v6.11.0 - 2017-12-18 * Fix docs generation when building on windows #729 [Tim Perry] diff --git a/package.json b/package.json index edea3537..1de53376 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "resin-cli", - "version": "6.11.0", + "version": "6.12.0", "description": "The official resin.io CLI tool", "main": "./build/actions/index.js", "homepage": "https://github.com/resin-io/resin-cli", @@ -143,4 +143,4 @@ "optionalDependencies": { "removedrive": "^1.0.0" } -} +} \ No newline at end of file