Merge pull request #2531 from doubles-ss/master

Feat: Add mtls authen option to http
pull/2927/head
Louis Lam 2 years ago committed by GitHub
commit 09fa60de55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,13 @@
-- You should not modify if this have pushed to Github, unless it does serious wrong with the db.
BEGIN TRANSACTION;
ALTER TABLE monitor
ADD tls_ca TEXT default null;
ALTER TABLE monitor
ADD tls_cert TEXT default null;
ALTER TABLE monitor
ADD tls_key TEXT default null;
COMMIT;

46
package-lock.json generated

@ -10,7 +10,7 @@
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@grpc/grpc-js": "~1.7.3", "@grpc/grpc-js": "~1.7.3",
"@louislam/ping": "~0.4.2-mod.2", "@louislam/ping": "~0.4.4-mod.0",
"@louislam/sqlite3": "15.1.2", "@louislam/sqlite3": "15.1.2",
"args-parser": "~1.3.0", "args-parser": "~1.3.0",
"axios": "~0.27.0", "axios": "~0.27.0",
@ -4213,13 +4213,11 @@
"integrity": "sha512-retLUN4TwCJ0QJDi9OCJwYVaXAz93NeOkEtEQL98M2bykBOxmURlP0YlfsuE46kItOOVZIWRYC3KsSLhQ1R2Qw==" "integrity": "sha512-retLUN4TwCJ0QJDi9OCJwYVaXAz93NeOkEtEQL98M2bykBOxmURlP0YlfsuE46kItOOVZIWRYC3KsSLhQ1R2Qw=="
}, },
"node_modules/@louislam/ping": { "node_modules/@louislam/ping": {
"version": "0.4.2-mod.2", "version": "0.4.4-mod.0",
"resolved": "https://registry.npmjs.org/@louislam/ping/-/ping-0.4.2-mod.2.tgz", "resolved": "https://registry.npmjs.org/@louislam/ping/-/ping-0.4.4-mod.0.tgz",
"integrity": "sha512-4krrRGohYdhQOD+Mt0Q8e1Z05DEKntZ7TgiY1jYaqWrMz0H2XJyRh+mLPOUVPL5zSymiHsZiK2ZACXtp/d9Wxg==", "integrity": "sha512-U2ZXcgFRPmZYd/ooA8KILG4aCMBsDrGP9NDWseHriZSsKlu5Y1lf/LbenN6tnqQ9JjAsbJjqwSi3xtAcWqU+1w==",
"dependencies": { "dependencies": {
"command-exists": "~1.2.9", "command-exists": "~1.2.9"
"q": "1.x",
"underscore": "^1.12.0"
}, },
"engines": { "engines": {
"node": ">=4.0.0" "node": ">=4.0.0"
@ -15570,15 +15568,6 @@
"node": ">=6" "node": ">=6"
} }
}, },
"node_modules/q": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/q/-/q-1.5.1.tgz",
"integrity": "sha512-kV/CThkXo6xyFEZUugw/+pIOywXcDbFYgSct5cT3gqlbkBE1SJdwy6UQoZvodiWF/ckQLZyDE/Bu1M6gVu5lVw==",
"engines": {
"node": ">=0.6.0",
"teleport": ">=0.2.0"
}
},
"node_modules/qlobber": { "node_modules/qlobber": {
"version": "5.0.3", "version": "5.0.3",
"resolved": "https://registry.npmjs.org/qlobber/-/qlobber-5.0.3.tgz", "resolved": "https://registry.npmjs.org/qlobber/-/qlobber-5.0.3.tgz",
@ -17977,11 +17966,6 @@
"url": "https://github.com/sponsors/ljharb" "url": "https://github.com/sponsors/ljharb"
} }
}, },
"node_modules/underscore": {
"version": "1.13.6",
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.6.tgz",
"integrity": "sha512-+A5Sja4HP1M08MaXya7p5LvjuM7K6q/2EaC0+iovj/wOcMsTzMvDFbasi/oSapiwOlt252IqsKqPjCl7huKS0A=="
},
"node_modules/unicode-canonical-property-names-ecmascript": { "node_modules/unicode-canonical-property-names-ecmascript": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-2.0.0.tgz", "resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-2.0.0.tgz",
@ -22231,13 +22215,11 @@
"integrity": "sha512-retLUN4TwCJ0QJDi9OCJwYVaXAz93NeOkEtEQL98M2bykBOxmURlP0YlfsuE46kItOOVZIWRYC3KsSLhQ1R2Qw==" "integrity": "sha512-retLUN4TwCJ0QJDi9OCJwYVaXAz93NeOkEtEQL98M2bykBOxmURlP0YlfsuE46kItOOVZIWRYC3KsSLhQ1R2Qw=="
}, },
"@louislam/ping": { "@louislam/ping": {
"version": "0.4.2-mod.2", "version": "0.4.4-mod.0",
"resolved": "https://registry.npmjs.org/@louislam/ping/-/ping-0.4.2-mod.2.tgz", "resolved": "https://registry.npmjs.org/@louislam/ping/-/ping-0.4.4-mod.0.tgz",
"integrity": "sha512-4krrRGohYdhQOD+Mt0Q8e1Z05DEKntZ7TgiY1jYaqWrMz0H2XJyRh+mLPOUVPL5zSymiHsZiK2ZACXtp/d9Wxg==", "integrity": "sha512-U2ZXcgFRPmZYd/ooA8KILG4aCMBsDrGP9NDWseHriZSsKlu5Y1lf/LbenN6tnqQ9JjAsbJjqwSi3xtAcWqU+1w==",
"requires": { "requires": {
"command-exists": "~1.2.9", "command-exists": "~1.2.9"
"q": "1.x",
"underscore": "^1.12.0"
} }
}, },
"@louislam/sqlite3": { "@louislam/sqlite3": {
@ -30817,11 +30799,6 @@
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.0.tgz", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.0.tgz",
"integrity": "sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA==" "integrity": "sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA=="
}, },
"q": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/q/-/q-1.5.1.tgz",
"integrity": "sha512-kV/CThkXo6xyFEZUugw/+pIOywXcDbFYgSct5cT3gqlbkBE1SJdwy6UQoZvodiWF/ckQLZyDE/Bu1M6gVu5lVw=="
},
"qlobber": { "qlobber": {
"version": "5.0.3", "version": "5.0.3",
"resolved": "https://registry.npmjs.org/qlobber/-/qlobber-5.0.3.tgz", "resolved": "https://registry.npmjs.org/qlobber/-/qlobber-5.0.3.tgz",
@ -32679,11 +32656,6 @@
"which-boxed-primitive": "^1.0.2" "which-boxed-primitive": "^1.0.2"
} }
}, },
"underscore": {
"version": "1.13.6",
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.6.tgz",
"integrity": "sha512-+A5Sja4HP1M08MaXya7p5LvjuM7K6q/2EaC0+iovj/wOcMsTzMvDFbasi/oSapiwOlt252IqsKqPjCl7huKS0A=="
},
"unicode-canonical-property-names-ecmascript": { "unicode-canonical-property-names-ecmascript": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-2.0.0.tgz", "resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-2.0.0.tgz",

@ -69,7 +69,7 @@
}, },
"dependencies": { "dependencies": {
"@grpc/grpc-js": "~1.7.3", "@grpc/grpc-js": "~1.7.3",
"@louislam/ping": "~0.4.2-mod.2", "@louislam/ping": "~0.4.4-mod.0",
"@louislam/sqlite3": "15.1.2", "@louislam/sqlite3": "15.1.2",
"args-parser": "~1.3.0", "args-parser": "~1.3.0",
"axios": "~0.27.0", "axios": "~0.27.0",

@ -73,6 +73,7 @@ class Database {
"patch-http-body-encoding.sql": true, "patch-http-body-encoding.sql": true,
"patch-add-description-monitor.sql": true, "patch-add-description-monitor.sql": true,
"patch-api-key-table.sql": true, "patch-api-key-table.sql": true,
"patch-monitor-tls.sql": true,
}; };
/** /**

@ -133,6 +133,9 @@ class Monitor extends BeanModel {
mqttPassword: this.mqttPassword, mqttPassword: this.mqttPassword,
authWorkstation: this.authWorkstation, authWorkstation: this.authWorkstation,
authDomain: this.authDomain, authDomain: this.authDomain,
tlsCa: this.tlsCa,
tlsCert: this.tlsCert,
tlsKey: this.tlsKey,
}; };
} }
@ -331,6 +334,18 @@ class Monitor extends BeanModel {
options.httpsAgent = new https.Agent(httpsAgentOptions); options.httpsAgent = new https.Agent(httpsAgentOptions);
} }
if (this.auth_method === "mtls") {
if (this.tlsCert !== null && this.tlsCert !== "") {
options.httpsAgent.options.cert = Buffer.from(this.tlsCert);
}
if (this.tlsCa !== null && this.tlsCa !== "") {
options.httpsAgent.options.ca = Buffer.from(this.tlsCa);
}
if (this.tlsKey !== null && this.tlsKey !== "") {
options.httpsAgent.options.key = Buffer.from(this.tlsKey);
}
}
log.debug("monitor", `[${this.name}] Axios Options: ${JSON.stringify(options)}`); log.debug("monitor", `[${this.name}] Axios Options: ${JSON.stringify(options)}`);
log.debug("monitor", `[${this.name}] Axios Request`); log.debug("monitor", `[${this.name}] Axios Request`);
@ -836,7 +851,6 @@ class Monitor extends BeanModel {
domain: this.authDomain, domain: this.authDomain,
workstation: this.authWorkstation ? this.authWorkstation : undefined workstation: this.authWorkstation ? this.authWorkstation : undefined
}); });
} else { } else {
res = await axios.request(options); res = await axios.request(options);
} }

@ -688,6 +688,9 @@ let needSetup = false;
bean.headers = monitor.headers; bean.headers = monitor.headers;
bean.basic_auth_user = monitor.basic_auth_user; bean.basic_auth_user = monitor.basic_auth_user;
bean.basic_auth_pass = monitor.basic_auth_pass; bean.basic_auth_pass = monitor.basic_auth_pass;
bean.tlsCa = monitor.tlsCa;
bean.tlsCert = monitor.tlsCert;
bean.tlsKey = monitor.tlsKey;
bean.interval = monitor.interval; bean.interval = monitor.interval;
bean.retryInterval = monitor.retryInterval; bean.retryInterval = monitor.retryInterval;
bean.resendInterval = monitor.resendInterval; bean.resendInterval = monitor.resendInterval;

@ -546,31 +546,50 @@
<option value="ntlm"> <option value="ntlm">
NTLM NTLM
</option> </option>
<option value="mtls">
mTLS
</option>
</select> </select>
</div> </div>
<template v-if="monitor.authMethod && monitor.authMethod !== null "> <template v-if="monitor.authMethod && monitor.authMethod !== null ">
<template v-if="monitor.authMethod === 'mtls' ">
<div class="my-3">
<label for="tls-cert" class="form-label">{{ $t("Cert") }}</label>
<textarea id="tls-cert" v-model="monitor.tlsCert" class="form-control" :placeholder="$t('Cert body')" required></textarea>
</div>
<div class="my-3">
<label for="tls-key" class="form-label">{{ $t("Key") }}</label>
<textarea id="tls-key" v-model="monitor.tlsKey" class="form-control" :placeholder="$t('Key body')" required></textarea>
</div>
<div class="my-3"> <div class="my-3">
<label for="basicauth" class="form-label">{{ $t("Username") }}</label> <label for="tls-ca" class="form-label">{{ $t("CA") }}</label>
<textarea id="tls-ca" v-model="monitor.tlsCa" class="form-control" :placeholder="$t('Server CA')"></textarea>
</div>
</template>
<template v-else>
<div class="my-3">
<label for="basicauth-user" class="form-label">{{ $t("Username") }}</label>
<input id="basicauth-user" v-model="monitor.basic_auth_user" type="text" class="form-control" :placeholder="$t('Username')"> <input id="basicauth-user" v-model="monitor.basic_auth_user" type="text" class="form-control" :placeholder="$t('Username')">
</div> </div>
<div class="my-3"> <div class="my-3">
<label for="basicauth" class="form-label">{{ $t("Password") }}</label> <label for="basicauth-pass" class="form-label">{{ $t("Password") }}</label>
<input id="basicauth-pass" v-model="monitor.basic_auth_pass" type="password" autocomplete="new-password" class="form-control" :placeholder="$t('Password')"> <input id="basicauth-pass" v-model="monitor.basic_auth_pass" type="password" autocomplete="new-password" class="form-control" :placeholder="$t('Password')">
</div> </div>
<template v-if="monitor.authMethod === 'ntlm' "> <template v-if="monitor.authMethod === 'ntlm' ">
<div class="my-3"> <div class="my-3">
<label for="basicauth" class="form-label">{{ $t("Domain") }}</label> <label for="ntlm-domain" class="form-label">{{ $t("Domain") }}</label>
<input id="basicauth-domain" v-model="monitor.authDomain" type="text" class="form-control" :placeholder="$t('Domain')"> <input id="ntlm-domain" v-model="monitor.authDomain" type="text" class="form-control" :placeholder="$t('Domain')">
</div> </div>
<div class="my-3"> <div class="my-3">
<label for="basicauth" class="form-label">{{ $t("Workstation") }}</label> <label for="ntlm-workstation" class="form-label">{{ $t("Workstation") }}</label>
<input id="basicauth-workstation" v-model="monitor.authWorkstation" type="text" class="form-control" :placeholder="$t('Workstation')"> <input id="ntlm-workstation" v-model="monitor.authWorkstation" type="text" class="form-control" :placeholder="$t('Workstation')">
</div> </div>
</template> </template>
</template> </template>
</template> </template>
</template>
<!-- gRPC Options --> <!-- gRPC Options -->
<template v-if="monitor.type === 'grpc-keyword' "> <template v-if="monitor.type === 'grpc-keyword' ">

Loading…
Cancel
Save