Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from 'node:fs';
import https from 'node:https';
import http from 'node:http';
import yaml from 'js-yaml';
import net from 'node:net';
import path from 'node:path';
Expand Down Expand Up @@ -544,6 +545,8 @@ export class KubeConfig implements SecurityAuthentication {
} else {
throw new Error('Unsupported proxy type');
}
} else if (cluster?.server?.startsWith('http:')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also check for skipTlsVerify being true before we allow http URLs? It's really not secure to do this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed a commit to check for skipTlsVerify as well and added a test for this.
I agree that it's not secure but I think the library should allow this as it is possible to do. 🤔

agent = new http.Agent(agentOptions);
} else {
agent = new https.Agent(agentOptions);
}
Expand Down
25 changes: 25 additions & 0 deletions src/config_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { deepEqual, deepStrictEqual, notStrictEqual, rejects, strictEqual, throw
import child_process from 'node:child_process';
import { readFileSync } from 'node:fs';
import https from 'node:https';
import http from 'node:http';
import { Agent, RequestOptions } from 'node:https';
import path, { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
Expand Down Expand Up @@ -448,6 +449,30 @@ describe('KubeConfig', () => {
message: 'Unsupported proxy type',
});
});
it('should apply http agent if cluster.server starts with http and no proxy-url is provided', async () => {
const kc = new KubeConfig();
kc.loadFromFile(kcProxyUrl);
kc.setCurrentContext('contextE');

const testServerName = 'http://example.com';
const rc = new RequestContext(testServerName, HttpMethod.GET);

await kc.applySecurityAuthentication(rc);

strictEqual(rc.getAgent() instanceof http.Agent, true);
});
it('should apply https agent if cluster.server starts with https and no proxy-url is provided', async () => {
const kc = new KubeConfig();
kc.loadFromFile(kcProxyUrl);
kc.setCurrentContext('contextF');

const testServerName = 'https://example.com';
const rc = new RequestContext(testServerName, HttpMethod.GET);

await kc.applySecurityAuthentication(rc);

strictEqual(rc.getAgent() instanceof https.Agent, true);
});
});

describe('loadClusterConfigObjects', () => {
Expand Down