-
Notifications
You must be signed in to change notification settings - Fork 744
refactor(storage): make runner config store provider-neutral #5277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
edersonbrilhante
merged 5 commits into
main
from
refactor-runner-config-storage-provider
Sep 8, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3a1992a
refactor(storage): extract runner config store
edersonbrilhante 2bbceef
refactor(storage): make runner config store provider-neutral
edersonbrilhante 9710301
fix(compute-providers): format runner creation callback
edersonbrilhante 7d22ad9
fix(control-plane): keep storage selection tests in feature branch
edersonbrilhante 4329d4b
fix(deps): align Lambda workspace lockfile
edersonbrilhante File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| export {}; | ||
|
|
||
| declare global { | ||
| namespace NodeJS { | ||
| interface ProcessEnv { | ||
| SSM_PARAMETER_STORE_TAGS?: string; | ||
| SSM_TOKEN_PATH?: string; | ||
| } | ||
| } | ||
| } |
42 changes: 42 additions & 0 deletions
42
lambdas/libs/storage-providers/aws/ssm/parameter-store-tags.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| interface SsmParameterStoreTag { | ||
| Key: string; | ||
| Value: string; | ||
| } | ||
|
|
||
| export function loadSsmParameterStoreTagsFromEnvironment(): SsmParameterStoreTag[] { | ||
| return process.env.SSM_PARAMETER_STORE_TAGS && process.env.SSM_PARAMETER_STORE_TAGS.trim() !== '' | ||
| ? validateSsmParameterStoreTags(process.env.SSM_PARAMETER_STORE_TAGS) | ||
| : []; | ||
| } | ||
|
|
||
| function validateSsmParameterStoreTags(tagsJson: string): SsmParameterStoreTag[] { | ||
| try { | ||
| const tags: unknown = JSON.parse(tagsJson); | ||
|
|
||
| if (!Array.isArray(tags)) { | ||
| throw new Error('Tags must be an array'); | ||
| } | ||
|
|
||
| if (tags.length === 0) { | ||
| return []; | ||
| } | ||
|
|
||
| tags.forEach((tag: unknown, index: number) => { | ||
| if (typeof tag !== 'object' || tag === null) { | ||
| throw new Error(`Tag at index ${index} must be an object`); | ||
| } | ||
|
|
||
| const candidate = tag as Record<string, unknown>; | ||
| if (!candidate.Key || typeof candidate.Key !== 'string' || candidate.Key.trim() === '') { | ||
| throw new Error(`Tag at index ${index} has missing or invalid 'Key' property`); | ||
| } | ||
| if (!Object.prototype.hasOwnProperty.call(candidate, 'Value') || typeof candidate.Value !== 'string') { | ||
| throw new Error(`Tag at index ${index} has missing or invalid 'Value' property`); | ||
| } | ||
| }); | ||
|
|
||
| return tags as SsmParameterStoreTag[]; | ||
| } catch (error) { | ||
| throw new Error(`Failed to parse SSM_PARAMETER_STORE_TAGS: ${(error as Error).message}`); | ||
| } | ||
| } |
88 changes: 88 additions & 0 deletions
88
lambdas/libs/storage-providers/aws/ssm/runner-config-store.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| import { putParameter } from '@aws-github-runner/aws-ssm-util'; | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
|
|
||
| import { createAwsSsmRunnerConfigStore } from './runner-config-store'; | ||
|
|
||
| vi.mock('@aws-github-runner/aws-ssm-util', () => ({ | ||
| putParameter: vi.fn(), | ||
| })); | ||
|
|
||
| const putParameterMock = vi.mocked(putParameter); | ||
| const cleanEnv = process.env; | ||
|
|
||
| describe('aws_ssm runner config store', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| process.env = { ...cleanEnv }; | ||
| delete process.env.SSM_PARAMETER_STORE_TAGS; | ||
| process.env.SSM_TOKEN_PATH = '/runner/tokens'; | ||
| }); | ||
|
|
||
| it('creates a secure parameter at the legacy path with metadata tags before configured tags', async () => { | ||
| process.env.SSM_PARAMETER_STORE_TAGS = JSON.stringify([ | ||
| { Key: 'Environment', Value: 'test' }, | ||
| { Key: 'Team', Value: 'actions' }, | ||
| ]); | ||
| const store = createAwsSsmRunnerConfigStore(); | ||
|
|
||
| await store.create( | ||
| { runnerId: 'i-123', value: 'encoded-jit-config' }, | ||
| { metadata: [{ key: 'InstanceId', value: 'i-123' }] }, | ||
| ); | ||
|
|
||
| expect(store.maxWritesPerSecond).toBe(40); | ||
| expect(putParameterMock).toHaveBeenCalledWith('/runner/tokens/i-123', 'encoded-jit-config', true, { | ||
| tags: [ | ||
| { Key: 'InstanceId', Value: 'i-123' }, | ||
| { Key: 'Environment', Value: 'test' }, | ||
| { Key: 'Team', Value: 'actions' }, | ||
| ], | ||
| }); | ||
| }); | ||
|
|
||
| it('uses an empty tag list when no tags are configured', async () => { | ||
| const store = createAwsSsmRunnerConfigStore(); | ||
|
|
||
| await store.create({ runnerId: 'runner-1', value: 'registration-config' }); | ||
|
|
||
| expect(putParameterMock).toHaveBeenCalledWith('/runner/tokens/runner-1', 'registration-config', true, { | ||
| tags: [], | ||
| }); | ||
| }); | ||
|
|
||
| it.each([undefined, '', ' '])('rejects missing or blank SSM_TOKEN_PATH %j before writing', (tokenPath) => { | ||
| setTokenPath(tokenPath); | ||
|
|
||
| expect(() => createAwsSsmRunnerConfigStore()).toThrow('Environment variable SSM_TOKEN_PATH is not set'); | ||
| expect(putParameterMock).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it.each([ | ||
| ['{}', 'Tags must be an array'], | ||
| ['[null]', 'Tag at index 0 must be an object'], | ||
| [JSON.stringify([{ Key: '', Value: 'test' }]), "Tag at index 0 has missing or invalid 'Key' property"], | ||
| [JSON.stringify([{ Key: 'Environment' }]), "Tag at index 0 has missing or invalid 'Value' property"], | ||
| ])('rejects invalid legacy SSM parameter tags', (tags, reason) => { | ||
| process.env.SSM_PARAMETER_STORE_TAGS = tags; | ||
|
|
||
| expect(() => createAwsSsmRunnerConfigStore()).toThrow(`Failed to parse SSM_PARAMETER_STORE_TAGS: ${reason}`); | ||
| expect(putParameterMock).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('treats a blank legacy tag value as no configured tags', async () => { | ||
| process.env.SSM_PARAMETER_STORE_TAGS = ' '; | ||
| const store = createAwsSsmRunnerConfigStore(); | ||
|
|
||
| await store.create({ runnerId: 'runner-1', value: 'jit-config' }); | ||
|
|
||
| expect(putParameterMock).toHaveBeenCalledWith('/runner/tokens/runner-1', 'jit-config', true, { tags: [] }); | ||
| }); | ||
| }); | ||
|
|
||
| function setTokenPath(tokenPath: string | undefined): void { | ||
| if (tokenPath === undefined) { | ||
| delete process.env.SSM_TOKEN_PATH; | ||
| } else { | ||
| process.env.SSM_TOKEN_PATH = tokenPath; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.