Skip to content

Commit b84949b

Browse files
committed
Pass OIDC environment variables to proxt
1 parent ddc330d commit b84949b

2 files changed

Lines changed: 55 additions & 11 deletions

File tree

__tests__/proxy-integration.test.ts

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

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

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)