Skip to content

feat(termination-watcher): support additional GitHub Apps - #5467

Merged
guicaulada merged 2 commits into
mainfrom
gc/feat/janitor-multi-app
Oct 27, 2026
Merged

guicaulada merged 2 commits into
mainfrom
gc/feat/janitor-multi-app

Conversation

@guicaulada

@guicaulada guicaulada commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Termination-watcher deregistration currently uses only the first GitHub App credential, and its Terraform wiring omits the additional-App manifest. Configured additional Apps therefore cannot contribute quota to termination cleanup or its SQS retry path.

Load all credentials through the existing manifest-backed store. Select an App using observed installation quota, skip Apps in a one-minute throttling cooldown when another is available, and use a random initial offset for unknown quotas. Keep App JWT and installation-token authentication paired, resolve installation access for the requested owner, and try another configured App if authentication fails. Each termination or retry operation selects an App; authenticated-operation failures retain existing error handling. Single-App configurations remain supported.

Pass the optional manifest reference and credential parameter ARNs through termination-watcher Terraform, including automatic forwarding from multi-runner. Grant scoped GetParameter access for the manifest and GetParameters access for batched credential reads. Omit the optional environment key when no manifest is configured. Deregistration retries retain the configured GHES endpoint.

Validation: 52 termination-watcher package tests and three mocked Terraform tests pass. Coverage includes additional-App deregistration, paired credentials, quota exhaustion, secondary-limit cooldown, authentication fallback, manifest/IAM wiring, disabled deregistration, and single-App defaults. Runtime TypeScript, ESLint, Prettier, Terraform formatting, generated documentation, Lambda bundle build, and diff checks pass. No live GitHub/AWS changes were performed. TFLint is unavailable locally; existing package-wide coverage thresholds remain unchanged.

This PR targets main and changes only termination-watcher authentication, configuration, permissions, and retries.

@guicaulada
guicaulada force-pushed the gc/feat/janitor-multi-app branch from 89ee01e to bfe90f4 Compare September 23, 2026 14:36
@guicaulada guicaulada changed the title feat: use additional GitHub Apps for runner deregistration and reconciliation feat(termination-watcher): support additional GitHub Apps Sep 23, 2026
@guicaulada
guicaulada changed the base branch from gc/feat/registration-janitor to main September 23, 2026 14:36
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Review

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

Scanned Files

None

@guicaulada
guicaulada marked this pull request as ready for review September 23, 2026 14:44
@guicaulada
guicaulada requested review from a team as code owners September 23, 2026 14:44
@guicaulada
guicaulada force-pushed the gc/feat/janitor-multi-app branch from bfe90f4 to 1c503d3 Compare September 24, 2026 13:54
@guicaulada
guicaulada force-pushed the gc/feat/janitor-multi-app branch from 1c503d3 to f360cb5 Compare October 5, 2026 14:04
@guicaulada
guicaulada force-pushed the gc/feat/janitor-multi-app branch from f360cb5 to 859a69f Compare October 14, 2026 12:35
@guicaulada
guicaulada requested a balanced review from Copilot October 14, 2026 16:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Quota state mixes independent installations and retains stale budgets, which can select exhausted Apps or suppress recovered capacity.

3 open findings
What changed in this PR

Adds multi-App authentication to termination-watcher cleanup and SQS retries, using the existing credential store.

Changes:

  • Adds quota-aware App selection, throttling cooldowns, and authentication fallback.
  • Forwards manifest configuration and scoped SSM permissions through Terraform.
  • Preserves the GHES endpoint on retries and adds tests and documentation.
File Description
modules/​termination-watcher/​variables.tf Adds optional multi-App inputs.
modules/​termination-watcher/​tests/​multi-app.tftest.hcl Tests manifest wiring and configuration defaults.
modules/​termination-watcher/​termination/​main.tf Permits batched credential reads.
modules/​termination-watcher/​README.md Documents multi-App support.
modules/​termination-watcher/​notification/​main.tf Permits batched credential reads.
modules/​termination-watcher/​main.tf Wires manifest environment and parameter ARNs.
modules/​termination-watcher/​deregister-retry.tf Extends retry credential permissions.
modules/​multi-runner/​termination-watcher.tf Forwards additional-App configuration.
lambdas/​functions/​termination-watcher/​src/​github-app-client.ts Implements App selection and paired authentication.
lambdas/​functions/​termination-watcher/​src/​github-app-client.test.ts Tests selection, cooldowns, and fallback.
lambdas/​functions/​termination-watcher/​src/​deregister.ts Uses shared authentication and retains retry endpoint.
lambdas/​functions/​termination-watcher/​src/​deregister.test.ts Tests additional-App deregistration.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No unresolved blocking issues remain in authentication, Terraform wiring, or regression coverage.

0 open findings

3 resolved since last review

🧠 Review effort: Balanced

@guicaulada
guicaulada force-pushed the gc/feat/janitor-multi-app branch 3 times, most recently from 02b0f49 to a7bbecb Compare October 19, 2026 14:27
@guicaulada
guicaulada force-pushed the gc/feat/janitor-multi-app branch 2 times, most recently from 52155e5 to ff1f47f Compare October 27, 2026 15:20
Brend-Smits
Brend-Smits previously approved these changes Oct 27, 2026
@guicaulada
guicaulada merged commit eefcb1e into main Oct 27, 2026
96 of 97 checks passed
@guicaulada
guicaulada deleted the gc/feat/janitor-multi-app branch October 27, 2026 17:35
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>
guicaulada pushed a commit that referenced this pull request Nov 3, 2026
🤖 I have created a release *beep* *boop*
---


##
[8.1.0](v8.0.0...v8.1.0)
(2026-10-29)


### Features

* add stateless registration cleanup with multi-App support
([#5465](#5465))
([5959d43](5959d43))
* **termination-watcher:** support additional GitHub Apps
([#5467](#5467))
([eefcb1e](eefcb1e))


### Bug Fixes

* **lambda:** bump undici from 6.29.0 to 6.29.1 in /lambdas
([#5554](#5554))
([94f46c7](94f46c7))
* **scale-down:** clean EC2 runners incrementally and isolate failures
([#5463](#5463))
([60a4c66](60a4c66))
* **scale-down:** scope cached clients by selected GitHub App
([#5466](#5466))
([bbd92fe](bbd92fe))
* **termination-watcher:** grant kms:Decrypt for GitHub App parameters
([#5562](#5562))
([7b54664](7b54664))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: runners-releaser[bot] <194412594+runners-releaser[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants