Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ describe('EC2 scale-set provider configuration', () => {
expect(parseEc2ScaleSetProviderConfig({ ...config, runnerNamePrefix: 'r'.repeat(45) })).toMatchObject({
runnerNamePrefix: 'r'.repeat(45),
});
expect(parseEc2ScaleSetProviderConfig(config).jitConfigTTLSeconds).toBeUndefined();
expect(parseEc2ScaleSetProviderConfig({ ...config, jitConfigTTLSeconds: 3600 })).toMatchObject({
jitConfigTTLSeconds: 3600,
});
});

it.each([
Expand All @@ -22,6 +26,10 @@ describe('EC2 scale-set provider configuration', () => {
[{ ...config, ssmParameterTags: [{ Key: 'aws:owner', Value: 'untrusted' }] }],
[{ ...config, runnerNamePrefix: 'r'.repeat(46) }],
[{ ...config, bootTimeoutMinutes: 10 }],
[{ ...config, jitConfigTTLSeconds: 0 }],
[{ ...config, jitConfigTTLSeconds: -1 }],
[{ ...config, jitConfigTTLSeconds: Number.NaN }],
[{ ...config, jitConfigTTLSeconds: '3600' }],
])('rejects invalid or unsupported values instead of forwarding them to AWS', (invalid) => {
expect(() => parseEc2ScaleSetProviderConfig(invalid)).toThrow();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface Ec2ScaleSetProviderConfig {
environment: string;
runnerNamePrefix: string;
jitConfigParameterPath: string;
jitConfigTTLSeconds?: number;
subnets: string[];
launchTemplateName: string;
ec2instanceCriteria: RunnerInputParameters['ec2instanceCriteria'];
Expand Down Expand Up @@ -72,6 +73,14 @@ function optionalBoolean(value: unknown, name: string): boolean | undefined {
return value;
}

function optionalPositiveNumber(value: unknown, name: string): number | undefined {
if (value === undefined) return undefined;
if (typeof value !== 'number' || !Number.isFinite(value) || value <= 0) {
throw new Ec2ScaleSetValidationError(`Invalid EC2 scale-set configuration field '${name}'`);
}
return value;
}

function requireStringArray(
value: unknown,
name: string,
Expand Down Expand Up @@ -213,6 +222,7 @@ export function parseEc2ScaleSetProviderConfig(value: unknown): Ec2ScaleSetProvi
'environment',
'runnerNamePrefix',
'jitConfigParameterPath',
'jitConfigTTLSeconds',
'subnets',
'launchTemplateName',
'ec2instanceCriteria',
Expand Down Expand Up @@ -271,6 +281,7 @@ export function parseEc2ScaleSetProviderConfig(value: unknown): Ec2ScaleSetProvi
environment: requireString(value.environment, 'environment', /^[A-Za-z0-9][A-Za-z0-9._-]*$/, 128),
runnerNamePrefix: requirePossiblyEmptyString(value.runnerNamePrefix, 'runnerNamePrefix', /^[A-Za-z0-9._-]*$/, 45),
jitConfigParameterPath,
jitConfigTTLSeconds: optionalPositiveNumber(value.jitConfigTTLSeconds, 'jitConfigTTLSeconds'),
subnets: requireStringArray(value.subnets, 'subnets', /^subnet-[0-9a-f]+$/, 32),
launchTemplateName: requireString(value.launchTemplateName, 'launchTemplateName', /^[A-Za-z0-9()./_-]+$/, 128),
ec2instanceCriteria: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,45 @@ describe('EC2 scale-set scale up', () => {
});
});

it('publishes the JIT configuration on the Standard tier without a policy when no TTL is configured', async () => {
const instanceId = 'i-1234567890abcdef0';
ec2Mock.on(DescribeInstancesCommand).resolves({});
ec2Mock.on(CreateFleetCommand).resolves({ Instances: [{ InstanceIds: [instanceId] }] });

await createTestProvider().reconcile(createRequest());

expect(ssmMock).toHaveReceivedCommandWith(PutParameterCommand, { Tier: 'Standard', Policies: undefined });
});

it('publishes the JIT configuration on the Advanced tier with an expiration policy when a TTL is configured', async () => {
const instanceId = 'i-1234567890abcdef0';
const now = new Date('2026-01-01T00:00:00.000Z');
vi.useFakeTimers({ now, toFake: ['Date'] });
try {
ec2Mock.on(DescribeInstancesCommand).resolves({});
ec2Mock.on(CreateFleetCommand).resolves({ Instances: [{ InstanceIds: [instanceId] }] });

const result = await createTestProvider({
configuration: { ...config, jitConfigTTLSeconds: 3600 },
}).reconcile(createRequest());

expect(result.actions.launched).toBe(1);
expect(ssmMock).toHaveReceivedCommandWith(PutParameterCommand, {
Name: `${config.jitConfigParameterPath}/${instanceId}`,
Tier: 'Advanced',
Policies: JSON.stringify([
{
Type: 'Expiration',
Version: '1.0',
Attributes: { Timestamp: '2026-01-01T01:00:00.000Z' },
},
]),
});
} finally {
vi.useRealTimers();
}
});

it('resolves an AMI parameter through the provider-owned SSM client', async () => {
const instanceId = 'i-1234567890abcdef0';
const amiIdSsmParameterName = '/github-action-runners/unit-test/ami';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,29 @@ async function publishJitConfiguration(
throw new Ec2ScaleSetValidationError('JIT configuration must be between 1 and 8192 bytes');
}

// Parameter policies (e.g. Expiration) are only supported on the Advanced
// tier, so a TTL forces the tier regardless of the value size. Expiration is
// enforced asynchronously by SSM and only cleans up parameters left behind by
// instances that never read their JIT configuration.
const ttlSeconds = input.configuration.jitConfigTTLSeconds;
await ssmClient.send(
new PutParameterCommand({
Name: jitParameterName(input.configuration, instanceId),
Value: encodedJitConfiguration,
Type: 'SecureString',
KeyId: input.configuration.ssmKmsKeyId,
Overwrite: false,
Tier: valueSize >= SSM_STANDARD_TIER_THRESHOLD ? 'Advanced' : 'Standard',
Tier: ttlSeconds !== undefined || valueSize >= SSM_STANDARD_TIER_THRESHOLD ? 'Advanced' : 'Standard',
Policies:
ttlSeconds === undefined
? undefined
: JSON.stringify([
{
Type: 'Expiration',
Version: '1.0',
Attributes: { Timestamp: new Date(Date.now() + ttlSeconds * 1000).toISOString() },
},
]),
Tags: jitParameterTags(input, instanceId),
}),
{ abortSignal: signal },
Expand Down
3 changes: 3 additions & 0 deletions modules/compute-providers/aws/ec2/scale-set.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ locals {
local.ami_id_ssm_external ? {
amiIdSsmParameterName = local.ami_id_ssm_parameter_name
} : {},
var.storage_provider.aws.ssm.ttl_seconds.tokens == null ? {} : {
jitConfigTTLSeconds = var.storage_provider.aws.ssm.ttl_seconds.tokens
},
)

scale_set_owned_instance_conditions = [
Expand Down
4 changes: 4 additions & 0 deletions modules/compute-providers/aws/ec2/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ variable "storage_provider" {
- `aws.ssm.paths.root`: Root Parameter Store path for the runner configuration.
- `aws.ssm.paths.tokens`: Path segment used for registration tokens and just-in-time configuration.
- `aws.ssm.paths.config`: Path segment used for persistent runner and provider configuration.
- `aws.ssm.ttl_seconds.tokens`: Optional TTL in seconds for scale-set just-in-time configuration parameters. When set, the parameters use the Advanced tier with an SSM expiration policy.
- `aws.ssm.tags`: Shared SSM tags that override module-level `tags`.
- `aws.ssm.parameters.tags`: Parameter-specific tags that override module-level and shared SSM tags.
EOT
Expand All @@ -375,6 +376,9 @@ variable "storage_provider" {
tokens = string
config = string
})
ttl_seconds = optional(object({
tokens = optional(number, null)
}), {})
tags = optional(map(string), {})
parameters = optional(object({
tags = optional(map(string), {})
Expand Down
5 changes: 5 additions & 0 deletions modules/multi-runner/tests/config-translation.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,11 @@ run "non_empty_v2_map_is_authoritative" {
error_message = "A non-empty v2 runner map must be authoritative and must not merge stable lanes or flat defaults."
}

assert {
condition = module.runner_configs["experimental"].orchestration_provider.webhook.scale_up.lambda.environment[0].variables["SSM_TOKEN_TTL_SECONDS"] == "7200"
error_message = "A v2 lane token TTL must reach the scale-up Lambda environment."
}

assert {
condition = jsonencode(local.normalized_config) == jsonencode(local.v2_config)
error_message = "A non-empty v2 runner map must select the v2 object without leaking stable flat inputs."
Expand Down
6 changes: 4 additions & 2 deletions modules/orchestration-providers/webhook/pool/pool.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ locals {
INCLUDE_BUSY_RUNNERS = var.config.include_busy_runners
}

ssm_environment_variables = {
ssm_environment_variables = merge({
PARAMETER_GITHUB_APP_ID_NAME = var.config.github_app_parameters.id.name
PARAMETER_GITHUB_APP_KEY_BASE64_NAME = var.config.github_app_parameters.key_base64.name
PARAMETER_GITHUB_APPS_MANIFEST_NAME = var.config.github_app_parameters.additional_apps_manifest != null ? var.config.github_app_parameters.additional_apps_manifest.name : ""
Expand All @@ -38,7 +38,9 @@ locals {
SSM_PARAMETER_STORE_TAGS = var.storage_provider.aws.ssm.parameter_store_tags
SSM_PARAMETER_STORE_MAX_CONCURRENT_INVOCATIONS = var.storage_provider.aws.ssm.parameter_store_max_concurrent_invocations
SSM_PARAMETER_STORE_MAX_WRITES_PER_SECOND = var.storage_provider.aws.ssm.parameter_store_max_writes_per_second
}
}, var.storage_provider.aws.ssm.token_ttl_seconds != null ? {
SSM_TOKEN_TTL_SECONDS = tostring(var.storage_provider.aws.ssm.token_ttl_seconds)
} : {})
}

resource "aws_lambda_function" "pool" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ variable "storage_provider" {

parameter_store_max_concurrent_invocations = optional(number, 1)
parameter_store_max_writes_per_second = optional(number, 40)
token_ttl_seconds = optional(number, null)
})
})
environment_variables = optional(map(string), {})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ resource "aws_lambda_function" "scale_up" {
SSM_PARAMETER_STORE_TAGS = var.storage_provider.aws.ssm.parameter_store_tags
SSM_PARAMETER_STORE_MAX_CONCURRENT_INVOCATIONS = var.storage_provider.aws.ssm.parameter_store_max_concurrent_invocations
SSM_PARAMETER_STORE_MAX_WRITES_PER_SECOND = var.storage_provider.aws.ssm.parameter_store_max_writes_per_second
}, var.storage_provider.scale_up.environment_variables)
}, var.storage_provider.aws.ssm.token_ttl_seconds != null ? {
SSM_TOKEN_TTL_SECONDS = tostring(var.storage_provider.aws.ssm.token_ttl_seconds)
} : {}, var.storage_provider.scale_up.environment_variables)
}

dynamic "vpc_config" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ variable "config" {
- `storage_provider.aws.ssm.parameter_store_tags`: JSON-encoded tags applied to parameters created at runtime.
- `storage_provider.aws.ssm.parameter_store_max_concurrent_invocations`: Expected number of concurrent scale-up and pool Lambda invocations writing to Parameter Store, used to pace writes.
- `storage_provider.aws.ssm.parameter_store_max_writes_per_second`: Parameter Store write-rate limit, in writes per second, that runtime writes are paced against.
- `storage_provider.aws.ssm.token_ttl_seconds`: Optional TTL in seconds for registration-token and JIT-config parameters. Null leaves SSM expiration policies disabled.
- `observability.logs`: Shared logging level, retention, encryption, and log-class configuration.
- `observability.tracing`: Lambda X-Ray and tracing-helper configuration.
- `observability.metrics`: Metrics enablement, namespace, and GitHub rate-limit metric configuration.
Expand Down Expand Up @@ -247,6 +248,7 @@ variable "storage_provider" {

parameter_store_max_concurrent_invocations = optional(number, 1)
parameter_store_max_writes_per_second = optional(number, 40)
token_ttl_seconds = optional(number, null)
})
})
scale_up = optional(object({
Expand Down
2 changes: 2 additions & 0 deletions modules/orchestration-providers/webhook/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ variable "storage_provider" {
- `storage_provider.aws.ssm.parameter_store_tags`: JSON-encoded tags applied to runtime parameters.
- `storage_provider.aws.ssm.parameter_store_max_concurrent_invocations`: Expected number of concurrent scale-up and pool Lambda invocations writing to Parameter Store, used to pace writes.
- `storage_provider.aws.ssm.parameter_store_max_writes_per_second`: Parameter Store write-rate limit, in writes per second, that runtime writes are paced against.
- `storage_provider.aws.ssm.token_ttl_seconds`: Optional TTL in seconds for registration-token and JIT-config parameters. Null leaves SSM expiration policies disabled.
- `scale_up`, `scale_down`, `pool`, and `job_retry`: Provider-owned environment variables and IAM policy fragments.
EOT
type = object({
Expand All @@ -235,6 +236,7 @@ variable "storage_provider" {

parameter_store_max_concurrent_invocations = optional(number, 1)
parameter_store_max_writes_per_second = optional(number, 40)
token_ttl_seconds = optional(number, null)
})
})
scale_up = optional(object({
Expand Down
1 change: 1 addition & 0 deletions modules/runner-config/orchestration-provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ module "orchestration_webhook" {
parameter_store_tags = local.parameter_store_tags
parameter_store_max_concurrent_invocations = var.storage_provider.aws.ssm.parameters.max_concurrent_invocations
parameter_store_max_writes_per_second = var.storage_provider.aws.ssm.parameters.max_writes_per_second
token_ttl_seconds = var.storage_provider.aws.ssm.ttl_seconds.tokens
}
}
}
Expand Down
60 changes: 60 additions & 0 deletions modules/runner-config/tests/pool.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -692,3 +692,63 @@ run "job_retry_uses_common_runner_configuration_identity" {
error_message = "Job retry must apply its configured Lambda reserved concurrency."
}
}

run "token_ttl_defaults_to_disabled" {
command = plan

assert {
condition = (
!contains(keys(module.orchestration_webhook[0].scale_up.lambda.environment[0].variables), "SSM_TOKEN_TTL_SECONDS")
&& !contains(keys(module.orchestration_webhook[0].pool.lambda.environment[0].variables), "SSM_TOKEN_TTL_SECONDS")
)
error_message = "Omitted token TTL must leave expiration disabled."
}
}

run "token_ttl_reaches_scale_up_and_pool" {
command = plan

variables {
storage_provider = {
aws = {
ssm = {
paths = {
root = "/github-runner"
tokens = "tokens"
config = "config"
}
ttl_seconds = { tokens = 300 }
}
}
}
}

assert {
condition = (
module.orchestration_webhook[0].scale_up.lambda.environment[0].variables["SSM_TOKEN_TTL_SECONDS"] == "300"
&& module.orchestration_webhook[0].pool.lambda.environment[0].variables["SSM_TOKEN_TTL_SECONDS"] == "300"
)
error_message = "The storage-provider token TTL must reach both scale-up and pool Lambdas."
}
}

run "rejects_non_positive_token_ttl" {
command = plan

variables {
storage_provider = {
aws = {
ssm = {
paths = {
root = "/github-runner"
tokens = "tokens"
config = "config"
}
ttl_seconds = { tokens = 0 }
}
}
}
}

expect_failures = [var.storage_provider]
}
10 changes: 9 additions & 1 deletion modules/runner-config/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ variable "storage_provider" {
- `storage_provider.aws.ssm.paths.tokens`: Path segment under `paths.root` used for registration tokens and just-in-time configuration.
- `storage_provider.aws.ssm.paths.config`: Path segment under `paths.root` used for persistent runner configuration.
- `storage_provider.aws.ssm.kms_key_id`: Optional customer-managed KMS key ARN used by control-plane IAM policies to decrypt shared GitHub App parameters. The ARN may be unknown until apply; null omits the provider-owned KMS statements. It does not select encryption for runtime-created runner parameters.
- `storage_provider.aws.ssm.ttl_seconds.tokens`: Optional TTL in seconds for the Parameter Store parameters holding the runner registration token or just-in-time configuration. When set, the webhook scale-up and pool Lambdas and the scale-set controller create these parameters with an SSM expiration policy. Requires the Advanced parameter tier, which incurs additional costs. Must be a positive number and should comfortably exceed the runner boot time. Null leaves native expiration disabled.
- `storage_provider.aws.ssm.tags`: Shared tags for SSM-related resources. These override module-level `tags` and are inherited by parameter and housekeeper resources.
- `storage_provider.aws.ssm.parameters.max_concurrent_invocations`: Expected number of concurrent scale-up and pool Lambda invocations writing to Parameter Store. Each invocation paces its writes to a share of the account-wide write-rate limit. The default is `1`.
- `storage_provider.aws.ssm.parameters.max_writes_per_second`: Parameter Store write rate to pace against, in writes per second. AWS documents a `PutParameter` quota of 3 TPS per account and Region (10 TPS with higher throughput enabled). The default of 40 keeps the previous pacing; lower it if `PutParameter` calls are throttled.
Expand Down Expand Up @@ -174,7 +175,10 @@ variable "storage_provider" {
config = string
})
kms_key_id = optional(string, null)
tags = optional(map(string), {})
ttl_seconds = optional(object({
tokens = optional(number, null)
}), {})
tags = optional(map(string), {})
parameters = optional(object({
tags = optional(map(string), {})
max_concurrent_invocations = optional(number, 1)
Expand Down Expand Up @@ -205,6 +209,10 @@ variable "storage_provider" {
})
})

validation {
condition = var.storage_provider.aws.ssm.ttl_seconds.tokens == null ? true : var.storage_provider.aws.ssm.ttl_seconds.tokens > 0
error_message = "`storage_provider.aws.ssm.ttl_seconds.tokens` must be a positive number."
}
}

variable "observability" {
Expand Down
Loading