Skip to content

Commit

Permalink
feat: add options to host rules to enable mTLS calls to host
Browse files Browse the repository at this point in the history
  • Loading branch information
lyonlai committed Aug 30, 2023
1 parent 685c4ca commit 930bfd3
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/config/options/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2348,6 +2348,36 @@ const options: RenovateOptions[] = [
cli: false,
env: false,
},
{
name: 'certificateAuthority',
description: 'The overriding trusted CA certificate',
type: 'string',
stage: 'repository',
parent: 'hostRules',
default: null,
cli: false,
env: false,
},
{
name: 'privateKey',
description: 'The private key in PEM format',
type: 'string',
stage: 'repository',
parent: 'hostRules',
default: null,
cli: false,
env: false,
},
{
name: 'certificate',
description: 'The certificate chains in PEM format',
type: 'string',
stage: 'repository',
parent: 'hostRules',
default: null,
cli: false,
env: false,
},
{
name: 'cacheHardTtlMinutes',
description:
Expand Down
3 changes: 3 additions & 0 deletions lib/types/host-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export interface HostRuleSearchResult {
dnsCache?: boolean;
keepalive?: boolean;
artifactAuth?: string[] | null;
certificateAuthority?: string;
privateKey?: string;
certificate?: string;
}

export interface HostRule extends HostRuleSearchResult {
Expand Down
26 changes: 26 additions & 0 deletions lib/util/http/host-rules.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ describe('util/http/host-rules', () => {
hostType: 'bitbucket',
token: 'cdef',
});

hostRules.add({
hostType: 'maven',
matchHost: 'https://custom.datasource',
certificateAuthority: 'ca-cert',
certificate: 'cert',
privateKey: 'key',
});
});

afterEach(() => {
Expand Down Expand Up @@ -148,6 +156,24 @@ describe('util/http/host-rules', () => {
`);
});

it('https', () => {
expect(
applyHostRules('https://custom.datasource/data/path', {
...options,
hostType: 'maven',
})
).toMatchInlineSnapshot(`
{
"hostType": "maven",
"https": {
"certificate": "cert",
"certificateAuthority": "ca-cert",
"key": "key",
},
}
`);
});

it('no fallback to github', () => {
hostRules.add({
hostType: 'github-tags',
Expand Down
13 changes: 13 additions & 0 deletions lib/util/http/host-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export type HostRulesGotOptions = Pick<
| 'lookup'
| 'agent'
| 'http2'
| 'https'
>;

export function findMatchingRules<GotOptions extends HostRulesGotOptions>(
Expand Down Expand Up @@ -162,6 +163,18 @@ export function applyHostRules<GotOptions extends HostRulesGotOptions>(
if (!hasProxy() && foundRules.enableHttp2 === true) {
options.http2 = true;
}

if (
foundRules.certificateAuthority !== null ||
foundRules.privateKey !== null ||
foundRules.certificate !== null
) {
options.https = {
certificateAuthority: foundRules.certificateAuthority,
key: foundRules.privateKey,
certificate: foundRules.certificate,
};
}
return options;
}

Expand Down

0 comments on commit 930bfd3

Please sign in to comment.