Self-hosted runner and the GitHub Apps¶
Why a self-hosted runner¶
Terraform state lives in a storage account behind a firewall that allows only known addresses. The jobs that read and write the state account (plan, apply, the drift plan, the unlock, and the drift run's lock sweep) run on a self-hosted runner on a private network with access the state firewall allows.
The jobs that hold no Azure identity (discovery of the PR's units, event
parsing, the merge gate, and drift issue reporting) run on hosted
ubuntu-latest runners, because the self-hosted runner is network-scoped and
does not carry gh.
Set the runner label with the RUNNER_LABEL repository variable. When it is not
set, jobs fall back to ubuntu-latest, which is fine for a demo that does not
need private state access.
The runner image¶
The runner image bakes in the tools the gates need so nothing is installed
on the critical path. It is built, scanned, and cosign-signed once and
published as ghcr.io/nrit-solutions/alz-runner; the bootstrap imports the
digest pinned in the customer tfvars into an in-tenant registry, and the
job pulls it from there over a private endpoint. Sovereignty-sensitive
customers can instead build the same image from source inside their tenant
(the bootstrap's runner_image_commit fallback). Either way:
- conftest and checkov are baked into the image. checkov is a Python tool
with no static binary, so baking it is the production path. On the self-hosted
posture, set
TFPR_EXTRA_TOOLSto justinfracost. - infracost is a static binary that the workflow installs per run when
TFPR_EXTRA_TOOLSincludesinfracost. It installs to a user-writable path because the runner runs as a non-root user.
On a GitHub-hosted posture there is no baked image, so TFPR_EXTRA_TOOLS installs
all three per run: conftest checkov infracost.
The image does not carry Terraform, Terragrunt, or the engine binary on
purpose: the repository's mise.toml and the engine pin decide those
versions per run, so a toolchain bump never needs an image release.
What the runners must reach¶
Every job installs the engine runtime from the public release its caller
pins, and the license check downloads a signed revocation list. The runners
need HTTPS access to api.github.com, github.com,
release-assets.githubusercontent.com and the revocation list host. The full
list, and how to test it, is in
License requirements.
Verify a runner image release¶
Releases, release notes and the SBOM are public on the
runner image releases page.
Each release names the image digest to pin, carries a cosign keyless
signature on that digest, and ships a signed SPDX SBOM as the release assets
sbom.spdx.json and sbom.spdx.json.bundle. Watch the repository for
releases to hear about a new version. Take runner_image_version and
runner_image_digest from the same release.
Verify the image signature, with the tag and digest of the release you pin (the current one is under Runner image pin):
TAG=vX.Y.Z
DIGEST=sha256:...
cosign verify "ghcr.io/nrit-solutions/alz-runner@${DIGEST}" \
--certificate-identity "https://github.com/nrit-solutions/nrit-alz-runner-image/.github/workflows/release.yml@refs/tags/${TAG}" \
--certificate-oidc-issuer https://token.actions.githubusercontent.com
Verify the SBOM:
gh release download "$TAG" -R nrit-solutions/nrit-alz-runner-image
cosign verify-blob sbom.spdx.json --bundle sbom.spdx.json.bundle \
--certificate-identity "https://github.com/nrit-solutions/nrit-alz-runner-image/.github/workflows/release.yml@refs/tags/${TAG}" \
--certificate-oidc-issuer https://token.actions.githubusercontent.com
Both print Verified OK. The identity proves the release workflow of this
repository signed the artifact at that tag, so you can check what runs in
your tenant without trusting the transport.
Runner logs¶
The Container Apps environment uses the azure-monitor logs destination, so
runner console and system logs follow its diagnostic settings. The bootstrap
sets none. The Deploy-Diag-LogsCat policy adds one that sends them to the
central Log Analytics workspace, after a
remediation on a new
stamp. Query them in the ContainerAppConsoleLogs table.
Runner sizing¶
Runner replicas run at 2 vCPU and 4Gi with a 7200-second replica timeout.
This is deliberate. The AVM module defaults (1 vCPU, 2Gi, 1800s) OOM-hang the heavy
ALZ policy-library plans and kill the runner mid-job, which leaves stale state
locks. The bootstrap sets the larger size through
container_app_container_cpu, container_app_container_memory, and
container_app_replica_timeout.
The KEDA scaler checks the GitHub job queue every 10 seconds
(container_app_polling_interval_seconds). A queued job waits on average half
that interval for the next check, then the container starts and the runner
registers, which together take about 40 seconds. The AVM default of 30 seconds
added about 15 seconds of wait to every self-hosted job. Polling is not billed
by Azure, and at 10 seconds it uses a few hundred GitHub API requests per hour
on the runners App, against a 5,000 per hour budget.
The runners GitHub App¶
Runner registration and the queue-watching KEDA scaler authenticate as a
dedicated GitHub App. Its permissions sit under Repository permissions:
Administration: Read and write, and Actions: Read-only. Nothing under
Organization or Account permissions, and webhook off. The runners are
repository-scoped, so the App needs the customer repository in its
installation; see
installing the checks and runners Apps. Every
call runs on a short-lived installation token minted from the App key, so
no expiring credential lives in the customer tenant. A stored PAT, the
fallback, stops all runner scale-up silently the day it expires. The
bootstrap wires it through github_runners_app_id,
github_runners_app_installation_id, and
TF_VAR_github_runners_app_private_key; see
Bootstrap reference.
The checks App¶
A second, single-purpose GitHub App owns every engine-authored check run:
the per-unit plan and apply rows, the required tfpr / merge-gate,
and the informational tfpr / approval. Onboarding always includes
it: without the App the rows are created with the
workflow token and rendered under an arbitrary Actions heading, and the
merge gate loses the engine identity the surface is built around.
The App is per-organization, because its private key is the credential that
writes the checks and is never shared across orgs. App names are globally
unique on GitHub and cosmetic here: the bootstrap's App script names it
tfpr-<org> by default (NRIT's is tfpr-nrit-solutions). The row names are identical
everywhere, tfpr / plan (<label>) #<run> and the fixed gate and
approval names; the client id and key are the contract. The engine reads:
TFPR_CHECKS_APP_CLIENT_ID(repository variable)TFPR_CHECKS_APP_PRIVATE_KEY(secret on theplanandapplyenvironments; on the repository only on a GitHub Free organization withlimit_environments_to_default_branch = false)
The App needs Repository permissions > Checks: Read and write and nothing else, webhook off, installed on the landing-zone repository. A configured client id whose App is not installed on the repository fails the run loudly rather than silently falling back.
Create it with the bootstrap repository's script, which opens GitHub's create page with the permission filled in and saves the private key with mode 600:
Install it on the organization with "All repositories" (see installing the Apps). The bootstrap does the rest from two tfvars inputs plus the key in the environment:
| Input | What it does |
|---|---|
checks_app_client_id |
Sets TFPR_CHECKS_APP_CLIENT_ID on the repository |
TF_VAR_checks_app_private_key |
Sets TFPR_CHECKS_APP_PRIVATE_KEY. Omit it on a re-run and the secret is destroyed |
checks_app_id |
Pins the required tfpr / merge-gate context in the ruleset to the App's numeric id, so a same-named check from a workflow or another App cannot satisfy the merge gate |
Look the ids up with gh api orgs/<org>/installations --jq '.installations[]
| {id, app_id, app_slug}'; id is the installation id and app_id the
numeric App ID.
Installing the checks and runners Apps¶
Both Apps are installed on the customer organization before the bootstrap runs.
The checks App: always "All repositories". Every repository in the organization, including the customer repositories the bootstrap creates later, is covered with no further step. The App can only write check runs. The bootstrap cannot add a repository to an installation itself: that call needs a user token.
The runners App: pick one mode.
- All repositories (default). Covers every customer repository with no
further step. Set
github_runners_app_installation_id. The cost is scope: the App can administer every repository in the organization, so use it in an organization that holds landing-zone repositories only. - Only select repositories (hardened). GitHub will not save that install
with no repository selected, and a new organization has none, so create an
empty private placeholder repository first (for example
app-install-anchor) and select it. After the bootstrap, add the customer repository to the installation by hand (the org's Settings > GitHub Apps > Configure). The runners cannot register until it is there.
Cross-repo access¶
GitHub resolves a uses: reference with the target repository's visibility,
never with a caller's token: a private reusable workflow is callable only from
its own organization. That is why the engine is published in public. The
reusable workflows, the dispatch action, the caller examples and the runtime
release assets are published to the public nrit-solutions/tfpr
repository by the engine's release job, so a landing-zone repository in any
organization can reference them and install the runtime without a token. No
organization setting is needed on either side, and no engine credential
lives in the customer repository. The repository tree is Apache-2.0; the
runtime release assets are proprietary and run only under a license (see
License).
Units source public Azure Verified Modules only, so no private module fetch happens on the plan path and nothing else needs a cross-repo grant.