@@ -2,7 +2,7 @@ import * as core from '@actions/core'
22import * as github from '@actions/github'
33import * as httpClient from '@actions/http-client'
44import { Context } from '@actions/github/lib/context'
5- import { ApiClient , CredentialFetchingError } from './api-client'
5+ import { ApiClient , Credential , CredentialFetchingError } from './api-client'
66import { getJobParameters } from './inputs'
77import { ImageService , MetricReporter } from './image-service'
88import { updaterImageName , PROXY_IMAGE_NAME } from './docker-tags'
@@ -89,7 +89,11 @@ export async function run(context: Context): Promise<void> {
8989 }
9090
9191 try {
92- const credentials = await apiClient . getCredentials ( )
92+ const credentials = ( await apiClient . getCredentials ( ) ) || [ ]
93+ const registryCredentials = credentialsFromEnv ( )
94+
95+ credentials . push ( ...registryCredentials )
96+
9397 const updater = new Updater (
9498 updaterImage ,
9599 PROXY_IMAGE_NAME ,
@@ -215,4 +219,38 @@ function dependabotJobUrl(id: number): string {
215219 return url_parts . filter ( Boolean ) . join ( '/' )
216220}
217221
222+ export function credentialsFromEnv ( ) : Credential [ ] {
223+ const registriesProxyStr = process . env . GITHUB_REGISTRIES_PROXY
224+ let credentialsStr : string
225+ if ( registriesProxyStr !== undefined ) {
226+ credentialsStr = Buffer . from ( registriesProxyStr , 'base64' ) . toString ( )
227+ } else {
228+ return [ ]
229+ }
230+
231+ let parsed : Credential [ ]
232+
233+ try {
234+ parsed = JSON . parse ( credentialsStr ) as Credential [ ]
235+ } catch {
236+ // Don't log the error as it may contain sensitive information
237+ parsed = [ ]
238+ botSay ( 'Failed to parse GITHUB_REGISTRIES_PROXY environment variable' )
239+ }
240+
241+ const nonSecrets = [ 'url' , 'username' , 'host' , 'replaces-base' ]
242+ for ( const e of parsed ) {
243+ // Mask credentials to reduce chance of accidental leakage in logs.
244+ for ( const key of Object . keys ( e ) ) {
245+ if ( ! nonSecrets . includes ( key ) ) {
246+ core . setSecret ( ( e as Record < string , unknown > ) [ key ] as string )
247+ }
248+ }
249+
250+ // TODO: Filter down to only credentials relevant to this job.
251+ }
252+
253+ return parsed
254+ }
255+
218256run ( github . context )
0 commit comments