Skip to content

Security model

This page is the whole security picture in one place: how jobs authenticate, what runs with which credential, what blocks an apply, and what is left as accepted risk. The detail pages link back here rather than repeating it.

Summary

  • No cloud secret exists. Azure access is Entra workload-identity OIDC, bound to a GitHub environment. There is nothing to rotate and nothing to leak.
  • Two identities, two privilege levels. Plan runs as Reader, apply runs as Owner, both at the scope of the landing-zone management group, never the tenant root on a production tenant. A plan job cannot reach the apply identity.
  • PR code never runs with write credentials. Jobs are split by trust. The jobs that hold GitHub write tokens run the pinned engine runtime and hold no id-token; the job that evaluates pull request HCL holds nothing at all, and Terraform and hooks run with an allow-listed environment that carries no GitHub token.
  • Five independent controls cover who asks, whether apply is allowed, whether what applies is what was reviewed, whether the branch can merge, and whether the plan passes policy, security, and cost.
  • State is Entra-only. Shared access keys are disabled on the storage account, and on the private posture the data plane is default-deny.

Identity and OIDC

Azure access uses Entra workload identity federation. A job binds a GitHub environment, GitHub mints an OIDC token whose subject carries the repository and the environment, and Entra matches that subject to a federated credential on a user-assigned managed identity.

OIDC trust chain: a workflow job in a plan or apply environment gets an OIDC token whose subject must match the federated credential for that environment; the plan identity gets Reader and the apply identity Owner at management-group scopeOIDC trust chain: a workflow job in a plan or apply environment gets an OIDC token whose subject must match the federated credential for that environment; the plan identity gets Reader and the apply identity Owner at management-group scope

The bootstrap (nrit-alz-bootstrap) creates both identities in identity.tf, each with one federated credential, using the immutable-id subject form by default (the name-only form below is the legacy fallback):

repo:org@<org-id>/repo@<repo-id>:environment:plan
repo:org@<org-id>/repo@<repo-id>:environment:apply

Apply is Owner because the foundation creates role assignments and policy, which Contributor cannot do. Plan is Reader, so a plan job cannot change anything even if the Terraform in the pull request asks it to.

The daily drift sweep runs its drift-plan job in the plan environment, on the Reader identity. One credential covers plan and drift.

Each environment carries its own AZURE_CLIENT_ID variable pointing at the matching identity. A repository-level value would hand the plan jobs the Owner identity, or the apply jobs the Reader one.

A pull_request subject does not work

When a job binds an environment, GitHub puts the environment in the token subject. A repo:<owner>/<repo>:pull_request federated credential never matches, and the login fails before any Terraform runs. The same applies to a renamed environment: the subject embeds the name, so a rename breaks every Azure job at login.

No secrets to rotate. No client secret or certificate is stored anywhere. The token is minted per job, lives for minutes, and is scoped to one repository and one environment.

Immutable repository ids. GitHub renders the sub claim of newly created repositories with immutable ids, repo:org@id/repo@id:environment:env. The bootstrap builds the subjects in that format by default (oidc_subject_uses_repo_ids), so renaming the organization or the repository does not break the trust. It falls back to the legacy name-only form only for repositories created before that rollout.

The subject binds two claims and no more. The workflow file and the engine tag are deliberately left out, so bumping the engine version needs no re-bootstrap. Entra's flexible federated credential caps its claim-matching expression at 128 characters, which repository plus environment plus workflow ref plus tag exceeds.

State access. The state storage account has shared_access_key_enabled = false, so there are no account keys to steal. root.hcl sets use_azuread_auth = true and both identities hold Storage Blob Data Contributor on the container (the plan side runs without the state lock, but terraform init must create the state blob of a unit that has never been applied), plus Storage Table Data Contributor at account scope for the cross-PR unit-lock table (the engine creates the table on first use, so no narrower scope exists at assignment time). On the self_hosted_private posture the account also carries a default-deny network rule that allows only the runner's egress IP. On the github_hosted posture there is no network rule, and Entra authentication is the only control.

The trust split

The PR-ops engine (nrit-tfpr) splits jobs by trust. Pull request code must never run in a job holding a credential it should not have.

The trust split: trusted jobs on hosted runners hold GitHub tokens and no id-token, so they cannot reach Azure and read pull request code only as data; Azure-facing jobs in the plan or apply environment hold an OIDC token to Azure and plan or apply the pull request code; both run the engine binary pinned at the engine tagThe trust split: trusted jobs on hosted runners hold GitHub tokens and no id-token, so they cannot reach Azure and read pull request code only as data; Azure-facing jobs in the plan or apply environment hold an OIDC token to Azure and plan or apply the pull request code; both run the engine binary pinned at the engine tag

Only default-branch runs are trusted. A pull_request run executes the pull request branch's own copy of the caller workflow, so a writer controls it. The PR caller's dispatch job therefore decides nothing: it dispatches the ops caller on the default branch with the PR number, and holds no secret. Every push and every comment then takes the same path there: resolve reads the pull request, its head and its impacted units from the API, opens the merge gate and the per-unit check rows, and gate writes the verdict from those results; drift has resolve and report. No dispatch input reaches the gate. These jobs run pinned engine code and request no id-token, so they cannot reach Azure.

The environments hold what a branch must not reach. plan and apply accept only the default branch, so a workflow pushed on any other branch gets neither the Azure token nor the checks App key, which lives on both environments and nowhere else. resolve, gate and drift's report bind plan only for that key. A repository on GitHub Free cannot limit environments or hold environment secrets on a private repository, so there the key stays at repository level and a writer can reach both.

Azure-facing jobs. The plan matrix, apply, unlock, drift-plan, and drift's lock-sweep. They bind the plan or apply environment, request an id-token, and log in with OIDC (the two lock jobs need it for the lock table on the state account). The consumer's code sits in the workspace as data to plan; the engine binary and scripts stay pinned in .tfpr-engine.

Discovery runs pull request code, so it runs alone. terragrunt find evaluates the pull request's HCL, run_cmd() included. It runs in its own discover job that holds nothing worth taking: no environment, no checks App token, no id-token, a read-only workflow token that only the fetch step sees, and the pull request head in a git worktree under the runner's temp directory, never the workspace. It uploads the selection as an artifact. resolve runs the same terragrunt find on the default branch, which the pull request cannot change, for the map of which unit reads which file. It does that before any step that holds the checks App token, and it keeps no git credential on disk. resolve never checks out the pull request and never evaluates its code: it treats the selection as data and checks it against the changed files and that map. A unit whose files changed, or that reads a changed shared file, must be in the selection, and a unit reported removed must be gone from the branch. Otherwise the gate fails with "Discovery disagrees with the changed files". A pull request can shape what discovery finds; it cannot make the gate believe less than the files show.

The same property covers the gate scripts and the gate results. Hooks in projects.yml call the scripts through $TFPR_ENGINE_DIR, which points at the engine runtime installed under the runner's temp directory from the pinned release and checked against the SHA256SUMS committed in the public repository at that tag. The per-unit gate results are written there too and read by label, so a committed gate/*.status file is never read; a pull request that touches .tfpr-engine/ or gate/ is refused outright ("engine paths in the PR tree"). Hooks and the extra_env list are read from projects.yml on the default branch, so a pull request cannot add a hook for its own run either.

The five controls

Five separate controls sit on the flow. Most are called gates, so name them precisely.

1. Command gate: who is asking

The gate has two layers. Every command must come from a comment whose author_association is OWNER, MEMBER, or COLLABORATOR. On top of that, tfpr apply and tfpr unlock require the commenter's real repository permission to be write or admin, read back from the API. Anything else gets a 😕 reaction and a reply saying which permission the command needs and which one the account has.

Association alone is not an authorization check

author_association is what GitHub reports on the comment, not the author's permission on the repository. MEMBER means any member of the organization, which under read base permissions includes people with no write access here. COLLABORATOR includes read and triage collaborators.

That is why the state-changing commands do not rely on it. tfpr plan still does: it reads rather than writes, and requiring write there would stop a read collaborator asking for a re-plan on their own pull request.

The permission check fails closed. A permission that cannot be read refuses the command, because "the API did not answer" and "this account has no write access" are indistinguishable, and treating silence as consent would let the gate vanish without a signal. The required level is configurable; write is the default.

The check exists only on the comment path. pull_request, workflow_dispatch, and workflow_call runs carry no author_association. See Who can run a command.

2. Approval gate: is the change approved

tfpr apply runs only when GitHub's reviewDecision on the pull request is APPROVED and an approving review sits on the head commit from a user who can push to the repository. REVIEW_REQUIRED and CHANGES_REQUESTED skip the apply and post a comment explaining why; an approval given before the latest push reads "Approval predates the latest push" when the ruleset keeps stale reviews. Commands run on open pull requests only: tfpr plan, tfpr apply and tfpr unlock on a closed or merged one are refused, and the apply job repeats that check before and after Terraform.

An empty reviewDecision means the repository requires no approving reviews at all, and the engine refuses that too. An empty decision is indistinguishable from a repository that lost its required-review ruleset, so treating it as consent would let the gate disappear with no signal. A repository that deliberately requires no reviews opts back in with the repository variable TFPR_ALLOW_UNREVIEWED_APPLY set to true. The bootstrap sets it only when the ruleset requires no review or is off. Leave it unset everywhere else.

The apply job requires the gate verdict to be exactly true, so a path that never reached the gate is refused rather than allowed.

Apply is pinned to the approved commit. resolve records the head SHA it gated on. The apply job checks out that exact SHA, not the moving head ref, and then re-reads the current head with tfpr verify-head. A push landing during environment approval or runner queueing stops the run instead of applying code nobody approved.

Every run that selects a unit also publishes an informational tfpr / approval check run carrying the review decision, so the requirement is visible from the first plan. A submitted or dismissed review refreshes it: the review caller on the PR branch only dispatches, and the ops run on the default branch reads the decision and writes the row, so no PR-side workflow writes a check. Never make it a required check.

3. Reviewed-plan guard: what applies is what was reviewed

Before applying a unit, the engine re-plans it and compares the fresh plan against the reviewed plan summary, which lives in the unit's check run on the head commit, where only the checks App can write; a summary pasted into a comment by anyone else is ignored. When they differ, the apply is refused: the unit's check reads "Plan changed since review" and the merge gate reads "Plan changed since review: comment tfpr plan, then tfpr apply after review". Re-run tfpr plan, review the new plan, then tfpr apply again. This closes the window between the review of a plan and the apply of a different one, whether the world moved or the branch did.

4. Merge gate: can the branch move

The engine writes one required check run, tfpr / merge-gate, under the org's checks App; the prefix is the brand every engine row carries, matching the engine repository name nrit-tfpr. It opens queued when a run takes the PR and concludes green only when the pull request has no Terraform, is a no-op, or has been fully applied, and only when every changed Terraform path belongs to a planned unit (gate_ignore: in projects.yml names the deliberate exceptions). Red otherwise, including when a unit is locked by another pull request.

Make it a required check on the default branch. That is what produces the apply-before-merge property: the main branch always matches applied infrastructure.

The bootstrap's require-approved-pr-to-main ruleset requires it: the required_status_checks variable defaults to ["tfpr / merge-gate"]. A customer tfvars that overrides the variable must keep that entry.

The ruleset also requires an approving pull request review. It gates the merge, not the apply. The engine gates the apply separately on the same review decision, so in practice an unapproved change can neither apply nor merge.

5. Plan gates: policy, security, and cost

Three post_plan hooks run on every plan and every drift plan, and not again on apply, whose plan the reviewed-plan guard has already matched to the gated one: conftest for custom Rego policy, checkov for the security baseline, and infracost for the cost delta. They are report-only by default and their findings are auto-expanded in the run comment when anything is flagged. See Policy, security, and cost gates.

Secrets and blast radius

Secrets are passed by name. The two reusable-workflow callers (tfpr.yml and drift.yml) pass exactly two secrets to the reusable workflow: TFPR_CHECKS_APP_PRIVATE_KEY and INFRACOST_API_KEY. Nothing else stored on the repository reaches the engine. The two dispatch-action callers pass nothing. secrets: inherit is not used: GitHub honours it only when the caller and the reusable workflow share an organization, so a repository in any organization other than nrit-solutions would run with every secret empty. See Secrets and variables.

Permissions are a ceiling. A reusable workflow cannot ask for more than the caller grants. The ops caller declares contents: read, pull-requests: write, checks: write and id-token: write. The drift caller is different: contents: read, issues: write, id-token: write, pull-requests: read for the lock sweep. The PR and unlock callers hold only contents: read and actions: write. Each engine job then requests only the subset it needs, and the trusted jobs request no id-token at all.

No engine credential, and output is scrubbed. The engine runtime is installed from a public release with no token, so no engine credential lives in the customer repository. Actions masks secrets in job logs but not in an API request body, and only for values it already knows, so every captured tool output passes through the engine's secret scrubber, both before it is posted as a comment or drift issue and as it streams to the job log. Its rules cover basic-auth URLs (the x-access-token:...@ form included), GitHub token prefixes, SAS signatures, connection-string keys (account, shared access and instrumentation keys, passwords), JSON Web Tokens, PEM private key blocks, Infracost keys and client_secret values. A plan diff line whose attribute name ends in a credential word (connection string, access, account, primary or secondary key, secret, password, token, SAS) shows (redacted) in place of the value, so a reviewer still sees that it changed. Names that only look similar, such as key_vault_id or public_key, and resource IDs stay visible. A credential inside a multi-line value, or under a name outside that list, is not caught: mark such outputs sensitive in the module.

Releases are immutable and verified from the tree. The engine's releases cannot be edited or have assets replaced once published, and every consumer job verifies the runtime it installs against the SHA256SUMS committed in the public repository at the pinned tag, never against the release's own copy. A swapped release asset fails the install. Each engine release and each runner image release also ships a signed SPDX SBOM; see Software bill of materials.

What a compromised plan runner could reach: the Reader identity at management-group scope, read on the state container through Storage Blob Data Reader, and the unit-lock table through Storage Table Data Contributor at account scope, so it could also forge or release cross-PR unit locks. It cannot write state. It reaches no GitHub token: Terraform and hooks see an allow-listed environment, and the workflow token and the checks App token stay with the engine process.

What it could not reach: the apply identity. The OIDC subject is environment-scoped, so a token minted in the plan environment matches only the plan federated credential. There is no personal access token in the customer repository, and no long-lived cloud credential to lift.

Break-glass and bypass

The require-approved-pr-to-main ruleset always carries one bypass actor: OrganizationAdmin, with bypass_mode = always. An organization admin can merge without an approved pull request. That is the accepted break-glass path, and it is deliberate: a ruleset with no bypass can wedge a repository with no way back.

The bootstrap's ruleset_bypass_actors adds more. In a customer-owned organization, give the MSP operator team pull_request bypass: its members can merge a pull request that does not meet the rules, but cannot push to the default branch directly. Nothing else is added by default.

Two limits on it are worth stating plainly.

  • Bypassing the ruleset bypasses the merge, not the apply. The engine reads reviewDecision itself and still refuses tfpr apply without an approving review. An admin who bypasses to merge has merged code that was never applied, which the daily drift sweep then reports.
  • The bypass is on the ruleset, so it is visible: rule bypasses appear in the organization audit log.

Rotation

OIDC has nothing to rotate. There is no client secret and no certificate behind the Azure login.

Five credentials do have a lifetime:

Credential Where it lives Note
Checks App private key TFPR_CHECKS_APP_PRIVATE_KEY secret on the plan and apply environments of the customer repository Signs the engine's check rows; part of onboarding, set by the bootstrap from TF_VAR_checks_app_private_key.
Infracost API key INFRACOST_API_KEY secret on the customer repository Set by the bootstrap from TF_VAR_infracost_api_key, or by you with infracost_api_key_unmanaged = true. The cost gate skips without it.
Bootstrap App private key Operator machine only, the file at github_app_pem_file or TF_VAR_github_app_private_key Never in a tfvars file (a path may be). Used only when the bootstrap runs; the provider mints a short-lived installation token from it.
Runners App private key Operator environment, TF_VAR_github_runners_app_private_key; the bootstrap hands it to the runner deployment Registers the self-hosted runners (self_hosted_private only). Never in a tfvars file.
Bootstrap GitHub PAT Operator environment only, GITHUB_TOKEN / TF_VAR_github_runners_token Fallback without the bootstrap App or the runners App. Never in a tfvars file. Used only when the bootstrap runs.

For the procedures, see the runbook.

Residual risks and known limits

Stated honestly, because a reviewer will find them anyway.

  • tfpr plan trusts organization membership. Under read base permissions, an organization member with no write access on this repository can type tfpr plan. They cannot apply or unlock: those read the commenter's real repository permission and require write.
  • A member can run plan against pull request code. The plan job runs the consumer's Terraform and Terragrunt from the pull request in the plan environment, and Terragrunt's run_cmd() runs shell. Hooks come from projects.yml on the default branch, so a pull request cannot change them for its own run. The exposure is the Reader identity, read access to state and write access to the unit-lock table, on a runner that is inside the customer network on the private posture.
  • The cost gate calls a hosted API. infracost sends per-resource region and SKU to its pricing API. The Terraform itself does not leave. This is an accepted trade-off; the self-hosted pricing API is behind a paid plan. Upload of the breakdown, which would carry the commit sha and the author's name, email, and message, is off: the gate sets it off on every run rather than leaving it to a remote Infracost Cloud default. See Cost gate data residency.
  • The security scan downloads a file. checkov fetches its list of guideline links from api0.prismacloud.io on every run, so each finding can link to its fix. It is a plain download: no plan, code, or customer data is sent. A runner with restricted egress can turn it off by adding --skip-download to CHECKOV_ARGS; findings then carry no link, and inline skips that use Prisma BC_* IDs stop working (CKV_* IDs still work). See checkov-gate.sh.
  • The license check downloads a file. Each run downloads a signed revocation list from license.nrit.cloud. It is a plain download: no repository, tenant or customer data is sent. The license and entitlement are plain variables, not secrets: each is a signed token that only works for the organization and tenant it names. A failed download fails open from a cached copy for 30 days, then tfpr apply is refused. See License.
  • GitHub environments carry no reviewer protection. The bootstrap limits plan and apply to the default branch, so a workflow on any other branch gets neither the Azure token nor the environment secrets. It adds no reviewer rules, because GitHub does not offer environment required-reviewers on private repositories on the Team plan. Approval is enforced in two portable places instead: the ruleset on the merge, and the engine's review-decision check on the apply. Do not read "the apply environment" as a second approval prompt; it is not one here.
  • State is one account for every unit. Units are isolated by blob key, not by separate accounts. The apply identity can write the whole container and the plan identity can read all of it.
  • The engine sees two named secrets. The checks App key and the Infracost key. A release that needs a new secret says so in its notes, and the callers gain one line.