Skip to content

Commit c70e4b8

Browse files
committed
Support insecure-skip-tls-verify as config option
1 parent 039ed70 commit c70e4b8

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

src/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ export class KubeConfig {
253253
if (!user) {
254254
return;
255255
}
256+
257+
if (cluster != null && cluster.skipTLSVerify) {
258+
opts.rejectUnauthorized = false;
259+
}
256260
const ca = cluster != null ? bufferFromFileOrString(cluster.caFile, cluster.caData) : null;
257261
if (ca) {
258262
opts.ca = ca;

src/config_test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ describe('KubeConfig', () => {
194194
ca: new Buffer('CADATA2', 'utf-8'),
195195
cert: new Buffer('USER2_CADATA', 'utf-8'),
196196
key: new Buffer('USER2_CKDATA', 'utf-8'),
197+
rejectUnauthorized: false,
197198
});
198199
});
199200
});
@@ -592,6 +593,46 @@ describe('KubeConfig', () => {
592593
}
593594
});
594595

596+
it('should populate rejectUnauthorized=false when skipTLSVerify is set', () => {
597+
const config = new KubeConfig();
598+
const token = 'token';
599+
config.loadFromClusterAndUser(
600+
{ skipTLSVerify: true } as Cluster,
601+
{
602+
authProvider: {
603+
name: 'azure',
604+
config: {
605+
'access-token': token,
606+
},
607+
},
608+
} as User);
609+
const opts = {} as requestlib.Options;
610+
611+
config.applyToRequest(opts);
612+
expect(opts.rejectUnauthorized).to.equal(false);
613+
});
614+
615+
it('should not set rejectUnauthorized if skipTLSVerify is not set', () => {
616+
// This test is just making 100% sure we validate certs unless we explictly set
617+
// skipTLSVerify = true
618+
const config = new KubeConfig();
619+
const token = 'token';
620+
config.loadFromClusterAndUser(
621+
{ } as Cluster,
622+
{
623+
authProvider: {
624+
name: 'azure',
625+
config: {
626+
'access-token': token,
627+
},
628+
},
629+
} as User);
630+
const opts = {} as requestlib.Options;
631+
632+
config.applyToRequest(opts);
633+
expect(opts.rejectUnauthorized).to.equal(undefined);
634+
});
635+
595636
it('should throw with expired token and no cmd', () => {
596637
const config = new KubeConfig();
597638
config.loadFromClusterAndUser(

src/web-socket-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export class WebSocketHandler implements WebSocketInterface {
105105
const uri = `${proto}://${target}${path}`;
106106

107107
const opts: WebSocket.ClientOptions = {};
108-
// TODO: This doesn't set insecureSSL if skipTLSVerify is set...
108+
109109
this.config.applytoHTTPSOptions(opts);
110110

111111
return new Promise((resolve, reject) => {

0 commit comments

Comments
 (0)