Skip to content

fix(termination-watcher): preserve env vars and KMS access - #5274

Draft
edersonbrilhante wants to merge 2 commits into
mainfrom
fix-termination-watcher-ssm-kms
Draft

edersonbrilhante wants to merge 2 commits into
mainfrom
fix-termination-watcher-ssm-kms

Conversation

@edersonbrilhante

Copy link
Copy Markdown
Contributor

Description

  • Preserve caller-provided termination-watcher environment variables instead of replacing them in the parent configuration.
  • Keep generated metric and tag-filter variables scoped to the Lambda components that own them.
  • Add optional ssm_kms_key_id support and grant kms:Decrypt to the notification, termination-handler, and deregistration-retry Lambda roles.
  • Wire the existing root and multi-runner kms_key_arn inputs to the termination watcher.
  • Keep the IAM policy shape plan-safe when the key ARN is null or unknown by using an inert fallback ARN.

The runtime already requests decrypted SSM values, so no Lambda source change is required.

Test Plan

  • Added Terraform behavior coverage for caller environment variables, component-owned variables, configured KMS access, and the null-key policy shape: 2 passed, 0 failed.
  • Ran terraform validate for the root module, modules/multi-runner, and modules/termination-watcher.
  • Ran TFLint for modules/termination-watcher.
  • Ran Terraform formatting and git diff --check for the affected files.

Related Issues

@github-actions

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@edersonbrilhante
edersonbrilhante force-pushed the fix-termination-watcher-ssm-kms branch from 221efdd to 453cbd4 Compare September 3, 2026 10:12
Brend-Smits added a commit to Brend-Smits/terraform-aws-github-runner that referenced this pull request Oct 28, 2026
The termination notification, termination handler and deregister-retry
Lambdas read the GitHub App credentials from SSM Parameter Store. When
the parameters are SecureStrings encrypted with a customer-managed KMS
key, the roles had no kms:Decrypt on it, so every read failed and
runners were never deregistered.

Add an optional github_app_kms_key_arn to the module config and build
the credential-read policy once, so all three roles get the SSM actions
and kms:Decrypt scoped to that key. The root module passes kms_key_arn
and multi-runner passes the SSM storage provider key, so consumers need
no new input. Deregistration disabled or no key keeps the previous
policy.

Builds on github-aws-runners#5467 and the earlier attempt in github-aws-runners#5274.

Signed-off-by: Brend Smits <[email protected]>
Brend-Smits added a commit that referenced this pull request Oct 29, 2026
…#5562)

## Description

The termination-watcher Lambdas (notification, handler and
deregister-retry) read the GitHub App credentials from SSM to deregister
runners. If those parameters are SecureStrings encrypted with a
customer-managed KMS key, the roles have no `kms:Decrypt` on it, so the
read fails and the runner is never deregistered. #5467 fixed the SSM
actions and parameter list, so this is the next thing that breaks.

This adds an optional `github_app_kms_key_arn` to the watcher config.
When it is set and deregistration is enabled, all three roles get
`kms:Decrypt` on that key. The SSM and KMS statements are built once and
shared by the three roles. `multi-runner` passes the SSM storage
provider key and the root module passes `kms_key_arn`, so nobody has to
change their inputs. Without a key, or with deregistration off, the
policy is the same as before.

Prior attempt in #5274, which is no longer active. It also changed how
environment variables are preserved, which I left out here to keep this
to the KMS access.

## Test Plan

- New `modules/termination-watcher/tests/kms.tftest.hcl`: key set (SSM
actions on all primary, additional-app and manifest ARNs plus
`kms:Decrypt` on only that key), no key, single app, deregistration
disabled with a key set, and a key that is only known after apply.
- `terraform test` in `modules/termination-watcher` and
`modules/multi-runner`, `terraform validate` in both and at the root,
`terraform fmt -check -recursive`.
- `yarn test`, `yarn lint` and `yarn format-check` in `lambdas`.
- Not deployed anywhere yet.

## Related Issues

Builds on #5467. Supersedes the KMS part of #5274.

---------

Signed-off-by: Brend Smits <[email protected]>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions Bot added the Stale label Dec 2, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant