Skip to content

Commit e22fe6e

Browse files
authored
runners: Add expiration policy to SSM parameters (#6885)
This adds an expiration policy to the SSM parameters for the runners. This is to ensure that the parameters are deleted after 30 minutes. Github Runner Tokens typically have a 1 hour expiration time, but our runners are typically expected to be up way quicker than that so 30 minutes is a good balance for when we expect the runners to be up. If a runner isn't conencted to Github by at least 30 minutes we will more than likely have spun it down and it will be deleted. This is an attempted re-land of 2 commits: * #6855 * #6858 --------- Signed-off-by: Eli Uriegas <[email protected]>
1 parent 6dd711f commit e22fe6e

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

terraform-aws-github-runner/modules/runners/lambdas/runners/src/scale-runners/runners.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,27 @@ describe('createRunner', () => {
12631263
Name: 'wg113-i-1234',
12641264
Value: 'us-east-1-BLAH',
12651265
Type: 'SecureString',
1266+
Policies: expect.any(String),
12661267
});
1268+
// Verify the Policies parameter contains the correct expiration policy structure
1269+
const putParameterCall = mockSSM.putParameter.mock.calls[0][0];
1270+
const policies = JSON.parse(putParameterCall.Policies);
1271+
expect(policies).toEqual([
1272+
{
1273+
Type: 'Expiration',
1274+
Version: '1.0',
1275+
Attributes: {
1276+
Timestamp: expect.any(String),
1277+
},
1278+
},
1279+
]);
1280+
1281+
// Verify the timestamp is approximately 30 minutes in the future
1282+
const expirationTime = new Date(policies[0].Attributes.Timestamp);
1283+
const now = Date.now();
1284+
const timeDiff = expirationTime.getTime() - now;
1285+
expect(timeDiff).toBeGreaterThan(25 * 60 * 1000); // at least 25 minutes (allowing for test execution time)
1286+
expect(timeDiff).toBeLessThan(35 * 60 * 1000); // at most 35 minutes (allowing for clock differences)
12671287
});
12681288

12691289
it('creates ssm experiment parameters when joining experiment', async () => {
@@ -1307,6 +1327,7 @@ describe('createRunner', () => {
13071327
Name: 'wg113-i-1234',
13081328
Value: 'us-east-1-BLAH #ON_AMI_EXPERIMENT',
13091329
Type: 'SecureString',
1330+
Policies: expect.any(String),
13101331
});
13111332
expect(mockEC2.runInstances).toBeCalledTimes(1);
13121333
expect(mockEC2.runInstances).toBeCalledWith(

terraform-aws-github-runner/modules/runners/lambdas/runners/src/scale-runners/runners.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,18 @@ async function addSSMParameterRunnerConfig(
392392
Name: parameterName,
393393
Value: runnerConfig,
394394
Type: 'SecureString',
395+
// NOTE: This does need to be an stringified JSON array of objects, check docs at:
396+
// https://docs.aws.amazon.com/systems-manager/latest/userguide/example_ssm_PutParameter_section.html
397+
Policies: JSON.stringify([
398+
{
399+
Type: 'Expiration',
400+
Version: '1.0',
401+
Attributes: {
402+
// Expire after 30 minutes from present time
403+
Timestamp: new Date(Date.now() + 1000 * 60 * 30).toISOString(),
404+
},
405+
},
406+
]),
395407
})
396408
.promise();
397409
return parameterName;

0 commit comments

Comments
 (0)