Skip to content

Commit

Permalink
Merge pull request #229 from github/mctofu/default-node-ca-cert
Browse files Browse the repository at this point in the history
Default to NODE_EXTRA_CA_CERTS config for proxy cert
  • Loading branch information
David McIntosh authored and GitHub committed Jul 26, 2022
2 parents 5086a77 + 509bd79 commit 8b0699b
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 9 deletions.
27 changes: 27 additions & 0 deletions __tests__/proxy-integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,33 @@ integration('ProxyBuilder', () => {
await proxy.shutdown()
})

jest.setTimeout(20000)
it('copies in the default node custom root CA if configured', async () => {
// make a tmp dir at the repo root unless it already exists
const tmpDir = path.join(__dirname, '../tmp')
if (!fs.existsSync(tmpDir)) {
fs.mkdirSync(tmpDir)
}
const certPath = path.join(__dirname, '../tmp/custom-cert.crt')
fs.writeFileSync(certPath, 'ca-pem-contents')
process.env.NODE_EXTRA_CA_CERTS = certPath

const proxy = await builder.run(jobId, credentials)
await proxy.container.start()

const id = proxy.container.id
const proc = spawnSync('docker', [
'exec',
id,
'cat',
'/usr/local/share/ca-certificates/custom-ca-cert.crt'
])
const stdout = proc.stdout.toString()
expect(stdout).toEqual('ca-pem-contents')

await proxy.shutdown()
})

jest.setTimeout(20000)
it('forwards custom proxy urls if configured', async () => {
const url = 'http://example.com'
Expand Down
14 changes: 10 additions & 4 deletions dist/main/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/main/index.js.map

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,11 @@ export class ProxyBuilder {
config
)

if (process.env.CUSTOM_CA_PATH) {
const customCAPath = this.customCAPath()
if (customCAPath) {
core.info('Detected custom CA certificate, adding to proxy')

const customCert = fs
.readFileSync(process.env.CUSTOM_CA_PATH, 'utf8')
.toString()
const customCert = fs.readFileSync(customCAPath, 'utf8').toString()
await ContainerService.storeCert(
CUSTOM_CA_CERT_NAME,
CA_CERT_INPUT_PATH,
Expand Down Expand Up @@ -224,4 +223,12 @@ export class ProxyBuilder {
core.info(`Created proxy container: ${container.id}`)
return container
}

private customCAPath(): string | undefined {
if ('CUSTOM_CA_PATH' in process.env) {
return process.env.CUSTOM_CA_PATH
}
// default to node.js configuration
return process.env.NODE_EXTRA_CA_CERTS
}
}

0 comments on commit 8b0699b

Please sign in to comment.