mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-04-27 14:30:07 +00:00
check for proxytunnel presence
This commit is contained in:
parent
6ae59654a0
commit
4b5240d8cd
@ -15,14 +15,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
var _, bash, getSubShellCommand;
|
|
||||||
|
|
||||||
_ = require('lodash');
|
|
||||||
|
|
||||||
bash = require('bash');
|
|
||||||
|
|
||||||
getSubShellCommand = require('../utils/helpers').getSubShellCommand;
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
signature: 'ssh [uuid]',
|
signature: 'ssh [uuid]',
|
||||||
description: '(beta) get a shell into the running app container of a device',
|
description: '(beta) get a shell into the running app container of a device',
|
||||||
@ -47,15 +39,47 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
action: function(params, options, done) {
|
action: function(params, options, done) {
|
||||||
var Promise, child_process, patterns, resin, verbose;
|
var Promise, _, bash, child_process, getSshProxyCommand, getSubShellCommand, hasbin, patterns, proxyConfig, resin, useProxy, verbose;
|
||||||
child_process = require('child_process');
|
child_process = require('child_process');
|
||||||
Promise = require('bluebird');
|
Promise = require('bluebird');
|
||||||
resin = require('resin-sdk-preconfigured');
|
resin = require('resin-sdk-preconfigured');
|
||||||
|
_ = require('lodash');
|
||||||
|
bash = require('bash');
|
||||||
|
hasbin = require('hasbin');
|
||||||
|
getSubShellCommand = require('../utils/helpers').getSubShellCommand;
|
||||||
patterns = require('../utils/patterns');
|
patterns = require('../utils/patterns');
|
||||||
if (options.port == null) {
|
if (options.port == null) {
|
||||||
options.port = 22;
|
options.port = 22;
|
||||||
}
|
}
|
||||||
verbose = options.verbose ? '-vvv' : '';
|
verbose = options.verbose ? '-vvv' : '';
|
||||||
|
proxyConfig = global.PROXY_CONFIG;
|
||||||
|
useProxy = !!proxyConfig && !options.noproxy;
|
||||||
|
getSshProxyCommand = function(hasTunnelBin) {
|
||||||
|
var i, proxyAuth, proxyCommand, tunnelOptions;
|
||||||
|
if (!useProxy) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
if (!hasTunnelBin) {
|
||||||
|
console.warn('Proxy is enabled but the `proxytunnel` binary cannot be found.\nPlease install it if you want to route the `resin ssh` requests through the proxy.\nAlternatively you can pass `--noproxy` param to the `resin ssh` command to ignore the proxy config\nfor the `ssh` requests.\n\nAttemmpting the unproxied request for now.');
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
tunnelOptions = {
|
||||||
|
proxy: proxyConfig.host + ":" + proxyConfig.port,
|
||||||
|
dest: '%h:%p'
|
||||||
|
};
|
||||||
|
proxyAuth = proxyConfig.proxyAuth;
|
||||||
|
if (proxyAuth) {
|
||||||
|
i = proxyAuth.indexOf(':');
|
||||||
|
_.assign(tunnelOptions, {
|
||||||
|
user: proxyAuth.substring(0, i),
|
||||||
|
pass: proxyAuth.substring(i + 1)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
proxyCommand = "proxytunnel " + (bash.args(tunnelOptions, '--', '='));
|
||||||
|
return "-o " + (bash.args({
|
||||||
|
ProxyCommand: proxyCommand
|
||||||
|
}, '', '='));
|
||||||
|
};
|
||||||
return Promise["try"](function() {
|
return Promise["try"](function() {
|
||||||
if (!params.uuid) {
|
if (!params.uuid) {
|
||||||
return false;
|
return false;
|
||||||
@ -77,35 +101,17 @@ module.exports = {
|
|||||||
username: resin.auth.whoami(),
|
username: resin.auth.whoami(),
|
||||||
uuid: device.uuid,
|
uuid: device.uuid,
|
||||||
containerId: resin.models.device.getApplicationInfo(device.uuid).get('containerId'),
|
containerId: resin.models.device.getApplicationInfo(device.uuid).get('containerId'),
|
||||||
proxyUrl: resin.settings.get('proxyUrl')
|
proxyUrl: resin.settings.get('proxyUrl'),
|
||||||
|
hasTunnelBin: useProxy ? hasbin('proxytunnel') : null
|
||||||
}).then(function(arg) {
|
}).then(function(arg) {
|
||||||
var containerId, proxyUrl, username, uuid;
|
var containerId, hasTunnelBin, proxyUrl, username, uuid;
|
||||||
username = arg.username, uuid = arg.uuid, containerId = arg.containerId, proxyUrl = arg.proxyUrl;
|
username = arg.username, uuid = arg.uuid, containerId = arg.containerId, proxyUrl = arg.proxyUrl, hasTunnelBin = arg.hasTunnelBin;
|
||||||
if (containerId == null) {
|
if (containerId == null) {
|
||||||
throw new Error('Did not find running application container');
|
throw new Error('Did not find running application container');
|
||||||
}
|
}
|
||||||
return Promise["try"](function() {
|
return Promise["try"](function() {
|
||||||
var command, i, proxyAuth, proxyCommand, proxyConfig, sshProxyCommand, subShellCommand, tunnelOptions;
|
var command, sshProxyCommand, subShellCommand;
|
||||||
sshProxyCommand = '';
|
sshProxyCommand = getSshProxyCommand(hasTunnelBin);
|
||||||
proxyConfig = global.PROXY_CONFIG;
|
|
||||||
if (proxyConfig && !options.noproxy) {
|
|
||||||
tunnelOptions = {
|
|
||||||
proxy: proxyConfig.host + ":" + proxyConfig.port,
|
|
||||||
dest: '%h:%p'
|
|
||||||
};
|
|
||||||
proxyAuth = proxyConfig.proxyAuth;
|
|
||||||
if (proxyAuth) {
|
|
||||||
i = proxyAuth.indexOf(':');
|
|
||||||
_.assign(tunnelOptions, {
|
|
||||||
user: proxyAuth.substring(0, i),
|
|
||||||
pass: proxyAuth.substring(i + 1)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
proxyCommand = "proxytunnel " + (bash.args(tunnelOptions, '--', '='));
|
|
||||||
sshProxyCommand = "-o " + (bash.args({
|
|
||||||
ProxyCommand: proxyCommand
|
|
||||||
}, '', '='));
|
|
||||||
}
|
|
||||||
command = "ssh " + verbose + " -t -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ControlMaster=no " + sshProxyCommand + " -p " + options.port + " " + username + "@ssh." + proxyUrl + " enter " + uuid + " " + containerId;
|
command = "ssh " + verbose + " -t -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ControlMaster=no " + sshProxyCommand + " -p " + options.port + " " + username + "@ssh." + proxyUrl + " enter " + uuid + " " + containerId;
|
||||||
subShellCommand = getSubShellCommand(command);
|
subShellCommand = getSubShellCommand(command);
|
||||||
return child_process.spawn(subShellCommand.program, subShellCommand.args, {
|
return child_process.spawn(subShellCommand.program, subShellCommand.args, {
|
||||||
|
@ -14,10 +14,6 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
###
|
###
|
||||||
|
|
||||||
_ = require('lodash')
|
|
||||||
bash = require('bash')
|
|
||||||
{ getSubShellCommand } = require('../utils/helpers')
|
|
||||||
|
|
||||||
module.exports =
|
module.exports =
|
||||||
signature: 'ssh [uuid]'
|
signature: 'ssh [uuid]'
|
||||||
description: '(beta) get a shell into the running app container of a device'
|
description: '(beta) get a shell into the running app container of a device'
|
||||||
@ -58,12 +54,45 @@ module.exports =
|
|||||||
child_process = require('child_process')
|
child_process = require('child_process')
|
||||||
Promise = require('bluebird')
|
Promise = require('bluebird')
|
||||||
resin = require('resin-sdk-preconfigured')
|
resin = require('resin-sdk-preconfigured')
|
||||||
|
_ = require('lodash')
|
||||||
|
bash = require('bash')
|
||||||
|
hasbin = require('hasbin')
|
||||||
|
{ getSubShellCommand } = require('../utils/helpers')
|
||||||
patterns = require('../utils/patterns')
|
patterns = require('../utils/patterns')
|
||||||
|
|
||||||
options.port ?= 22
|
options.port ?= 22
|
||||||
|
|
||||||
verbose = if options.verbose then '-vvv' else ''
|
verbose = if options.verbose then '-vvv' else ''
|
||||||
|
|
||||||
|
proxyConfig = global.PROXY_CONFIG
|
||||||
|
useProxy = !!proxyConfig and not options.noproxy
|
||||||
|
|
||||||
|
getSshProxyCommand = (hasTunnelBin) ->
|
||||||
|
return '' if not useProxy
|
||||||
|
|
||||||
|
if not hasTunnelBin
|
||||||
|
console.warn('''
|
||||||
|
Proxy is enabled but the `proxytunnel` binary cannot be found.
|
||||||
|
Please install it if you want to route the `resin ssh` requests through the proxy.
|
||||||
|
Alternatively you can pass `--noproxy` param to the `resin ssh` command to ignore the proxy config
|
||||||
|
for the `ssh` requests.
|
||||||
|
|
||||||
|
Attemmpting the unproxied request for now.
|
||||||
|
''')
|
||||||
|
return ''
|
||||||
|
|
||||||
|
tunnelOptions =
|
||||||
|
proxy: "#{proxyConfig.host}:#{proxyConfig.port}"
|
||||||
|
dest: '%h:%p'
|
||||||
|
{ proxyAuth } = proxyConfig
|
||||||
|
if proxyAuth
|
||||||
|
i = proxyAuth.indexOf(':')
|
||||||
|
_.assign tunnelOptions,
|
||||||
|
user: proxyAuth.substring(0, i)
|
||||||
|
pass: proxyAuth.substring(i + 1)
|
||||||
|
proxyCommand = "proxytunnel #{bash.args(tunnelOptions, '--', '=')}"
|
||||||
|
return "-o #{bash.args({ ProxyCommand: proxyCommand }, '', '=')}"
|
||||||
|
|
||||||
Promise.try ->
|
Promise.try ->
|
||||||
return false if not params.uuid
|
return false if not params.uuid
|
||||||
return resin.models.device.has(params.uuid)
|
return resin.models.device.has(params.uuid)
|
||||||
@ -82,25 +111,12 @@ module.exports =
|
|||||||
# get full uuid
|
# get full uuid
|
||||||
containerId: resin.models.device.getApplicationInfo(device.uuid).get('containerId')
|
containerId: resin.models.device.getApplicationInfo(device.uuid).get('containerId')
|
||||||
proxyUrl: resin.settings.get('proxyUrl')
|
proxyUrl: resin.settings.get('proxyUrl')
|
||||||
.then ({ username, uuid, containerId, proxyUrl }) ->
|
|
||||||
|
hasTunnelBin: if useProxy then hasbin('proxytunnel') else null
|
||||||
|
.then ({ username, uuid, containerId, proxyUrl, hasTunnelBin }) ->
|
||||||
throw new Error('Did not find running application container') if not containerId?
|
throw new Error('Did not find running application container') if not containerId?
|
||||||
Promise.try ->
|
Promise.try ->
|
||||||
sshProxyCommand = ''
|
sshProxyCommand = getSshProxyCommand(hasTunnelBin)
|
||||||
|
|
||||||
proxyConfig = global.PROXY_CONFIG
|
|
||||||
if proxyConfig and not options.noproxy
|
|
||||||
tunnelOptions =
|
|
||||||
proxy: "#{proxyConfig.host}:#{proxyConfig.port}"
|
|
||||||
dest: '%h:%p'
|
|
||||||
{ proxyAuth } = proxyConfig
|
|
||||||
if proxyAuth
|
|
||||||
i = proxyAuth.indexOf(':')
|
|
||||||
_.assign tunnelOptions,
|
|
||||||
user: proxyAuth.substring(0, i)
|
|
||||||
pass: proxyAuth.substring(i + 1)
|
|
||||||
proxyCommand = "proxytunnel #{bash.args(tunnelOptions, '--', '=')}"
|
|
||||||
sshProxyCommand = "-o #{bash.args({ ProxyCommand: proxyCommand }, '', '=')}"
|
|
||||||
|
|
||||||
command = "ssh #{verbose} -t \
|
command = "ssh #{verbose} -t \
|
||||||
-o LogLevel=ERROR \
|
-o LogLevel=ERROR \
|
||||||
-o StrictHostKeyChecking=no \
|
-o StrictHostKeyChecking=no \
|
||||||
|
@ -50,6 +50,7 @@
|
|||||||
"drivelist": "^5.0.16",
|
"drivelist": "^5.0.16",
|
||||||
"etcher-image-write": "^9.0.3",
|
"etcher-image-write": "^9.0.3",
|
||||||
"global-tunnel-ng": "^2.1.0",
|
"global-tunnel-ng": "^2.1.0",
|
||||||
|
"hasbin": "^1.2.3",
|
||||||
"inquirer": "^3.0.6",
|
"inquirer": "^3.0.6",
|
||||||
"is-root": "^1.0.0",
|
"is-root": "^1.0.0",
|
||||||
"js-yaml": "^3.7.0",
|
"js-yaml": "^3.7.0",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user