Repository navigation
Description
Problem or Motivation
Nothing stops an agent from running apply on GitHub settings. Provider calls also bypass the run_gh pacing.
Order 6 of the plan in #5311. The owner approved the plan on 2026-11-13.
Proposed Solution & Architectural Design
Add tf.stacks[].agent_access (plan or apply, default plan for tf/github/*), checked with is_agent_caller. Before a github stack plan, check the remaining budget. For an agent caller, use the reader App credentials from the keyring when they exist.
Target Subsystem
OpenTofu / Infrastructure as Code
Existing Tool Considered
tofu does all of the work. No open tool adds devops pacing, the agent refusal or a dry run with zero requests.
Cost: Build: about 2.0M tokens and 3 days in 3 PRs (pass-through 1.2M, drift fix 0.3M, guard 0.5M), test first. Keep: about 50k tokens a month. Fix: about 200k tokens for each break. This item is the guard part: about 0.5M tokens.
Acceptance Criteria
- Tests show these results: an agent apply is refused, a person passes, a plan below the budget floor is refused, and the dry run sends no request.
- SECURITY.md has a GitHub settings section.
Dependencies
Source: #5311
Alternatives check of 2026-11-22: in-use.
The repository already uses this tool.
Tool: opentofu/opentofu (https://github.com/opentofu/opentofu), MPL-2.0, last activity 2026-11-21, maintained.
Reason: Searches found no tool with an agent refusal, a pre-plan budget floor, a zero-request dry run or reader App credentials; OpenTofu already runs the tf/github stacks but supplies none of those guards.
Covers:
- Runs plan, apply and destroy of the tf/github stacks
- GitHub settings engine that ADR 0026 records
- Provider reads and drift detection for stack resources
Lacks:
- No refusal of apply or destroy for an agent caller
- No pre-plan core budget floor check
- No dry run that sends zero provider requests
- No reader App credentials for an agent plan
Proposed design
Problem statement
An agent can run tofu apply or destroy against GitHub settings in tf/github stacks today. Provider calls also bypass the run_gh pacing. This item adds the agent-access guard for plan, apply and destroy. It adds the pre-plan core budget floor, reader App credentials for agent plans and a zero-request dry run. It documents the controls in SECURITY.md. The state-change guard is deferred because no devops tf state command exists.
Acceptance criteria
Requirement: Agent plan allowed at plan level
The tf command MUST allow an agent caller to run plan on a tf/github stack whose agent_access is plan.
Scenario: Agent plan at plan level
- WHEN an agent caller runs plan for a tf/github stack with agent_access set to plan
- THEN the command starts the plan and reports no agent-access refusal
Requirement: Agent apply refused at plan level
The tf command MUST refuse an apply of a tf/github stack whose agent_access is plan when is_agent_caller reports an agent caller.
Scenario: Agent apply at plan level
- WHEN an agent caller runs apply for a tf/github stack with agent_access set to plan
- THEN the command exits 1 with the access-refused error before the fake process runner records a tofu call and names tf.stacks[].agent_access
Requirement: Person apply passes at plan level
The tf command MUST allow a person caller to apply a tf/github stack whose agent_access is plan.
Scenario: Person apply at plan level
- WHEN a person caller runs apply for a tf/github stack with agent_access set to plan
- THEN the command starts the apply and the fake process runner records the tofu apply
Requirement: Agent destroy refused at plan level
The tf command MUST refuse a destroy of a tf/github stack whose agent_access is plan when is_agent_caller reports an agent caller.
Scenario: Agent destroy at plan level
- WHEN an agent caller runs destroy for a tf/github stack with agent_access set to plan
- THEN the command exits 1 with the access-refused error before the fake process runner records a tofu call and names tf.stacks[].agent_access
Requirement: Agent apply allowed at apply level
The tf command MUST allow an agent caller to apply a tf/github stack whose agent_access is apply.
Scenario: Agent apply at apply level
- WHEN an agent caller runs apply for a tf/github stack with agent_access set to apply
- THEN the command starts the apply and reports no agent-access refusal
Requirement: Default agent access for GitHub stacks
The tf config loader MUST set agent_access to plan for each tf/github stack that has no agent_access value.
Scenario: Default agent access for GitHub stacks
- WHEN the tf config loader reads a tf/github stack with no agent_access value
- THEN the loaded stack reports agent_access as plan
Requirement: Invalid agent access refused
The tf config loader MUST refuse an agent_access value other than plan or apply on a tf/github stack.
Scenario: Invalid agent access value
- WHEN the tf config loader reads a tf/github stack with agent_access set to full
- THEN the loader raises a configuration error naming tf.stacks[].agent_access and the allowed values plan and apply
Requirement: GitHub plan refused below budget floor
The tf command MUST refuse a tf/github stack plan when the remaining core budget of the run_gh ledger is below the configured floor.
Scenario: Plan below budget floor
- WHEN a caller runs plan for a tf/github stack and the fake core quota reports 249 remaining
- THEN the command exits 1 before the fake process runner records a tofu call and names the remaining 249 and the floor 250
Requirement: Dry run sends no provider request
The tf command MUST send no provider request when --dry-run is set.
Scenario: Dry run makes no provider request
- WHEN a person caller runs apply for a tf/github stack with --dry-run
- THEN the command prints the tofu command that it would run and the fake process runner records no tofu call
Requirement: Agent plan uses reader App credentials
The tf command MUST use the reader App credentials from the keyring for an agent caller when those credentials exist.
Scenario: Agent plan uses reader credentials
- WHEN an agent caller runs plan for a tf/github stack and the keyring holds the tf.github_reader settings and private key
- THEN the fake process runner receives the reader installation token and the fake keyring records no read of the writer App key
Requirement: Agent plan refused without reader credentials
The tf command MUST refuse an agent plan of a tf/github stack when the reader App credentials are absent, instead of using the writer App credentials.
Scenario: Agent plan without reader credentials
- WHEN an agent caller runs plan for a tf/github stack and the reader App settings or private key are absent
- THEN the command exits 1 naming tf.github_reader.app_id, tf.github_reader.installation_id and tf.github_reader.private_key, and the fake process runner records no tofu call
Requirement: SECURITY.md GitHub settings section
SECURITY.md MUST have a GitHub settings section that states the agent refusal, the budget check, the reader credentials and the zero-request dry run.
Scenario: GitHub settings security section
- WHEN uv run devops ci --check --only docs runs after the SECURITY.md edit
- THEN the command exits 0 and reports the docs row as passed
Existing Tool Considered
The alternatives check of 2026-11-22 records the verdict in-use for the tool opentofu/opentofu (https://github.com/opentofu/opentofu). The issue body's alternatives block lists what the tool covers and lacks. This item adds the agent refusal, the pre-plan core budget floor, the zero-request dry run and the reader App credentials around it. The guard is about 0.5M tokens of the plan's 2.0M-token, 3-day build. Keeping it costs about 50k tokens a month. Each break costs about 200k tokens to fix.
Key questions
- Which existing tool runs the tf/github stacks?: OpenTofu with the integrations/github provider runs the tf/github stacks. The alternatives check of 2026-11-22 records
in-useforopentofu/opentofu. The issue body's alternatives block lists what it covers and lacks. [sources: docs/adr/0026-github-settings-are-opentofu-code-the-owner-applies.md:15, docs/adr/0026-github-settings-are-opentofu-code-the-owner-applies.md:34] - Where does the tf command enforce agent_access for tf/github stacks?: One function, require_agent_access, in a new src/devops_cli/tf/access.py, runs at the top of tf_plan, tf_apply and tf_destroy. It runs after validate_dir and before the command is built or run. It calls is_agent_caller and reads the stack's agent_access. It follows require_agent_level for infra repos. The state subcommand is deferred because no devops tf state command exists. (best practice) [sources: src/devops_cli/infra/access.py:41, src/devops_cli/commands/tf.py:212, src/devops_cli/commands/tf.py:263, src/devops_cli/core/caller.py:79]
- Chosen: One function called before the provider call. Covers plan, apply and destroy with one rule, refuses before any provider request, and follows the infra access guard.
- Rejected: One check in each subcommand. Repeats the rule and lets a later subcommand miss it.
- Rejected: A Typer callback. The callback does not know the subcommand or the stack directory, so it cannot read the right agent_access.
- What default does agent_access take for tf/github stacks?: The default is plan for tf/github stacks. An explicit apply is required before an agent can apply or destroy. ADR 0026 records that agents plan with the reader App and only a person applies. (best practice) [sources: docs/adr/0026-github-settings-are-opentofu-code-the-owner-applies.md:34, AGENTS.md:21]
- Chosen: Default plan. Matches the recorded decision that agents plan and the owner applies, and gives the least privilege by default.
- Rejected: Default apply. Lets an agent change GitHub settings without an explicit opt-in.
- Rejected: Default none. Blocks the agent plan that the plan requires and that the reader App exists for.
- Which budget floor blocks a GitHub stack plan?: A new DEFAULT_TF_GITHUB_CORE_BUDGET_FLOOR of 250 goes in src/devops_cli/config/defaults.py. The command compares it with the core quota that GitHubRateLimiter.get_quota("core") reads from the run_gh ledger before a tf/github stack plan. The project has no REST budget floor to reuse. The 250-point floor it records is for GraphQL points, which a provider plan does not spend. (best practice) [sources: src/devops_cli/github/rate_limiter.py:1268, src/devops_cli/config/defaults.py:846, src/devops_cli/config/defaults.py:849, docs/adr/0006-github-session-requests-go-through-gidgethub.md:16]
- Chosen: Add a core budget floor of 250. Uses the ledger that run_gh and the GitHub session share, sends no request, and follows the recorded GraphQL floor's 5% rule for the 5,000-point hourly budget.
- Rejected: Reuse DEFAULT_GH_GRAPHQL_BUDGET_FLOOR. That floor counts GraphQL points, and a provider plan spends REST core points, so the two cannot be compared.
- Rejected: Read the live /rate_limit endpoint before each plan. Adds a request to every plan and breaks the zero-request dry run.
- Which App credentials does an agent use for a GitHub stack plan?: The reader App devops-settings-reader uses new settings tf.github_reader.app_id, tf.github_reader.installation_id and tf.github_reader.private_key. The keyring entry is tf_github_reader_private_key. The command mints an installation token with mint_installation_token and gives it to the tofu child. When the reader settings or key are absent, an agent plan is refused and names those settings. It never falls back to the writer App, because ADR 0026 gives agents the reader App and only a person applies. (best practice) [sources: docs/adr/0026-github-settings-are-opentofu-code-the-owner-applies.md:17, docs/adr/0026-github-settings-are-opentofu-code-the-owner-applies.md:34, src/devops_cli/github/app_installation.py:108, docs/CONFIGURATION.md:89, docs/ENV_VARS.md:194]
- Chosen: Reader App credentials, fail closed when absent. Gives an agent plan only the read access that ADR 0026 records, and a missing reader key cannot silently grant the writer App.
- Rejected: Reader App credentials, fall back to the writer App. A missing reader key would give an agent a token that can change settings, contrary to ADR 0026 and AGENTS.md.
- Rejected: Always use the writer App. Gives a plan more access than it needs and contradicts the reader App decision.
- What does --dry-run do for a tf/github stack?: It keeps the existing request-plan dry-run class. It runs the agent-access and budget checks, renders the tofu command that it would run, and returns before run_subprocess. It starts no tofu process and sends zero provider requests. (best practice) [sources: ARCHITECTURE.md:170, src/devops_cli/commands/tf.py:173, src/devops_cli/commands/tf.py:221, src/devops_cli/commands/tf.py:267]
- Chosen: Check and print only. The project records that a dry run sends no external request, a read included, and the existing tf commands already return before run_subprocess.
- Rejected: Run tofu plan with refresh disabled. A plan can still read data sources and send provider requests.
- What does SECURITY.md add for GitHub settings?: It adds a GitHub Settings section after the Infra Repos section. The section states the agent refusal for apply and destroy, the plan default, the pre-plan core budget floor, the reader App credentials and the zero-request dry run. (best practice) [sources: SECURITY.md:66, docs/adr/0026-github-settings-are-opentofu-code-the-owner-applies.md:34]
- Chosen: Add a GitHub Settings section. The issue requires it, and SECURITY.md already records the infra access controls in its own section.
- Rejected: Leave SECURITY.md unchanged. Leaves the new controls undocumented.
- Does this item guard a tf state subcommand?: No. No devops tf state command exists. The documented commands are init, plan, apply, destroy, output, validate, fmt, status, graph, drift, lint, notify-plan and cost. commands/tf.py defines no state command. The state-change guard is deferred to a new issue so the plan, apply and destroy guard can ship and be tested now. [sources: docs/commands/tf.md:5, src/devops_cli/commands/tf.py:121, src/devops_cli/commands/tf.py:157, src/devops_cli/commands/tf.py:196, src/devops_cli/commands/tf.py:250]
Fit
Fits in one pull request.
Suspected block
None.
Activity
dan-petty commentedon Nov 13, 2026
tf, and .github/labels.yml declares no scope/tf label. Add the label to the file to give the scope to this item.Both control agent access to infrastructure, but #5125 enables a sanctioned apply path while this item blocks agent apply and destroy on tf/github.devops-cli-service commentedon Nov 16, 2026
Alternatives check: in-use
Reason: Searches surfaced OpenTofu, the IaC engine the project already uses for GitHub settings as code (ADR 0026; parent #5311), and it runs the tf/github stacks (plan/apply/destroy/state, import blocks, kubernetes backend). It does not, however, provide the agent refusal, the pre-plan budget pacing or a zero-request dry run that this issue needs, so it covers only part of the need.
The repository already uses this tool.
Tool: opentofu/opentofu (https://github.com/opentofu/opentofu)
Covers:
Lacks:
Tools considered:
Searches run:
Sources:
Checked on 2026-11-16. A person decides what this means for the item. The check changes no label and closes no issue.
devops-cli-service commentedon Nov 17, 2026
Refine cannot set this item to Ready at 1774ebf while the items below stay open. The next refine round looks at the item again when they close, or when a person replies in a comment or edits the body.
devops-cli-service commentedon Nov 25, 2026
Next step: the stage job writes the plan of the item. See Moved to new items in the section Proposed design of the body.
devops-cli-service commentedon Nov 25, 2026
Released in v0.219.0: https://github.com/dan-petty/devops-cli/releases/tag/v0.219.0
devops-cli-service commentedon Nov 25, 2026
Live since 2026-11-25 17:09 UTC