@@ -90,6 +90,37 @@ function generateRunnerServiceConfig(githubRunnerConfig: CreateGitHubRunnerConfi
9090 return config ;
9191}
9292
93+ export function validateSsmParameterStoreTags ( tagsJson : string ) : { Key : string ; Value : string } [ ] {
94+ try {
95+ const tags = JSON . parse ( tagsJson ) ;
96+
97+ if ( ! Array . isArray ( tags ) ) {
98+ throw new Error ( 'Tags must be an array' ) ;
99+ }
100+
101+ if ( tags . length === 0 ) {
102+ return [ ] ;
103+ }
104+
105+ tags . forEach ( ( tag , index ) => {
106+ if ( typeof tag !== 'object' || tag === null ) {
107+ throw new Error ( `Tag at index ${ index } must be an object` ) ;
108+ }
109+ if ( ! tag . Key || typeof tag . Key !== 'string' || tag . Key . trim ( ) === '' ) {
110+ throw new Error ( `Tag at index ${ index } has missing or invalid 'Key' property` ) ;
111+ }
112+ if ( ! tag . Value || typeof tag . Value !== 'string' || tag . Value . trim ( ) === '' ) {
113+ throw new Error ( `Tag at index ${ index } has missing or invalid 'Value' property` ) ;
114+ }
115+ } ) ;
116+
117+ return tags ;
118+ } catch ( err ) {
119+ logger . error ( 'Invalid SSM_PARAMETER_STORE_TAGS format' , { error : err } ) ;
120+ throw new Error ( `Failed to parse SSM_PARAMETER_STORE_TAGS: ${ ( err as Error ) . message } ` ) ;
121+ }
122+ }
123+
93124async function getGithubRunnerRegistrationToken ( githubRunnerConfig : CreateGitHubRunnerConfig , ghClient : Octokit ) {
94125 const registrationToken =
95126 githubRunnerConfig . runnerType === 'Org'
@@ -261,7 +292,7 @@ export async function scaleUp(payloads: ActionRequestMessageSQS[]): Promise<stri
261292 : [ ] ;
262293 const ssmParameterStoreTags : { Key : string ; Value : string } [ ] =
263294 process . env . SSM_PARAMETER_STORE_TAGS && process . env . SSM_PARAMETER_STORE_TAGS . trim ( ) !== ''
264- ? JSON . parse ( process . env . SSM_PARAMETER_STORE_TAGS )
295+ ? validateSsmParameterStoreTags ( process . env . SSM_PARAMETER_STORE_TAGS )
265296 : [ ] ;
266297
267298 const { ghesApiUrl, ghesBaseUrl } = getGitHubEnterpriseApiUrl ( ) ;
0 commit comments