Skip to content

Commit 5397a65

Browse files
JamieMageehoneyankit
authored andcommitted
Pass OIDC environment variables to proxt
1 parent ddc330d commit 5397a65

4 files changed

Lines changed: 70 additions & 13 deletions

File tree

__tests__/proxy-integration.test.ts

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
import {spawnSync} from 'child_process'
12
import Docker from 'dockerode'
3+
import fs from 'fs'
4+
import path from 'path'
25
import {Credential} from '../src/api-client'
3-
import {ImageService} from '../src/image-service'
46
import {PROXY_IMAGE_NAME} from '../src/docker-tags'
7+
import {ImageService} from '../src/image-service'
58
import {ProxyBuilder} from '../src/proxy'
69
import {integration, removeDanglingUpdaterContainers} from './helpers'
7-
import {spawnSync} from 'child_process'
8-
import fs from 'fs'
9-
import path from 'path'
1010

1111
integration('ProxyBuilder', () => {
1212
const docker = new Docker()
@@ -182,4 +182,57 @@ integration('ProxyBuilder', () => {
182182
const output = proc.stdout.toString().trim()
183183
expect(output).toEqual(url)
184184
})
185+
186+
jest.setTimeout(20000)
187+
it('forwards OIDC token request URL if configured', async () => {
188+
const url =
189+
'https://vstoken.actions.githubusercontent.com/_apis/distributedtask/hubs/build/plans/123/jobs/456/oidctoken'
190+
process.env.ACTIONS_ID_TOKEN_REQUEST_URL = url
191+
192+
const proxy = await builder.run(
193+
jobId,
194+
jobToken,
195+
dependabotApiUrl,
196+
credentials
197+
)
198+
await proxy.container.start()
199+
200+
const id = proxy.container.id
201+
const proc = spawnSync('docker', [
202+
'exec',
203+
id,
204+
'printenv',
205+
'ACTIONS_ID_TOKEN_REQUEST_URL'
206+
])
207+
const output = proc.stdout.toString().trim()
208+
expect(output).toEqual(url)
209+
210+
await proxy.shutdown()
211+
})
212+
213+
jest.setTimeout(20000)
214+
it('forwards OIDC token request token if configured', async () => {
215+
const token = 'e30='
216+
process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN = token
217+
218+
const proxy = await builder.run(
219+
jobId,
220+
jobToken,
221+
dependabotApiUrl,
222+
credentials
223+
)
224+
await proxy.container.start()
225+
226+
const id = proxy.container.id
227+
const proc = spawnSync('docker', [
228+
'exec',
229+
id,
230+
'printenv',
231+
'ACTIONS_ID_TOKEN_REQUEST_TOKEN'
232+
])
233+
const output = proc.stdout.toString().trim()
234+
expect(output).toEqual(token)
235+
236+
await proxy.shutdown()
237+
})
185238
})

dist/main/index.js

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/main/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/proxy.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import fs from 'fs'
21
import * as core from '@actions/core'
32
import Docker, {Container, Network} from 'dockerode'
3+
import fs from 'fs'
4+
import {md, pki} from 'node-forge'
5+
import {Credential} from './api-client'
46
import {CertificateAuthority, ProxyConfig} from './config-types'
57
import {ContainerService} from './container-service'
6-
import {Credential} from './api-client'
7-
import {pki, md} from 'node-forge'
8-
import {outStream, errStream} from './utils'
8+
import {errStream, outStream} from './utils'
99

1010
const KEY_SIZE = 2048
1111
const KEY_EXPIRY_YEARS = 2
@@ -234,7 +234,9 @@ export class ProxyBuilder {
234234
`JOB_ID=${jobId}`,
235235
`JOB_TOKEN=${jobToken}`,
236236
`PROXY_CACHE=${this.cachedMode ? 'true' : 'false'}`,
237-
`DEPENDABOT_API_URL=${dependabotApiUrl}`
237+
`DEPENDABOT_API_URL=${dependabotApiUrl}`,
238+
`ACTIONS_ID_TOKEN_REQUEST_TOKEN=${process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN || ''}`,
239+
`ACTIONS_ID_TOKEN_REQUEST_URL=${process.env.ACTIONS_ID_TOKEN_REQUEST_URL || ''}`
238240
],
239241
Entrypoint: [
240242
'sh',

0 commit comments

Comments
 (0)