Add support for self-signed certificates to MaxCtrl
MaxCtrl now supports explicit paths for certificates and optional server certificate verification. This allows testing by using a self-signed certificate with the server certificate verification turned off.
This commit is contained in:
@ -43,10 +43,17 @@ All command accept the following global options.
|
|||||||
-h, --hosts List of MaxScale hosts. The hosts must be in HOST:PORT format
|
-h, --hosts List of MaxScale hosts. The hosts must be in HOST:PORT format
|
||||||
and each value must be separated by a comma.
|
and each value must be separated by a comma.
|
||||||
[string] [default: "localhost:8989"]
|
[string] [default: "localhost:8989"]
|
||||||
-s, --secure Enable HTTPS requests [boolean] [default: "false"]
|
-t, --timeout Request timeout in milliseconds [number] [default: 10000]
|
||||||
-t, --timeout Request timeout in milliseconds [number] [default: "10000"]
|
-q, --quiet Silence all output [boolean] [default: false]
|
||||||
-q, --quiet Silence all output [boolean] [default: "false"]
|
--tsv Print tab separated output [boolean] [default: false]
|
||||||
--tsv Print tab separated output [boolean] [default: "false"]
|
|
||||||
|
HTTPS/TLS Options:
|
||||||
|
-s, --secure Enable HTTPS requests [boolean] [default: false]
|
||||||
|
--tls-key Path to TLS private key [string]
|
||||||
|
--tls-cert Path to TLS public certificate [string]
|
||||||
|
--tls-ca-cert Path to TLS CA certificate [string]
|
||||||
|
--tls-verify-server-cert Whether to verify server TLS certificates
|
||||||
|
[boolean] [default: true]
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
--version Show version number [boolean]
|
--version Show version number [boolean]
|
||||||
|
|||||||
@ -16,6 +16,7 @@ var colors = require('colors/safe');
|
|||||||
var Table = require('cli-table');
|
var Table = require('cli-table');
|
||||||
var consoleLib = require('console')
|
var consoleLib = require('console')
|
||||||
var os = require('os')
|
var os = require('os')
|
||||||
|
var fs = require('fs')
|
||||||
|
|
||||||
module.exports = function() {
|
module.exports = function() {
|
||||||
|
|
||||||
@ -57,6 +58,13 @@ module.exports = function() {
|
|||||||
argv.reject(err)
|
argv.reject(err)
|
||||||
})
|
})
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
|
|
||||||
|
if (err.error.cert) {
|
||||||
|
// TLS errors cause extremely verbose errors, truncate the certifiate details
|
||||||
|
// from the error output
|
||||||
|
delete err.error.cert
|
||||||
|
}
|
||||||
|
|
||||||
// One of the HTTP request pings to the cluster failed, log the error
|
// One of the HTTP request pings to the cluster failed, log the error
|
||||||
argv.reject(JSON.stringify(err.error, null, 4))
|
argv.reject(JSON.stringify(err.error, null, 4))
|
||||||
})
|
})
|
||||||
@ -181,6 +189,31 @@ module.exports = function() {
|
|||||||
return Promise.resolve(colors.green('OK'))
|
return Promise.resolve(colors.green('OK'))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
this.setTlsCerts = function(args) {
|
||||||
|
args.agentOptions = {}
|
||||||
|
if (this.argv['tls-key']) {
|
||||||
|
args.agentOptions.key = fs.readFileSync(this.argv['tls-key'])
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.argv['tls-cert']) {
|
||||||
|
args.agentOptions.cert = fs.readFileSync(this.argv['tls-cert'])
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.argv['tls-ca-cert']) {
|
||||||
|
args.agentOptions.ca = fs.readFileSync(this.argv['tls-ca-cert'])
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.argv['tls-passphrase']) {
|
||||||
|
args.agentOptions.passphrase = this.argv['tls-passphrase']
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.argv['tls-verify-server-cert']) {
|
||||||
|
args.agentOptions.checkServerIdentity = function() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Helper for executing requests and handling their responses, returns a
|
// Helper for executing requests and handling their responses, returns a
|
||||||
// promise that is fulfilled when all requests successfully complete. The
|
// promise that is fulfilled when all requests successfully complete. The
|
||||||
// promise is rejected if any of the requests fails.
|
// promise is rejected if any of the requests fails.
|
||||||
@ -189,6 +222,7 @@ module.exports = function() {
|
|||||||
args.uri = getUri(host, this.argv.secure, resource)
|
args.uri = getUri(host, this.argv.secure, resource)
|
||||||
args.json = true
|
args.json = true
|
||||||
args.timeout = this.argv.timeout
|
args.timeout = this.argv.timeout
|
||||||
|
setTlsCerts(args)
|
||||||
|
|
||||||
return request(args)
|
return request(args)
|
||||||
.then(function(res) {
|
.then(function(res) {
|
||||||
@ -275,7 +309,11 @@ function pingCluster(hosts) {
|
|||||||
var promises = []
|
var promises = []
|
||||||
|
|
||||||
hosts.forEach(function(i) {
|
hosts.forEach(function(i) {
|
||||||
promises.push(request(getUri(i, this.argv.secure, '')))
|
args = {}
|
||||||
|
args.uri = getUri(i, this.argv.secure, '')
|
||||||
|
args.json = true
|
||||||
|
setTlsCerts(args)
|
||||||
|
promises.push(request(args))
|
||||||
})
|
})
|
||||||
|
|
||||||
return Promise.all(promises)
|
return Promise.all(promises)
|
||||||
|
|||||||
@ -21,7 +21,7 @@ program
|
|||||||
.strict()
|
.strict()
|
||||||
.exitProcess(false)
|
.exitProcess(false)
|
||||||
.showHelpOnFail(false)
|
.showHelpOnFail(false)
|
||||||
.group(['u', 'p', 'h', 's', 't', 'q', 'tsv'], 'Global Options:')
|
.group(['u', 'p', 'h', 't', 'q', 'tsv'], 'Global Options:')
|
||||||
.option('u', {
|
.option('u', {
|
||||||
alias:'user',
|
alias:'user',
|
||||||
global: true,
|
global: true,
|
||||||
@ -42,27 +42,45 @@ program
|
|||||||
default: 'localhost:8989',
|
default: 'localhost:8989',
|
||||||
type: 'string'
|
type: 'string'
|
||||||
})
|
})
|
||||||
.option('s', {
|
|
||||||
alias: 'secure',
|
|
||||||
describe: 'Enable HTTPS requests',
|
|
||||||
default: 'false',
|
|
||||||
type: 'boolean'
|
|
||||||
})
|
|
||||||
.option('t', {
|
.option('t', {
|
||||||
alias: 'timeout',
|
alias: 'timeout',
|
||||||
describe: 'Request timeout in milliseconds',
|
describe: 'Request timeout in milliseconds',
|
||||||
default: '10000',
|
default: 10000,
|
||||||
type: 'number'
|
type: 'number'
|
||||||
})
|
})
|
||||||
.option('q', {
|
.option('q', {
|
||||||
alias: 'quiet',
|
alias: 'quiet',
|
||||||
describe: 'Silence all output',
|
describe: 'Silence all output',
|
||||||
default: 'false',
|
default: false,
|
||||||
type: 'boolean'
|
type: 'boolean'
|
||||||
})
|
})
|
||||||
.option('tsv', {
|
.option('tsv', {
|
||||||
describe: 'Print tab separated output',
|
describe: 'Print tab separated output',
|
||||||
default: 'false',
|
default: false,
|
||||||
|
type: 'boolean'
|
||||||
|
})
|
||||||
|
.group(['s', 'tls-key', 'tls-cert', 'tls-ca-cert', 'tls-verify-server-cert'], 'HTTPS/TLS Options:')
|
||||||
|
.option('s', {
|
||||||
|
alias: 'secure',
|
||||||
|
describe: 'Enable HTTPS requests',
|
||||||
|
default: false,
|
||||||
|
type: 'boolean'
|
||||||
|
})
|
||||||
|
.option('tls-key', {
|
||||||
|
describe: 'Path to TLS private key',
|
||||||
|
type: 'string'
|
||||||
|
})
|
||||||
|
.option('tls-cert', {
|
||||||
|
describe: 'Path to TLS public certificate',
|
||||||
|
type: 'string'
|
||||||
|
})
|
||||||
|
.option('tls-ca-cert', {
|
||||||
|
describe: 'Path to TLS CA certificate',
|
||||||
|
type: 'string'
|
||||||
|
})
|
||||||
|
.option('tls-verify-server-cert', {
|
||||||
|
describe: 'Whether to verify server TLS certificates',
|
||||||
|
default: true,
|
||||||
type: 'boolean'
|
type: 'boolean'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user