From 9f96801f76949d870cde8e14e1ad9ac073df757a Mon Sep 17 00:00:00 2001 From: Daniel Petty Date: Sat, 21 Nov 2026 16:23:03 +0000 Subject: [PATCH 1/3] refactor(roadmap): delete the git settings scan check_settings OriginGit runs each call with the token in a new git folder with no global, system or clone configuration, so the scan protected no call. Delete check_settings, refused_settings, their constants and the scan after each turn. GitSettingsError and git_config stay for a link at the shallow file of the clone. --- SECURITY.md | 3 +- docs/ERRORS.md | 2 +- docs/ROADMAP_WORKFLOW.md | 8 +- .../6638-delete-check-settings/.openspec.yaml | 2 + .../6638-delete-check-settings/design.md | 10 ++ .../6638-delete-check-settings/proposal.md | 31 ++++ .../specs/roadmap-implement-runner/spec.md | 60 +++++++ .../6638-delete-check-settings/tasks.md | 22 +++ src/devops_cli/config/constants.py | 67 -------- src/devops_cli/exceptions/roadmap.py | 4 +- src/devops_cli/lang/en/messages.py | 7 +- src/devops_cli/roadmap/failure.py | 2 +- .../roadmap/implement/git_isolation.py | 119 ++----------- .../roadmap/implement/implement_run.py | 28 ++-- .../roadmap/implement/implement_step.py | 13 +- .../test_roadmap_implement_checkpoint.py | 10 +- .../test_roadmap_implement_git_isolation.py | 157 ++++++++---------- tests/roadmap/test_roadmap_faults.py | 7 +- tests/support/roadmap_implement.py | 8 + 19 files changed, 248 insertions(+), 312 deletions(-) create mode 100644 openspec/changes/6638-delete-check-settings/.openspec.yaml create mode 100644 openspec/changes/6638-delete-check-settings/design.md create mode 100644 openspec/changes/6638-delete-check-settings/proposal.md create mode 100644 openspec/changes/6638-delete-check-settings/specs/roadmap-implement-runner/spec.md create mode 100644 openspec/changes/6638-delete-check-settings/tasks.md diff --git a/SECURITY.md b/SECURITY.md index 1ddc0f3af2..b94336e03d 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -51,9 +51,8 @@ All code authored in or evaluated by DevOps CLI must strictly adhere to the foll - **gh.** A gh child gets no `GH_TOKEN` and no `GITHUB_TOKEN`, as gh gives its environment to each `--jq` filter. For each gh child the runner makes a new folder (mode 0700), writes the token to its `hosts.yml` (mode 0600), sets `GH_CONFIG_DIR` and `GH_HOST=github.com`, and removes the folder when the child ends, also after an error, a timeout or a cancel. The folder goes directly into the runtime folder of the user (`platformdirs`), else directly into the temp folder of the system, else into `/gh-config` when the data directory is absolute. No folder of devops-cli is between the runtime folder and the token folder, so no link below the runtime folder can move the token folder. A runtime folder or a `gh-config` folder that is a link, belongs to another user or that others can read is skipped. tempfile uses the current folder when it can write no temp folder, so a runtime or temp folder that resolves into the current folder is skipped too, unless the current folder is the root of the file system. Thus a token file goes into the current folder, which can be a working tree, only when `data.dir` names a folder there. When none works, the call stops with an error that names `XDG_RUNTIME_DIR`, `TMPDIR` and `data.dir`. An async call looks up the token in a thread and makes the folder in the thread of the event loop, so a cancelled call leaves no folder. A gh child reads no gh configuration of the person: no alias, pager, editor or `git_protocol`, and no login for a host other than github.com. The local gh commands (`gh auth`, version and help) get the tokens of the environment. - **git.** Only a git child that reaches a remote (`push`, `fetch`, `pull`, `ls-remote`, `clone`, and `remote set-head`, `show`, `update` and `prune`) gets `GH_TOKEN`, which `gh auth git-credential` reads. A local git child, such as `git add` or `git commit`, gets none: a program that the configuration of its repository names runs as its child. - **A timeout.** Each child that gets the session's token starts in a session of its own. A timeout kills its whole process group, so no helper that the child started, such as `git-remote-https`, keeps the token in its environment. - - **The implement job.** The agent of a step runs as the user of the Job, so it can write the git configuration of the home folder and of the clone, the hooks and the attribute files. Each git call of the job that reaches `origin` runs through `OriginGit` (`src/devops_cli/roadmap/implement/git_isolation.py`): in a new bare git folder that links the objects of the clone, with `GIT_CONFIG_GLOBAL=/dev/null`, `GIT_CONFIG_NOSYSTEM=1`, an empty home folder, an empty `credential.helper` before the trusted helper, no hooks, and the URL of `origin` that the job read before its first step. The job ends every leftover process before the check of the settings, before it makes the folder and again before the call. When each turn of the agent ends and before each such call, the job checks the git settings of the checkout, and a key, an attribute driver or an alternates file that it does not allow stops the item with the class `git_config`. A refused setting at a push in the middle of a turn stops the item at once. The new git folder gets a copy of the `shallow` file of a shallow clone, which the job opens with `O_NOFOLLOW`: a link there stops the item with `git_config`. A fetch that changes the file writes it back through a new file with a random name and `os.replace`, so the write follows no link. A verification command of a plan runs git only as the negative search `! git grep`, which reaches no remote: in the checkout, any other git call would read the configuration that the agent can write. + - **The implement job.** The agent of a step runs as the user of the Job, so it can write the git configuration of the home folder and of the clone, the hooks and the attribute files. Each git call of the job that reaches `origin` runs through `OriginGit` (`src/devops_cli/roadmap/implement/git_isolation.py`): in a new bare git folder that links the objects of the clone, with `GIT_CONFIG_GLOBAL=/dev/null`, `GIT_CONFIG_NOSYSTEM=1`, an empty home folder, an empty `credential.helper` before the trusted helper, no hooks, and the URL of `origin` that the job read before its first step. The job ends every leftover process before it makes the folder and again before the call. The new git folder gets a copy of the `shallow` file of a shallow clone, which the job opens with `O_NOFOLLOW`: a link there stops the item with `git_config`. A fetch that changes the file writes it back through a new file with a random name and `os.replace`, so the write follows no link. A verification command of a plan runs git only as the negative search `! git grep`, which reaches no remote: in the checkout, any other git call would read the configuration that the agent can write. - **Every child with the token in a runner.** The job also runs code of the checkout that the agent wrote: the tests, the hooks of `pre-commit` and the exit checks. In a runner, the process runner ends every leftover process of the job before and after each child that gets the session's token (a gh child, or a git child that reaches a remote), and before the token folder of a gh child exists. The sweep ends every descendant of the job, so a runner runs its children that get the token one at a time. A process that survives stops the item. - - **Limits.** A target repository whose attributes name Git LFS (`filter=lfs`) or another filter, diff or merge driver that git does not define cannot use the implement Job: each item stops with `git_config`. Check the `.gitattributes` of a repository before the Service gets it. `devops roadmap eval implement` clones with `--shared`, which writes an alternates file, so it runs only outside a runner. - **The risk that stays.** The token is in the environment or in a file of the same user while a child runs, so a process of that user could read it. The job ends every process that it started before and after such a child, and the root file system and the folders of `PATH` of the runner image are read-only. `ensure_checkout` and `plan_implement` fetch in the clone with the token, before any step of an agent runs. A process that is killed while a gh child runs can leave the folder of that call: in a runner it is on an `emptyDir` that ends with the pod, and on a workstation it stays until a person removes it. The two-container Job of #3700 moves the token out of the reach of the agent. - **The tests.** `tests/core/test_process.py`, `tests/roadmap/implement/test_roadmap_implement_git_isolation.py` and `tests/roadmap/implement/test_roadmap_implement_token_isolation.py` fail when any of this breaks. diff --git a/docs/ERRORS.md b/docs/ERRORS.md index b972f755e0..6e175026a2 100644 --- a/docs/ERRORS.md +++ b/docs/ERRORS.md @@ -64,7 +64,7 @@ Each exception class declares its `error_code` and `exit_code`. A command that a | `GitHubUnauthenticatedError` | `GITHUB_UNAUTHENTICATED` | `1` | Git | Raised when the process has no GitHub identity, or GitHub refused its token (HTTP 401). | | `GitHubUnreadError` | `GITHUB_UNREAD` | `1` | Git | Raised when no answer from GitHub could be read, so what the request did is unknown. | | `GitOperationError` | `GIT_OPERATION_ERROR` | `1` | Git | Base exception for Git repository and branch operation failures. | -| `GitSettingsError` | `ROADMAP_IMPLEMENT_REFUSED` | `1` | Roadmap | Raised when the git settings of the checkout of the implement job hold a key, an attribute | +| `GitSettingsError` | `ROADMAP_IMPLEMENT_REFUSED` | `1` | Roadmap | Raised when the `shallow` file of the clone of the implement job is a link or is not a | | `GiteaAccessBlocked` | `GITEA_ACCESS_BLOCKED` | `1` | Gitea | Raised when Cloudflare Access blocks a Gitea request with a redirect or challenge. | | `GiteaError` | `GITEA_ERROR` | `1` | Gitea | Base exception for Gitea forge operations. | | `HTTPTimeoutTypeError` | `VALIDATION_ERROR` | `1` | Devops_cli.http.client | Raised when an invalid timeout parameter type is provided. | diff --git a/docs/ROADMAP_WORKFLOW.md b/docs/ROADMAP_WORKFLOW.md index 5d1789d68b..073b9a9114 100644 --- a/docs/ROADMAP_WORKFLOW.md +++ b/docs/ROADMAP_WORKFLOW.md @@ -203,7 +203,7 @@ Each clear by digest adds an entry (the class, the new digest and the time) to ` ## The failure classes -A stop has a class (`roadmap/failure.py`, #3065). A stop site that knows its cause passes the class itself (#3476): the classes `no_change_in_fix`, `tests_lost`, `head_moved`, `output_cap`, `limit_reached` and `outside_plan` come from the step, `git_config` comes from the check of the git settings, the step `fix-plan` gives `timeout` to an attempt that spent its time budget (#5363), the refine round gives `form_check` to a proposal that fails a form check (#6327), and no rule makes them. For any other stop, the classifier is a pure function of the error text, the exit status, the refusal of a tool, the name of the check and the log of the check. It never reads the last message of the agent, which is a claim that no check verified. A failure that no rule matches is `ci_infra`. The stop comment starts with the failed check and the end of its log, then names the class, the action taken and the action left. It shows the last message of the agent as a claim that no check verified. The Job log holds one line with the class and the action left. The Service adds 1 to `devops_cli_service_implement_failures_total` with the labels `class` and `repo` when a round reports the Job. A Job that left the Item with no result gets the class of the tail of its log. +A stop has a class (`roadmap/failure.py`, #3065). A stop site that knows its cause passes the class itself (#3476): the classes `no_change_in_fix`, `tests_lost`, `head_moved`, `output_cap`, `limit_reached` and `outside_plan` come from the step, `git_config` comes from a `shallow` file of the clone that is a link, the step `fix-plan` gives `timeout` to an attempt that spent its time budget (#5363), the refine round gives `form_check` to a proposal that fails a form check (#6327), and no rule makes them. For any other stop, the classifier is a pure function of the error text, the exit status, the refusal of a tool, the name of the check and the log of the check. It never reads the last message of the agent, which is a claim that no check verified. A failure that no rule matches is `ci_infra`. The stop comment starts with the failed check and the end of its log, then names the class, the action taken and the action left. It shows the last message of the agent as a claim that no check verified. The Job log holds one line with the class and the action left. The Service adds 1 to `devops_cli_service_implement_failures_total` with the labels `class` and `repo` when a round reports the Job. A Job that left the Item with no result gets the class of the tail of its log. | Class | Default action | Meaning | | :--- | :--- | :--- | @@ -227,7 +227,7 @@ A stop has a class (`roadmap/failure.py`, #3065). A stop site that knows its cau | `limit_reached` | `raise_limit` | A step spent a token budget or a time limit of `roadmap.implement`, or the one extension of its token budget. The reason names the setting and its value. See [the budgets](#checks-of-the-implement-job) | | `read_only_path` | `wait` | A command wrote to a path that the Job mounts read-only. A new attempt or a new runner image writes to the same path, so a person fixes the cause | | `outside_plan` | `wait` | A fix step changed, added or deleted a path that the plan does not name (a path in a code span of any group, or a file of the change folder). The stop names the paths and holds the discarded diff. A person decides whether the plan changes | -| `git_config` | `wait` | The git settings of the checkout hold a key that the job does not allow, an attribute names a filter, or a diff or merge driver that git does not define, or the clone has an alternates file. The job checks them when each turn of the agent ends and before each git call that reaches `origin`. The stop names each key, or each attribute and its first path, and no value, and pushes nothing. A person removes the setting and its cause | +| `git_config` | `wait` | The `shallow` file of the clone is a link or is not a regular file at a git call that reaches `origin`. git never makes the file a link. The stop names `shallow` and pushes nothing. A person removes the file and its cause | | `plan_unreadable` | `wait` | The plan reader cannot read back the rendered files of a plan, or reads facts that differ from the proposal (#5214) | | `form_check` | `retry` | A refine round wrote a proposal with an empty part that the schema allows: no problem statement, no existing-tool answer, or, for a proposal that fits one pull request, no criterion or a criterion with an empty part. A field that the schema refuses is `parser`. The result line names the failed parts (#6327) | @@ -462,7 +462,7 @@ The runner Job runs the checks that a person runs in the devcontainer, from the - **After the push.** The Job sets the title and the body of the draft, comments the steps on it, records `implement.result` as `drafted`, sets Status In Review and ends (#6559). It watches no check and marks nothing ready. The checks of the pull request stay the gate. Before the end, the Job asks `draft_readiness` with no check runs, as its step `ready` did: a missing change, a group that is not ticked, a change that is not archived or a stage prompt with no eval scores stops the item. In mode `on` of `roadmap.fix_checks.mode`, the watch row runs the ready path of the step `fix-checks` on a green draft and starts a fix-checks Job for a failed check whose name gives the class `test`, `lint` or `types`; modes `off` and `plan` leave a green draft a draft. A failed or cancelled check, or a conflict, has a repair owner only when the mode is `on`, the class is one of these, and the fix-checks unit of the head and the check has not ended with no repair. In each other case the watch row stops the item: Status Blocked, `implement.stopped` at `pull request`, the class, `implement.result` stopped, and one stop comment that names the check or the conflict. The row judges the latest run of each check name. It leaves a draft that an owner label claims. A stopped item gets no ready mark and no fix-checks Job until `implement: retry` clears the stop. A Staged item that delivers on its plan pull request gets the same rules. - **Time.** The hooks add about 10 s to each step, and the install about 9 s. The scoped checks add about 35 s for the first two, and for the tests at most 30 test modules. On 2 CPUs, as in a Job, 12 test modules of the roadmap ran in 88 s, so the tests add at most about 3.5 minutes. The comment on the pull request gives the seconds of each scoped check. -- **Target repositories.** The Job refuses a filter, and a diff or merge driver that git does not define itself, in the attributes of the checkout (the class `git_config`). So a repository that uses Git LFS (`filter=lfs diff=lfs merge=lfs`), `merge=ours` or another driver of its own cannot use the implement Job: each item stops at its first turn. Check the `.gitattributes` of a repository before the Service gets it. A shallow clone, which a run with `--source` can name, works: the network calls copy its `shallow` file. +- **Target repositories.** A shallow clone, which a run with `--source` can name, works: the network calls copy its `shallow` file. - **gh calls.** The Job, and each `devops` command, runs gh with a configuration folder of its own that holds only the token ([SECURITY.md](../SECURITY.md), item 15). A gh call reads no gh configuration of the person: no alias, pager, editor or `git_protocol`, and no login for a host other than github.com. Tests hold the drift: each local hook runs a tool that the runner image holds, each scoped row is a row of `devops ci`, and the branches of the Job pass the branch-name hook. @@ -484,7 +484,7 @@ The implement job has a baseline score. The command that gives it calls a model | `no_scratch` | The diff adds no file at the root, under `.data/`, or with a scratch suffix | | `tasks_ticked` | Every task of the group is ticked | -The report lists each property as pass, fail or skipped, the tokens, the model requests, the tool calls and the wall time of each fixture, and the property that failed first. A run writes the same report as JSON under `eval/implement` in the data directory. The command reads no GitHub state, writes none and pushes nothing. The scratch clone has no remote and goes away after the run. The scratch clone shares the objects of this repository (`git clone --shared`), which writes an alternates file. The check of the git settings refuses that file in a runner, so the command runs only outside a runner. +The report lists each property as pass, fail or skipped, the tokens, the model requests, the tool calls and the wall time of each fixture, and the property that failed first. A run writes the same report as JSON under `eval/implement` in the data directory. The command reads no GitHub state, writes none and pushes nothing. The scratch clone has no remote and goes away after the run. The scratch clone shares the objects of this repository (`git clone --shared`). The fixtures hold the diffs of real runs: deliveries, and stops with a scratch file in the root. `--check-only` evaluates those recorded diffs with no model and no clone, and exits 1 when a diff fails other properties than its record says. `--check-only --run-commands` also applies each diff in a clone, runs the two properties that run commands, and compares all six with the record. A record may name a command property as failed. `--dry-run` lists the fixtures and the model requests, and makes no request. `--no-tools` runs the same fixtures with the remote MCP tools of the step disabled, so two runs of the eval on one fixture set measure the effect of the tools. diff --git a/openspec/changes/6638-delete-check-settings/.openspec.yaml b/openspec/changes/6638-delete-check-settings/.openspec.yaml new file mode 100644 index 0000000000..137e8c3a00 --- /dev/null +++ b/openspec/changes/6638-delete-check-settings/.openspec.yaml @@ -0,0 +1,2 @@ +schema: spec-driven +created: 2026-11-21 diff --git a/openspec/changes/6638-delete-check-settings/design.md b/openspec/changes/6638-delete-check-settings/design.md new file mode 100644 index 0000000000..13ca5816ce --- /dev/null +++ b/openspec/changes/6638-delete-check-settings/design.md @@ -0,0 +1,10 @@ +# Design + +## Decisions +- **`GitSettingsError` and `git_config` stay.** `_read_shallow` raises the error for a link, or anything but a regular file, at the `shallow` file of the clone. That handling stays until #3700, so the error, the class and the stop paths in `implement_run.py` stay for it. The tests of these stop paths now make the `shallow` file a link in place of a refused key. +- **One sweep before the folder.** `OriginGit` ran a sweep, the scan and a second sweep. With no scan, the two sweeps ran one after the other, so one goes. The sweep before the call with the token stays. +- **`_git` loses `isolated`.** Only the scan read the configuration of the clone, with `isolated=False`. Each other call ran isolated. + +## Rejected alternatives +- **Keep the scan as a signal.** The audit of the git use of the roadmap Jobs and the owner decision on #6638 found that the scan protects no call with the token. It also starts a `core.fsmonitor` program before it refuses it, and it refuses Git LFS repositories, blobless clones and the `--shared` evaluation clone. +- **Delete `GitSettingsError` and `git_config` too.** `_read_shallow` still raises the error, and #6638 keeps the `shallow` file handling until #3700. A delete would leave a link at `shallow` with no class. diff --git a/openspec/changes/6638-delete-check-settings/proposal.md b/openspec/changes/6638-delete-check-settings/proposal.md new file mode 100644 index 0000000000..8cc76ea83b --- /dev/null +++ b/openspec/changes/6638-delete-check-settings/proposal.md @@ -0,0 +1,31 @@ +# Proposal: #6638 + +## Why +#6638: `check_settings` scans the git settings of the checkout before each call of `OriginGit` that holds the token, and when each turn of the agent ends. It refuses keys, attribute drivers and an alternates file, and the item stops with the class `git_config`. + +The scan protects no call with the token. `OriginGit` runs each fetch and push in a new git folder with `GIT_CONFIG_GLOBAL=/dev/null` and `GIT_CONFIG_NOSYSTEM=1`, so git reads none of the scanned settings. The scan also has costs: it runs `git ls-files` and `git check-attr` in the checkout, so a `core.fsmonitor` program runs before the scan refuses it, and it refuses blobless clones, Git LFS repositories and the `--shared` evaluation clone. The owner approved the removal of this check on 2026-11-21 (AGENTS.md rule 5). + +## What Changes +- Delete `check_settings`, `refused_settings` and their helpers from `git_isolation.py`, and the constants that only they read: `CONST_GIT_ALLOWED_SETTINGS`, `CONST_GIT_ALLOWED_SETTING_PATTERNS`, `CONST_GIT_ATTRIBUTE_DRIVERS`, `CONST_GIT_BUILTIN_DRIVERS`, `CONST_GIT_ATTRIBUTE_STATES`, `CONST_GIT_ALTERNATES_FILE` and the message `implement_git_attribute_refused`. +- Delete the scan after each turn of the agent in `implement_step.py`, and the second sweep of `OriginGit` that ran after the scan. +- Keep `OriginGit`, its isolated configuration, the sweeps, the `shallow` file handling and the URL pin until #3700. +- Keep `GitSettingsError` and the class `git_config` for their one other raiser: a `shallow` file of the clone that is a link or is not a regular file. The stop paths in `implement_run.py` stay for it, and the message of the error names that file. +- Add tests that an `insteadOf`, a `pushInsteadOf`, a `pushurl` and a `pre-push` hook in the hooks folder of the clone get no request and do not run. +- The change is observable: an item no longer stops on a git setting, so the spec `roadmap-implement-runner` gets a delta. + +## Capabilities +- `roadmap-implement-runner`: remove the requirement of the scan, and change the requirements of the sweeps, of the checkpoint and stop push, and of the network call. + +## Impact +- A target repository with Git LFS, a blobless clone or a driver of its own can use the implement Job. +- The class `git_config` now comes only from a link at the `shallow` file. +- The change fits one pull request. + +## Feasibility +- `git_isolation.py` on `origin/main`: `_Folder.call` runs git with `--git-dir` of a new bare folder, `CONST_GIT_ISOLATED_CONFIG_ENV` and an empty `HOME`, so git reads no configuration of the home folder or of the clone. +- A mutation of `_Folder.call` that runs git in the git folder of the clone, with no isolated environment, makes the new `insteadOf` and `pushInsteadOf` tests fail: the push goes to the planted server. With the isolation, they pass. +- `_read_shallow` raises `GitSettingsError` for a link at `shallow`, so the error and the class have a raiser after the deletion. + +## Existing Tool Considered +- No tool is needed: the change deletes code. git itself, with `GIT_CONFIG_GLOBAL=/dev/null`, `GIT_CONFIG_NOSYSTEM=1` and a new `--git-dir`, is the control that stays. +- Deleted internal code: `check_settings`, `refused_settings`, `_allowed`, `_refused_keys`, `_driver_refused`, `_refused_attributes`, `_CHECKED_SCOPES`, the `isolated` option of `_git`, six constants and one message. diff --git a/openspec/changes/6638-delete-check-settings/specs/roadmap-implement-runner/spec.md b/openspec/changes/6638-delete-check-settings/specs/roadmap-implement-runner/spec.md new file mode 100644 index 0000000000..15894c3b1e --- /dev/null +++ b/openspec/changes/6638-delete-check-settings/specs/roadmap-implement-runner/spec.md @@ -0,0 +1,60 @@ +## MODIFIED Requirements + +### Requirement: A network git call of the implement job reads no file that the agent can write +The implement job SHALL run each git call that reaches `origin`, also the calls of `add_worktree`, through `OriginGit`: in a new bare git folder whose `objects` folder links the object folder of the clone, with `CONST_GIT_TOKEN_CALL_CONFIG`, `CONST_GIT_ISOLATED_CONFIG_ENV`, an empty home folder, and the URL of `origin` that the job read before its first item. It SHALL end every leftover process before it makes the folder and again just before the call. + +#### Scenario: The options and the environment of the call +- **WHEN** the job fetches a branch +- **THEN** the fetch gets `-c credential.helper=`, `-c credential.https://githubproxy.fjygbaifeng.eu.org.helper=`, `-c 'credential.https://githubproxy.fjygbaifeng.eu.org.helper=!gh auth git-credential'` and `-c core.hooksPath=/dev/null`, `GIT_CONFIG_GLOBAL=/dev/null` and `GIT_CONFIG_NOSYSTEM=1`, and a `HOME` that is gone after the call + +#### Scenario: A push sends a commit +- **WHEN** the job pushes the commit `` to its branch +- **THEN** the push gets `--no-verify` and the refspec `:refs/heads/`, runs outside the clone, and the remote-tracking ref of the branch in the clone is `` after it + +#### Scenario: Programs that the home folder of the Job names +- **WHEN** a turn of the agent writes into the git configuration of the home folder a hook folder with a `pre-commit`, `post-commit`, `pre-push` and `reference-transaction` hook and a credential helper, each of which writes the `GH_TOKEN` that it sees, and the job runs a Planned item to its pull request +- **THEN** the branch of the item is on `origin`, the `pre-commit` hook ran with no token, and no program wrote the session's token + +#### Scenario: A server that asks for credentials +- **WHEN** a credential helper is in the home folder and in the configuration of the clone, an `http.proxy` with `http.sslVerify=false` is in both, and the job pushes to a loopback server that answers 401 with a Basic challenge +- **THEN** no helper runs, no request reaches the proxy, the server receives no `Authorization` header, and the push fails + +#### Scenario: A pre-push hook of the clone +- **WHEN** the configuration of the clone sets `core.hooksPath` to a folder with a `pre-push` hook, and the job pushes to a bare repository on disk +- **THEN** the branch is on the bare repository, and the hook did not run + +#### Scenario: A pre-push hook in the hooks folder of the clone +- **WHEN** the hooks folder of the clone holds a `pre-push` hook, no `core.hooksPath` is set, and the job pushes to a bare repository on disk +- **THEN** the branch is on the bare repository, and the hook did not run + +#### Scenario: A URL that the home folder or the clone names +- **WHEN** the home folder and the configuration of the clone hold an `insteadOf`, a `pushInsteadOf` or a `pushurl` that names a loopback server that asks for credentials, and the job pushes to a bare repository on disk +- **THEN** the branch is on the bare repository, and the server receives no request + +### Requirement: The leftover processes end before each part of a network git call +`OriginGit` SHALL end every leftover process before it makes the new folder, and again just before the call with the token. + +#### Scenario: The order of the calls +- **WHEN** the job fetches a branch +- **THEN** the leftover processes end before the new folder is made, again after the refs are copied, and only then the fetch with the token runs + +#### Scenario: A refused setting before the call +- **WHEN** the `shallow` file of the clone is a link, and the job fetches a branch in a runner +- **THEN** the leftover processes end first, the call raises `GitSettingsError` that names `shallow`, and the fetch with the token does not run + +### Requirement: A refused setting at a checkpoint or stop push stops the item at once +A `shallow` file of the clone that is a link, or is not a regular file, at the push of a checkpoint SHALL stop the item with the class `git_config` at once, before the job writes a record of the push. Such a file at the push of a stop SHALL give the stop the class `git_config`. + +#### Scenario: A setting before a checkpoint push +- **WHEN** the agent makes the `shallow` file of the clone a link in group 1 of a change of four groups, and group 1 passes +- **THEN** the checkpoint before group 2 stops the item with the class `git_config`, and the job asks the model for nothing more + +#### Scenario: A setting that an exit check writes +- **WHEN** an exit check of the step makes the `shallow` file of the clone a link and fails, and no repair round is left +- **THEN** the item stops with the class `git_config`, and the comment names `shallow` + +## REMOVED Requirements + +### Requirement: A git setting that the job does not allow stops the item +**Reason**: The scan protects no call with the token. `OriginGit` runs each fetch and push in a new git folder with `GIT_CONFIG_GLOBAL=/dev/null` and `GIT_CONFIG_NOSYSTEM=1`, so git reads none of the scanned settings (#6638). The scan ran `git ls-files` and `git check-attr` in the checkout, so a `core.fsmonitor` program ran before the scan refused it, and it refused blobless clones, Git LFS repositories and the `--shared` evaluation clone. +**Migration**: The requirement "A network git call of the implement job reads no file that the agent can write" keeps the token away from each setting that the agent can write. The two-container Job of #3700 removes `OriginGit`. diff --git a/openspec/changes/6638-delete-check-settings/tasks.md b/openspec/changes/6638-delete-check-settings/tasks.md new file mode 100644 index 0000000000..73fe0ca4c1 --- /dev/null +++ b/openspec/changes/6638-delete-check-settings/tasks.md @@ -0,0 +1,22 @@ +# Tasks + +## 1. The tests of the network call (tests) + +- [x] 1.1 Add tests that an `insteadOf`, a `pushInsteadOf` and a `pushurl` of the home folder and of the clone get no request, and that a `pre-push` hook in the hooks folder of the clone does not run. + - Verification: `$ uv run devops ci test tests/roadmap/implement/test_roadmap_implement_git_isolation.py` + +## 2. The deletion of the scan (refactor) + +- [x] 2.1 Change the tests of the `git_config` stop paths and of the sweep before a refusal to a link at the `shallow` file (`link_shallow`), and delete the tests that cover only the scan. + - Verification: `$ uv run devops ci test tests/roadmap/implement/test_roadmap_implement_git_isolation.py tests/roadmap/implement/test_roadmap_implement_checkpoint.py tests/roadmap/test_roadmap_faults.py tests/roadmap/test_roadmap_failure.py` +- [x] 2.2 Delete `check_settings`, `refused_settings`, their helpers and constants, the message `implement_git_attribute_refused`, the scan after a turn in `implement_step.py`, the second sweep of `OriginGit` and the `isolated` option of `_git`. Change the texts of `GitSettingsError`, `git_config` and `implement_run.py` to the `shallow` file. + - Verification: `$ ! git grep -n -E "refused_settings|check_settings\(|CONST_GIT_ALLOWED_SETTING|CONST_GIT_ATTRIBUTE_|CONST_GIT_BUILTIN_DRIVERS|CONST_GIT_ALTERNATES_FILE|implement_git_attribute_refused" src/ tests/` + +## 3. Documents + +- [x] 3.1 Remove the scan from `SECURITY.md` and `docs/ROADMAP_WORKFLOW.md`, and regenerate `docs/ERRORS.md`. + - Verification: `$ uv run devops docs generate --check` +- [x] 3.2 Change the spec `roadmap-implement-runner`: remove the requirement of the scan, and change the requirements of the sweeps, of the checkpoint and stop push, and of the network call. + - Verification: `$ uv run devops ci --check --only openspec` + +- Pending a person: review the diff in tuicr (tuicr -r origin/main..HEAD). diff --git a/src/devops_cli/config/constants.py b/src/devops_cli/config/constants.py index e4d55c5626..ef7413946a 100644 --- a/src/devops_cli/config/constants.py +++ b/src/devops_cli/config/constants.py @@ -1280,73 +1280,6 @@ """The `git -c` values of a network git call of the implement job (GHSA). The empty helper clears every helper before the trusted one, and no hook runs. The git folder of the call shares the objects of the clone, so git packs and prunes nothing from it.""" -CONST_GIT_ALLOWED_SETTINGS: Final[frozenset[str]] = frozenset( - { - "core.repositoryformatversion", - "core.filemode", - "core.bare", - "core.logallrefupdates", - "core.ignorecase", - "core.precomposeunicode", - "remote.origin.url", - "remote.origin.fetch", - "user.name", - "user.email", - "commit.gpgsign", - "extensions.worktreeconfig", - } -) -"""The git keys of the scopes `local` and `worktree` that the implement job allows in its clone: -the keys that `git clone`, `git init`, `ensure_checkout` and the eval write. None names a program, -a file or a host (GHSA).""" -CONST_GIT_ALLOWED_SETTING_PATTERNS: Final[tuple[str, ...]] = ("branch.*.remote", "branch.*.merge") -"""The `fnmatch` patterns of the other git keys that the implement job allows in its clone.""" -CONST_GIT_ATTRIBUTE_DRIVERS: Final[tuple[str, ...]] = ("filter", "diff", "merge") -"""The git attributes whose value names a driver that git starts as a program.""" -CONST_GIT_BUILTIN_DRIVERS: Final[Mapping[str, frozenset[str]]] = MappingProxyType( - { - "filter": frozenset(), - "diff": frozenset( - { - "ada", - "bash", - "bibtex", - "cpp", - "csharp", - "css", - "dts", - "elixir", - "fortran", - "fountain", - "golang", - "html", - "ini", - "java", - "kotlin", - "markdown", - "matlab", - "objc", - "pascal", - "perl", - "php", - "python", - "r", - "ruby", - "rust", - "scheme", - "tex", - } - ), - "merge": frozenset({"text", "binary", "union"}), - } -) -"""The values of each attribute of `CONST_GIT_ATTRIBUTE_DRIVERS` that git defines itself -(userdiff.c, gitattributes(5)): a built-in pattern of `diff` and a built-in driver of `merge` run -no program. No filter is built in.""" -CONST_GIT_ATTRIBUTE_STATES: Final[frozenset[str]] = frozenset({"unspecified", "set", "unset"}) -"""The words of `git check-attr` for an attribute with no value.""" -CONST_GIT_ALTERNATES_FILE: Final[str] = "objects/info/alternates" -"""The file of a git folder that names other object folders (gitrepository-layout(5)).""" CONST_GIT_SHALLOW_FILE: Final[str] = "shallow" """The file of a git folder that names the commits whose parents a shallow clone does not hold (gitrepository-layout(5)).""" diff --git a/src/devops_cli/exceptions/roadmap.py b/src/devops_cli/exceptions/roadmap.py index daa6a714ef..32d5add1b1 100644 --- a/src/devops_cli/exceptions/roadmap.py +++ b/src/devops_cli/exceptions/roadmap.py @@ -68,8 +68,8 @@ class RoadmapImplementError(DevOpsCLIError): class GitSettingsError(RoadmapImplementError): - """Raised when the git settings of the checkout of the implement job hold a key, an attribute - or a file that the job does not allow. `settings` names each one, and holds no value.""" + """Raised when the `shallow` file of the clone of the implement job is a link or is not a + regular file. `settings` names the file, and holds no value.""" def __init__(self, message: str, *, settings: tuple[str, ...]) -> None: self.settings = settings diff --git a/src/devops_cli/lang/en/messages.py b/src/devops_cli/lang/en/messages.py index b5a957af30..0514687c92 100644 --- a/src/devops_cli/lang/en/messages.py +++ b/src/devops_cli/lang/en/messages.py @@ -3791,11 +3791,10 @@ class RoadmapMessages: "job runs no program with the GitHub token while such a process lives, so it stops the item." ) implement_git_settings_refused: str = ( - "The git settings of the checkout hold {settings}, which the implement job does not allow. " - "The job runs no more git commands in the checkout and pushes nothing. A person removes " - "the setting and its cause, and then retries the item." + "The git folder of the clone holds {settings} as a link or as a file that is not a regular " + "file, which the implement job does not allow. The job pushes nothing. A person removes " + "the file and its cause, and then retries the item." ) - implement_git_attribute_refused: str = "the attribute {attribute} ({path}, {more} more paths)" implement_agent_phase_key_refused: str = ( "The agent phase holds the model key only, and this environment holds {names}. Run the " "agent phase in a container with no App key and no GitHub token. This process ran no step." diff --git a/src/devops_cli/roadmap/failure.py b/src/devops_cli/roadmap/failure.py index 7ee6a57f5d..8f3f6cee89 100644 --- a/src/devops_cli/roadmap/failure.py +++ b/src/devops_cli/roadmap/failure.py @@ -10,7 +10,7 @@ **Typed classes.** A stop site that knows its cause passes the class itself: `no_change_in_fix`, `tests_lost`, `head_moved`, `output_cap`, `limit_reached` and `outside_plan` come from the step, and -`git_config` from the check of the git settings of the implement job; no rule below makes them, +`git_config` from a `shallow` file of the clone that is a link; no rule below makes them, except the rule of an evicted pod, which gives `limit_reached` (#5960). A command of the implement job that the process runner refuses (`SecurityError`) gives `refused_tool`, which a rule below also reads from the text. A pull request title or body that breaks a form rule two times gives diff --git a/src/devops_cli/roadmap/implement/git_isolation.py b/src/devops_cli/roadmap/implement/git_isolation.py index 017a8ffa1e..3d814e6db8 100644 --- a/src/devops_cli/roadmap/implement/git_isolation.py +++ b/src/devops_cli/roadmap/implement/git_isolation.py @@ -1,4 +1,4 @@ -"""The git calls of the implement job that reach `origin`, and the check of its git settings (GHSA). +"""The git calls of the implement job that reach `origin` (GHSA). **The invariant.** No git call that holds the GitHub token reads a configuration, hook, attribute or credential file that the agent can write, and no process that the agent, or a git call without @@ -9,9 +9,9 @@ git child that reaches a remote (`git_reaches_remote`), so a local git call of the job, such as `git add` or `git commit`, holds none. -**A network call** (`OriginGit`) ends every leftover process of the job, checks the settings of -the checkout, ends every leftover process again, and makes a new folder with `tempfile.mkdtemp`. In it, a new bare git folder gets the -object folder of the clone as a link, and an empty folder becomes the home folder of the call. A +**A network call** (`OriginGit`) ends every leftover process of the job, and makes a new folder +with `tempfile.mkdtemp`. In it, a new bare git folder gets the object folder of the clone as a +link, and an empty folder becomes the home folder of the call. A fetch first gets the remote-tracking refs of the clone, so that it asks only for the objects that the clone lacks. The new folder gets a copy of the `shallow` file of a shallow clone, and a fetch that changes it writes it back. Neither step follows a link at the `shallow` file or at a @@ -22,20 +22,11 @@ alone. The remote is the URL of `origin` that the job read before its first step. The job writes the remote-tracking ref that the call changed into the clone, and removes the folder. Every call but the one with the token runs with no token. - -**The check of the settings** (`check_settings`) reads the keys of the scopes `local` and -`worktree`, the attributes `filter`, `diff` and `merge` of each path that git would stage, and the -alternates file of the clone. A key outside `CONST_GIT_ALLOWED_SETTINGS`, a driver that git does -not define itself, or an alternates file raises `GitSettingsError`, which stops the item with the -failure class `git_config`. The error names each key or attribute, and never a value. A call with -the token reads none of these settings, so the check is a signal and a second guard. It runs only -in a runner, as `end_leftover_processes` does: a person can keep a filter of their own. """ from __future__ import annotations import errno -import fnmatch import os import shutil import stat @@ -47,12 +38,6 @@ from devops_cli.config.commands import BIN_GIT from devops_cli.config.constants import ( - CONST_GIT_ALLOWED_SETTING_PATTERNS, - CONST_GIT_ALLOWED_SETTINGS, - CONST_GIT_ALTERNATES_FILE, - CONST_GIT_ATTRIBUTE_DRIVERS, - CONST_GIT_ATTRIBUTE_STATES, - CONST_GIT_BUILTIN_DRIVERS, CONST_GIT_ISOLATED_CONFIG_ENV, CONST_GIT_NONINTERACTIVE_ENV, CONST_GIT_SHALLOW_FILE, @@ -69,18 +54,16 @@ # The operation that a failed call names; the value of `implement.GIT_OPERATION`. _OPERATION = "roadmap.implement" -# The scopes of `git config --list --show-scope` that the clone and its worktree hold. -_CHECKED_SCOPES = frozenset({"local", "worktree"}) _ORIGIN_REFS = "refs/remotes/origin/" -def _git(where: Sequence[str], *args: str, stdin: str | None = None, isolated: bool = True) -> str: - """The output of a git call with no token: `git `. `isolated` turns the global - and the system configuration off. Raises `GitOperationError` with git's reason, masked.""" +def _git(where: Sequence[str], *args: str, stdin: str | None = None) -> str: + """The output of a git call with no token: `git `, with the global and the system + configuration off. Raises `GitOperationError` with git's reason, masked.""" proc = run_subprocess( [BIN_GIT, *where, *args], input=stdin, - env=dict(CONST_GIT_ISOLATED_CONFIG_ENV) if isolated else None, + env=dict(CONST_GIT_ISOLATED_CONFIG_ENV), check=False, quiet=True, ) @@ -106,81 +89,6 @@ def _sweep() -> None: process_hardening.end_leftover_processes() -# ── The check of the settings ───────────────────────────────────────────────────────────── - - -def _allowed(key: str) -> bool: - return key in CONST_GIT_ALLOWED_SETTINGS or any( - fnmatch.fnmatchcase(key, pattern) for pattern in CONST_GIT_ALLOWED_SETTING_PATTERNS - ) - - -def _refused_keys(checkout: Path) -> list[str]: - """The keys of the scopes `local` and `worktree` outside the allowlist, each once. The keys of a - file that `include.path` names have the scope of the file that includes it.""" - listed = _git(["-C", str(checkout)], "config", "--list", "--show-scope", "-z", isolated=False) - fields = listed.split("\0") - keys = ( - entry.partition("\n")[0] - for scope, entry in zip(fields[0::2], fields[1::2], strict=False) - if scope in _CHECKED_SCOPES - ) - return list(dict.fromkeys(key for key in keys if not _allowed(key))) - - -def _driver_refused(attribute: str, value: str) -> bool: - return value not in CONST_GIT_ATTRIBUTE_STATES and value not in CONST_GIT_BUILTIN_DRIVERS.get( - attribute, frozenset() - ) - - -def _refused_attributes(checkout: Path) -> list[str]: - """The attributes of `CONST_GIT_ATTRIBUTE_DRIVERS` that name a driver that git does not define, - each with the first path that has it and the count of the others. `git check-attr` reads every - attribute file that git reads for a path.""" - where = ["-C", str(checkout)] - listed = _git(where, "ls-files", "-z", "--cached", "--others", "--exclude-standard") - if not listed: - return [] - found = _git(where, "check-attr", "-z", "--stdin", *CONST_GIT_ATTRIBUTE_DRIVERS, stdin=listed) - fields = found.split("\0") - paths: dict[str, list[str]] = {} - for path, attribute, value in zip(fields[0::3], fields[1::3], fields[2::3], strict=False): - if _driver_refused(attribute, value): - paths.setdefault(attribute, []).append(path) - return [ - MESSAGES.roadmap.implement_git_attribute_refused.format( - attribute=attribute, path=min(held), more=len(held) - 1 - ) - for attribute, held in paths.items() - ] - - -def refused_settings(checkout: Path) -> list[str]: - """What the git settings of `checkout` hold that the implement job does not allow: each key, - each attribute with its first path, and the alternates file. Empty when it allows them all.""" - alternates = _common_dir(checkout) / CONST_GIT_ALTERNATES_FILE - return [ - *_refused_keys(checkout), - *_refused_attributes(checkout), - *([CONST_GIT_ALTERNATES_FILE] if alternates.exists() else []), - ] - - -def check_settings(checkout: Path) -> None: - """In a runner, raise `GitSettingsError` when the git settings of `checkout` hold what the - implement job does not allow (`refused_settings`).""" - if not load_settings().roadmap.implement.in_runner: - return - refused = refused_settings(checkout) - if refused: - named = ", ".join(f"`{setting}`" for setting in refused) - raise GitSettingsError( - MESSAGES.roadmap.implement_git_settings_refused.format(settings=named), - settings=tuple(refused), - ) - - # ── The network calls ───────────────────────────────────────────────────────────────────── @@ -280,8 +188,8 @@ def call(self, *args: str) -> str: class OriginGit: """The git calls of the implement job that reach `origin` of the clone of `repository` (the clone or one of its worktrees), at `url`. Each call runs in a new git folder, as the module - text says. A call that git refuses raises `GitOperationError`, and a refused setting raises - `GitSettingsError` before any call.""" + text says. A call that git refuses raises `GitOperationError`, and a `shallow` file of the + clone that is a link raises `GitSettingsError`.""" repository: Path url: str @@ -289,12 +197,9 @@ class OriginGit: @contextmanager def _folder(self, *, refs: bool) -> Iterator[_Folder]: """A new git folder with the objects of the clone, and with its remote-tracking refs when - `refs` is true. The leftover processes end before the check of the settings, so that they - are gone also when the check stops the call, before the folder exists, and again before the + `refs` is true. The leftover processes end before the folder exists, and again before the caller runs the call with the token. The folder goes when the block ends.""" _sweep() - check_settings(self.repository) - _sweep() parent = Path(tempfile.mkdtemp(prefix="devops-origin-")) try: common = _common_dir(self.repository) @@ -355,4 +260,4 @@ def push(self, branch: str, tip: str | None, *, lease: str | None = None) -> Non _git(["-C", str(self.repository)], "update-ref", "--stdin", stdin=change) -__all__ = ["OriginGit", "check_settings", "origin_url", "refused_settings"] +__all__ = ["OriginGit", "origin_url"] diff --git a/src/devops_cli/roadmap/implement/implement_run.py b/src/devops_cli/roadmap/implement/implement_run.py index 72b256464b..8a2e50d42c 100644 --- a/src/devops_cli/roadmap/implement/implement_run.py +++ b/src/devops_cli/roadmap/implement/implement_run.py @@ -12,8 +12,8 @@ other child (`uv`, `ruff`) get none. Each git call that reaches `origin` runs through `OriginGit` (`git_isolation.py`, GHSA): in a new git folder, with no configuration, hook or attribute file that the agent can write, after the job ends every leftover process (`end_leftover_processes`). The job -also ends every process of a step when the step ends, and checks the git settings of the checkout -(`check_settings`): a setting that it does not allow stops the item with the class `git_config`. +also ends every process of a step when the step ends. A `shallow` file of the clone that is a link +stops the item with the class `git_config`. **One item.** The job takes over the staged branch in a worktree, sets Status In Progress and rebases onto the fetched default branch. It runs one step for each group that has an unticked @@ -2054,8 +2054,8 @@ def end_stopped(self, stop: _StopError) -> ImplementResult: # ── The stop ── def stop(self, stop: _StopError) -> None: - """Push what passed, tell the item why, set it Blocked, and record the step. A git setting - that the job does not allow stops the push, and the class of the stop is `git_config`. + """Push what passed, tell the item why, set it Blocked, and record the step. A `shallow` file + of the clone that is a link stops the push, and the class of the stop is `git_config`. First it writes the disk use of the home volume at the step to the Job log (#6076). The stop comment on the issue is the one copy of the stop report; the comment of the run on the pull request links it (#6194).""" @@ -2211,9 +2211,9 @@ def _push_passed(self, *, at_stop: bool = False) -> str: with none, nothing is pushed. A rebase conflict aborts the rebase, pushes the head with a lease, records the conflicting paths in `implement.conflict`, and returns an empty text (#5615). `at_stop` is true for the push of a stop, which drops what no commit holds first. - The text to add to the comment when the push fails, else empty. A git setting that the job does not allow raises - `GitSettingsError`: the item stops with the class `git_config`, and the job writes no - record of the push first.""" + The text to add to the comment when the push fails, else empty. A `shallow` file of the + clone that is a link raises `GitSettingsError`: the item stops with the class `git_config`, + and the job writes no record of the push first.""" texts = MESSAGES.roadmap try: if self.pull is None and not self._has_new_commits(): @@ -2254,10 +2254,10 @@ def _earlier_stop(check_log: str | None, conflict: str | None) -> EarlierStop | def _failure_class_of(exc: Exception) -> FailureClass | None: - """The class of a stop that `exc` causes, when the error knows it: a git setting that the job - does not allow is `git_config` (GHSA), and a command that the process runner refuses before it - starts (`SecurityError`) is `refused_tool`, as a new runner image meets the same refusal - (#5887). None lets the classifier read the text.""" + """The class of a stop that `exc` causes, when the error knows it: a `shallow` file of the + clone that is a link is `git_config` (GHSA), and a command that the process runner refuses + before it starts (`SecurityError`) is `refused_tool`, as a new runner image meets the same + refusal (#5887). None lets the classifier read the text.""" if isinstance(exc, GitSettingsError): return FailureClass.GIT_CONFIG if isinstance(exc, SecurityError): @@ -2266,9 +2266,9 @@ def _failure_class_of(exc: Exception) -> FailureClass | None: def _error_stop(step: str, exc: Exception, *, kept_branch: bool = False) -> _StopError: - """The stop that an error ends the run with: its class and its message, secrets masked. A git - setting that the job does not allow stops with the class `git_config` and pushes nothing: the - push would meet the same setting.""" + """The stop that an error ends the run with: its class and its message, secrets masked. A + `shallow` file of the clone that is a link stops with the class `git_config` and pushes + nothing: the push would meet the same link.""" reason = MESSAGES.roadmap.implement_stop_error.format( error=type(exc).__name__, message=mask_secrets(str(exc)) ) diff --git a/src/devops_cli/roadmap/implement/implement_step.py b/src/devops_cli/roadmap/implement/implement_step.py index a2adae9695..5fbbfccb20 100644 --- a/src/devops_cli/roadmap/implement/implement_step.py +++ b/src/devops_cli/roadmap/implement/implement_step.py @@ -117,7 +117,6 @@ classify_failure, ) from devops_cli.roadmap.fence import code_fence -from devops_cli.roadmap.implement.git_isolation import check_settings from devops_cli.roadmap.implement.implement_base_replay import ( BaseReplay, BaseStatus, @@ -1973,19 +1972,14 @@ def _turn( message: str, conversation: Conversation | None = None, *, - source: Path, usage_limits: UsageLimits, ) -> _Run: """One turn of the agent under `usage_limits`. When it ends, so does every process of the - agent's shell, before the job runs a program that gets the session's token. Then, in a runner, - the git settings of the checkout `source` are checked before the job runs git there again: a - setting that the job does not allow raises `GitSettingsError` (GHSA).""" + agent's shell, before the job runs a program that gets the session's token.""" try: - run = _run_agent(agent, model, log, message, conversation, usage_limits=usage_limits) + return _run_agent(agent, model, log, message, conversation, usage_limits=usage_limits) finally: _end_agent_processes() - check_settings(source) - return run def _tree(source: Path) -> str: @@ -2099,7 +2093,6 @@ def _extra_turn( log, ask.message, first.conversation, - source=source, usage_limits=usage_limits, ) ) @@ -2336,7 +2329,7 @@ def _attempt( log.fail_to_pass = None log.verified.clear() log.parser_failures = 0 - run = _turn(agent, tier_model, log, message, source=source, usage_limits=usage_limits) + run = _turn(agent, tier_model, log, message, usage_limits=usage_limits) first_request = first_request or run.first_request_tokens failure = ( _Failure(run.reason, klass=run.failure_class) diff --git a/tests/roadmap/implement/test_roadmap_implement_checkpoint.py b/tests/roadmap/implement/test_roadmap_implement_checkpoint.py index 2ae337565b..47fd8e6e54 100644 --- a/tests/roadmap/implement/test_roadmap_implement_checkpoint.py +++ b/tests/roadmap/implement/test_roadmap_implement_checkpoint.py @@ -23,6 +23,7 @@ TASKS_PATH, JobWorld, advance_main, + link_shallow, ) from tests.support.roadmap_stage import STAGE_REPO, run_git @@ -509,16 +510,13 @@ def test_a_withdraw_after_a_refused_draft_finds_no_branch_and_does_nothing( assert planned_world.sent("PATCH", f"pulls/{PULL}") == [] -def test_a_checkpoint_that_meets_a_refused_setting_stops_the_item_at_once( +def test_a_checkpoint_that_meets_a_link_at_the_shallow_file_stops_the_item_at_once( job_world: JobWorld, ) -> None: - """The agent writes a git setting that the job refuses in group 1. The checkpoint before + """The agent makes the `shallow` file of the clone a link in group 1. The checkpoint before group 2 stops the item with the class `git_config`, and the job asks the model for nothing more (#6559: the checkpoint is the push between the steps).""" - script = _script( - *_passes(1, GROUPS), - at1=lambda: job_world.repo.git("config", "credential.helper", "example-value-7"), - ) + script = _script(*_passes(1, GROUPS), at1=lambda: link_shallow(job_world.repo)) applied = job_world.run(script) diff --git a/tests/roadmap/implement/test_roadmap_implement_git_isolation.py b/tests/roadmap/implement/test_roadmap_implement_git_isolation.py index 8ff388cf0e..b30217e725 100644 --- a/tests/roadmap/implement/test_roadmap_implement_git_isolation.py +++ b/tests/roadmap/implement/test_roadmap_implement_git_isolation.py @@ -1,4 +1,4 @@ -"""The network git calls of the implement job and the check of the git settings (GHSA). +"""The network git calls of the implement job (GHSA). `OriginGit` runs each call that reaches `origin` in a new git folder, with the token, and reads no configuration file, hook or credential helper of the home folder or of the clone. Git runs for @@ -21,19 +21,17 @@ from devops_cli.core import process_hardening from devops_cli.exceptions import GitOperationError from devops_cli.exceptions.roadmap import GitSettingsError -from devops_cli.git.worktree_add import worktree_directory from devops_cli.roadmap.implement import git_isolation -from devops_cli.roadmap.implement.git_isolation import OriginGit, refused_settings +from devops_cli.roadmap.implement.git_isolation import OriginGit from tests.support.fakes.process import ProcessAnswer, ProcessCall, ProcessFake from tests.support.implement_step import git_for_real from tests.support.model_script import ModelScript, say, tool_calls -from tests.support.roadmap_implement import JobWorld, group_one_calls +from tests.support.roadmap_implement import JobWorld, group_one_calls, link_shallow from tests.support.roadmap_stage import StageRepo, run_git pytestmark = pytest.mark.usefixtures("keyring_store") BRANCH = "fix/1-the-job-drops-a-comment" -VALUE = "example-value-7" def _recorder(path: Path, capture: Path, name: str) -> Path: @@ -181,6 +179,54 @@ def test_a_push_to_a_server_that_asks_for_credentials_asks_no_planted_helper_and assert [headers for headers in seen if "Authorization" in headers] == [] +@pytest.mark.parametrize( + "lines", + [ + '[url "{url}"]\n\tinsteadOf = {origin}\n', + '[url "{url}"]\n\tpushInsteadOf = {origin}\n', + '[remote "origin"]\n\tpushurl = {url}\n', + ], + ids=["insteadOf", "pushInsteadOf", "pushurl"], +) +def test_a_push_sends_nothing_to_a_url_that_the_home_folder_or_the_clone_names( + stage_repo: StageRepo, + work: str, + planted: Callable[[str], None], + capture: Path, + challenge: tuple[str, list[dict[str, str]]], + lines: str, +) -> None: + """An `insteadOf`, a `pushInsteadOf` or a `pushurl` in the home folder and in the clone names a + server that asks for credentials. The push goes to `origin`, and the server gets no request, so + it gets no token.""" + url, seen = challenge + planted(lines.format(url=url, origin=stage_repo.origin)) + + OriginGit(stage_repo.clone, str(stage_repo.origin)).push(BRANCH, work) + + assert run_git(stage_repo.origin, "rev-parse", f"refs/heads/{BRANCH}") == work + assert (seen, _seen(capture)) == ([], "") + + +def test_a_push_runs_no_hook_of_the_hooks_folder_of_the_clone( + stage_repo: StageRepo, work: str, capture: Path +) -> None: + """git looks for a hook in the hooks folder of the clone when no `core.hooksPath` is set. A + `pre-push` hook there does not run, and the branch is on `origin`.""" + hooks = Path( + run_git(stage_repo.clone, "rev-parse", "--path-format=absolute", "--git-path", "hooks") + ) + hooks.mkdir(parents=True, exist_ok=True) + _recorder(hooks / "pre-push", capture, "pre-push") + + OriginGit(stage_repo.clone, str(stage_repo.origin)).push(BRANCH, work) + + assert (run_git(stage_repo.origin, "rev-parse", f"refs/heads/{BRANCH}"), _seen(capture)) == ( + work, + "", + ) + + def test_a_fetch_writes_the_new_objects_and_the_ref_into_the_clone(stage_repo: StageRepo) -> None: other = stage_repo.origin.parent / "other" run_git(other.parent, "clone", "-q", str(stage_repo.origin), str(other)) @@ -247,17 +293,16 @@ def git(call: ProcessCall) -> subprocess.CompletedProcess[str]: return order -def test_the_leftover_processes_end_before_the_check_before_the_folder_and_before_the_token_call( +def test_the_leftover_processes_end_before_the_folder_and_before_the_token_call( stage_repo: StageRepo, recorded: list[str], process_fake: ProcessFake ) -> None: OriginGit(stage_repo.clone, str(stage_repo.origin)).fetch("main") token_call = recorded.index("fetch") - first, second, third = (i for i, word in enumerate(recorded) if word == "sweep") - assert "config" in recorded[first:second] + first, second = (i for i, word in enumerate(recorded) if word == "sweep") assert first == 0 - assert second < recorded.index("mkdtemp") < recorded.index("update-ref") < third - assert third == token_call - 1 + assert first < recorded.index("mkdtemp") < recorded.index("update-ref") < second + assert second == token_call - 1 fetch = next(call for call in process_fake.calls if _words(call) == "fetch") assert fetch.env is not None assert {key: fetch.env.get(key) for key in ("GIT_CONFIG_GLOBAL", "GIT_CONFIG_NOSYSTEM")} == { @@ -273,18 +318,18 @@ def test_the_leftover_processes_end_before_the_check_before_the_folder_and_befor assert not Path(fetch.env["HOME"]).exists() -def test_a_refused_setting_ends_the_leftover_processes_before_the_check( +def test_a_link_at_the_shallow_file_ends_the_leftover_processes_before_the_refusal( stage_repo: StageRepo, recorded: list[str] ) -> None: - """A refused setting stops the call before the folder exists. The leftover processes end first - all the same, because the job writes to GitHub after the stop.""" - run_git(stage_repo.clone, "config", "credential.helper", VALUE) + """A link at the `shallow` file stops the call before the call with the token. The leftover + processes end first all the same, because the job writes to GitHub after the stop.""" + link_shallow(stage_repo) with pytest.raises(GitSettingsError) as refused: OriginGit(stage_repo.clone, str(stage_repo.origin)).fetch("main") - assert (refused.value.settings, recorded[0], "mkdtemp" in recorded) == ( - ("credential.helper",), + assert (refused.value.settings, recorded[0], "fetch" in recorded) == ( + ("shallow",), "sweep", False, ) @@ -304,85 +349,19 @@ def test_a_push_gives_the_token_only_to_the_call_in_the_new_folder( assert recorded[recorded.index("push") - 1] == "sweep" -# ── The settings check ──────────────────────────────────────────────────────────────────── - - -def test_the_settings_of_a_new_clone_pass_the_check(stage_repo: StageRepo) -> None: - assert refused_settings(stage_repo.clone) == [] - - -def test_an_alternates_file_of_the_clone_is_refused(stage_repo: StageRepo, tmp_path: Path) -> None: - (stage_repo.clone / ".git" / "objects" / "info" / "alternates").write_text( - f"{tmp_path}\n", encoding="utf-8" - ) - - assert refused_settings(stage_repo.clone) == ["objects/info/alternates"] - - -@pytest.mark.parametrize( - ("settings", "attributes", "named"), - [ - ({"filter.x.clean": VALUE}, "* filter=x\n", ["filter.x.clean", "filter ("]), - ({"gpg.program": VALUE, "commit.gpgsign": "true"}, "", ["gpg.program"]), - ({"credential.helper": VALUE}, "", ["credential.helper"]), - ], - ids=["filter", "gpg", "helper"], -) -def test_a_setting_that_a_turn_writes_stops_the_item_with_the_class_git_config( - job_world: JobWorld, settings: dict[str, str], attributes: str, named: list[str] -) -> None: - """The agent writes a setting in its turn. The item stops with the class `git_config` before - the job runs `git add`, `git commit`, `git push` or `git fetch` again, and the comment names - each key and holds no value.""" - planted_at: list[int] = [] - - def plant() -> None: - for key, value in settings.items(): - job_world.repo.git("config", key, value) - if attributes: - (worktree_directory(1, job_world.repo.clone) / ".gitattributes").write_text( - attributes, encoding="utf-8" - ) - planted_at.append(len(job_world.programs.calls)) - - script = ModelScript( - tool_calls(*group_one_calls()), say("Group 1 is done."), effects={2: plant} - ) - - applied = job_world.run(script) - - held = job_world.store.item(1) - assert held is not None - after = [_words(call) for call in job_world.programs.calls[planted_at[0] :]] - comment = job_world.issue_comments()[-1] - assert (applied.stopped, held.status, held.job_record.get("implement.failure")) == ( - (1,), - "Blocked", - "git_config", - ) - assert {"add", "commit", "push", "fetch", "ls-remote"} & set(after) == set() - assert ([name for name in named if name not in comment], VALUE in comment) == ([], False) - - -def test_the_check_runs_only_in_a_runner(stage_repo: StageRepo) -> None: - """A person can keep a global filter, so outside a runner the check refuses nothing.""" - run_git(stage_repo.clone, "config", "credential.helper", VALUE) - - git_isolation.check_settings(stage_repo.clone) - - assert refused_settings(stage_repo.clone) == ["credential.helper"] +# ── The shallow file ────────────────────────────────────────────────────────────────────── -def test_a_setting_that_an_exit_check_writes_stops_the_push_of_the_stop_with_the_class_git_config( +def test_a_link_that_an_exit_check_writes_at_the_shallow_file_stops_the_push_of_the_stop( job_world: JobWorld, config: Callable[..., Path] ) -> None: - """An exit check of the step runs code of the checkout after the check of the turn. It writes a - setting and fails, and no repair round is left. The push of the stop meets the setting: the - item stops with the class `git_config`, and the comment names the key and holds no value.""" + """An exit check of the step runs code of the checkout. It makes the `shallow` file of the + clone a link and fails, and no repair round is left. The push of the stop meets the link: the + item stops with the class `git_config`, and the comment names `shallow`.""" config(roadmap={"implement": {"in_runner": True, "repair_rounds": 0}}) def lint(call: ProcessCall) -> subprocess.CompletedProcess[str]: - job_world.repo.git("config", "credential.helper", VALUE) + link_shallow(job_world.repo) return subprocess.CompletedProcess(list(call.argv), 1, "E999 example\n", "") job_world.programs.answer( @@ -397,7 +376,7 @@ def lint(call: ProcessCall) -> subprocess.CompletedProcess[str]: assert held is not None comment = job_world.issue_comments()[-1] assert (applied.stopped, held.job_record.get("implement.failure")) == ((1,), "git_config") - assert ("credential.helper" in comment, VALUE in comment) == (True, False) + assert "`shallow`" in comment def test_a_fetch_in_a_shallow_clone_gets_the_new_commit( diff --git a/tests/roadmap/test_roadmap_faults.py b/tests/roadmap/test_roadmap_faults.py index ed8833818d..f4e0320244 100644 --- a/tests/roadmap/test_roadmap_faults.py +++ b/tests/roadmap/test_roadmap_faults.py @@ -34,6 +34,7 @@ JobWorld, archive_effect, group_one_calls, + link_shallow, two_groups, ) @@ -288,14 +289,10 @@ def archive_with_why(call: ProcessCall) -> subprocess.CompletedProcess[str]: def _setup_git_config(world: JobWorld, config: Callable[..., Path]) -> ModelScript: config(roadmap={"implement": {"in_runner": True}}) - def set_config() -> None: - wt = worktree_directory(world.number, world.repo.clone) - subprocess.run(["git", "config", "credential.helper", "store"], cwd=wt, check=True) - return ModelScript( tool_calls(*group_one_calls()), say("Group 1 is done."), - effects={1: set_config}, + effects={1: lambda: link_shallow(world.repo)}, ) diff --git a/tests/support/roadmap_implement.py b/tests/support/roadmap_implement.py index b1722db716..2a819687a9 100644 --- a/tests/support/roadmap_implement.py +++ b/tests/support/roadmap_implement.py @@ -505,6 +505,14 @@ def advance_main(world: JobWorld, name: str = "main-moved.txt", text: str = "Mai world.repo.git("push", "-q", "origin", "main") +def link_shallow(repo: StageRepo) -> None: + """What the agent can do and no git command does: make the `shallow` file of the clone a link, + here to no file. A network git call of the job refuses it (`GitSettingsError`).""" + shallow = repo.clone / ".git" / "shallow" + if not shallow.is_symlink(): + shallow.symlink_to(repo.clone.parent / "absent") + + @dataclass class JobWorld: """A Staged item, its repository, GitHub and the process edge, ready for a run.""" From 491de52ea7c2d004a2c8573da29c04f1e328c835 Mon Sep 17 00:00:00 2001 From: Daniel Petty Date: Sat, 21 Nov 2026 16:28:07 +0000 Subject: [PATCH 2/3] docs(openspec): archive 6638-delete-check-settings --- .../.openspec.yaml | 0 .../design.md | 0 .../proposal.md | 0 .../specs/roadmap-implement-runner/spec.md | 0 .../tasks.md | 0 .../specs/roadmap-implement-runner/spec.md | 47 +++++++------------ 6 files changed, 16 insertions(+), 31 deletions(-) rename openspec/changes/{6638-delete-check-settings => archive/2026-11-21-6638-delete-check-settings}/.openspec.yaml (100%) rename openspec/changes/{6638-delete-check-settings => archive/2026-11-21-6638-delete-check-settings}/design.md (100%) rename openspec/changes/{6638-delete-check-settings => archive/2026-11-21-6638-delete-check-settings}/proposal.md (100%) rename openspec/changes/{6638-delete-check-settings => archive/2026-11-21-6638-delete-check-settings}/specs/roadmap-implement-runner/spec.md (100%) rename openspec/changes/{6638-delete-check-settings => archive/2026-11-21-6638-delete-check-settings}/tasks.md (100%) diff --git a/openspec/changes/6638-delete-check-settings/.openspec.yaml b/openspec/changes/archive/2026-11-21-6638-delete-check-settings/.openspec.yaml similarity index 100% rename from openspec/changes/6638-delete-check-settings/.openspec.yaml rename to openspec/changes/archive/2026-11-21-6638-delete-check-settings/.openspec.yaml diff --git a/openspec/changes/6638-delete-check-settings/design.md b/openspec/changes/archive/2026-11-21-6638-delete-check-settings/design.md similarity index 100% rename from openspec/changes/6638-delete-check-settings/design.md rename to openspec/changes/archive/2026-11-21-6638-delete-check-settings/design.md diff --git a/openspec/changes/6638-delete-check-settings/proposal.md b/openspec/changes/archive/2026-11-21-6638-delete-check-settings/proposal.md similarity index 100% rename from openspec/changes/6638-delete-check-settings/proposal.md rename to openspec/changes/archive/2026-11-21-6638-delete-check-settings/proposal.md diff --git a/openspec/changes/6638-delete-check-settings/specs/roadmap-implement-runner/spec.md b/openspec/changes/archive/2026-11-21-6638-delete-check-settings/specs/roadmap-implement-runner/spec.md similarity index 100% rename from openspec/changes/6638-delete-check-settings/specs/roadmap-implement-runner/spec.md rename to openspec/changes/archive/2026-11-21-6638-delete-check-settings/specs/roadmap-implement-runner/spec.md diff --git a/openspec/changes/6638-delete-check-settings/tasks.md b/openspec/changes/archive/2026-11-21-6638-delete-check-settings/tasks.md similarity index 100% rename from openspec/changes/6638-delete-check-settings/tasks.md rename to openspec/changes/archive/2026-11-21-6638-delete-check-settings/tasks.md diff --git a/openspec/specs/roadmap-implement-runner/spec.md b/openspec/specs/roadmap-implement-runner/spec.md index c549878b91..916fc2a7fb 100644 --- a/openspec/specs/roadmap-implement-runner/spec.md +++ b/openspec/specs/roadmap-implement-runner/spec.md @@ -229,16 +229,24 @@ The implement job SHALL run each git call that reaches `origin`, also the calls - **WHEN** the configuration of the clone sets `core.hooksPath` to a folder with a `pre-push` hook, and the job pushes to a bare repository on disk - **THEN** the branch is on the bare repository, and the hook did not run +#### Scenario: A pre-push hook in the hooks folder of the clone +- **WHEN** the hooks folder of the clone holds a `pre-push` hook, no `core.hooksPath` is set, and the job pushes to a bare repository on disk +- **THEN** the branch is on the bare repository, and the hook did not run + +#### Scenario: A URL that the home folder or the clone names +- **WHEN** the home folder and the configuration of the clone hold an `insteadOf`, a `pushInsteadOf` or a `pushurl` that names a loopback server that asks for credentials, and the job pushes to a bare repository on disk +- **THEN** the branch is on the bare repository, and the server receives no request + ### Requirement: The leftover processes end before each part of a network git call -`OriginGit` SHALL end every leftover process before the check of the settings, again before it makes the new folder, and again just before the call with the token. A refused setting SHALL stop the call after the first sweep and before the folder exists. +`OriginGit` SHALL end every leftover process before it makes the new folder, and again just before the call with the token. #### Scenario: The order of the calls - **WHEN** the job fetches a branch -- **THEN** the leftover processes end before the check of the settings, again after the check and before the new folder is made, again after the refs are copied, and only then the fetch with the token runs +- **THEN** the leftover processes end before the new folder is made, again after the refs are copied, and only then the fetch with the token runs #### Scenario: A refused setting before the call -- **WHEN** the configuration of the clone holds `credential.helper`, and the job fetches a branch in a runner -- **THEN** the leftover processes end before the check, the call raises `GitSettingsError` that names `credential.helper`, and no new folder is made +- **WHEN** the `shallow` file of the clone is a link, and the job fetches a branch in a runner +- **THEN** the leftover processes end first, the call raises `GitSettingsError` that names `shallow`, and the fetch with the token does not run ### Requirement: The new git folder of a shallow clone gets its shallow file The new git folder of a network call SHALL get a copy of the `shallow` file of a shallow clone, which the job SHALL open with `O_NOFOLLOW`. A link, or anything but a regular file, at that place SHALL raise `GitSettingsError` that names `shallow`. A fetch that changes the file SHALL write it back into the clone through a new file with a random name, which then replaces the old file (`os.replace`), so the write follows no link. @@ -255,29 +263,6 @@ The new git folder of a network call SHALL get a copy of the `shallow` file of a - **WHEN** a link waits at `shallow.devops-cli` in the git folder of the clone, and a fetch changes the `shallow` file - **THEN** the target of the link does not change, `shallow` is a regular file with the new text, and no temporary file stays -### Requirement: A git setting that the job does not allow stops the item -In a runner, the implement job SHALL check the git settings of the checkout when each turn of the agent ends and before each network git call (`check_settings`). A setting that the job does not allow SHALL stop the item with the failure class `git_config` and push nothing. The reason and the log line SHALL name each key, or each attribute with its path, and SHALL hold no value. - -#### Scenario: What the job does not allow -- **WHEN** the checkout holds a key of the scope `local` or `worktree` outside `CONST_GIT_ALLOWED_SETTINGS` and its patterns, an attribute `filter` with a value, an attribute `diff` that is no built-in pattern of git, an attribute `merge` other than `text`, `binary` and `union`, or the file `objects/info/alternates` of the clone -- **THEN** `refused_settings` names it - -#### Scenario: A filter -- **WHEN** a turn of the agent writes `filter.x.clean` into the configuration of the clone and `* filter=x` into `.gitattributes` -- **THEN** the item stops with the class `git_config`, the job runs no `git add`, `git commit`, `git push` or `git fetch` after the turn, and the comment names `filter.x.clean` and the attribute `filter` of `.gitattributes`, and holds no value of either - -#### Scenario: A GPG program -- **WHEN** a turn of the agent writes `gpg.program` and `commit.gpgsign` into the configuration of the clone -- **THEN** the item stops with the class `git_config`, and the comment names `gpg.program` and holds no value - -#### Scenario: A credential helper -- **WHEN** a turn of the agent adds `credential.helper` to the configuration of the clone -- **THEN** the item stops with the class `git_config`, and the comment names `credential.helper` and holds no value - -#### Scenario: The settings of a new clone -- **WHEN** the job runs an item in a clone that `git clone` made, with the identity that `ensure_checkout` sets -- **THEN** the check refuses no key - ### Requirement: Repository and item labels `build_job` SHALL set `roadmap.devops-cli/owner`, `roadmap.devops-cli/repo` and `roadmap.devops-cli/item` on the Job metadata and on the pod template metadata. @@ -462,15 +447,15 @@ The shell of the agent of a step, the `pre-commit` runs, the scoped checks, the - **THEN** the PATH of the shell starts with `node_modules/.bin` and `.venv/bin` of that checkout ### Requirement: A refused setting at a checkpoint or stop push stops the item at once -A refused setting at the push of a checkpoint SHALL stop the item with the class `git_config` at once, before the job writes a record of the push. A refused setting at the push of a stop SHALL give the stop the class `git_config`. +A `shallow` file of the clone that is a link, or is not a regular file, at the push of a checkpoint SHALL stop the item with the class `git_config` at once, before the job writes a record of the push. Such a file at the push of a stop SHALL give the stop the class `git_config`. #### Scenario: A setting before a checkpoint push -- **WHEN** the agent writes `credential.helper` into the configuration of the clone in group 1 of a change of four groups, and group 1 passes +- **WHEN** the agent makes the `shallow` file of the clone a link in group 1 of a change of four groups, and group 1 passes - **THEN** the checkpoint before group 2 stops the item with the class `git_config`, and the job asks the model for nothing more #### Scenario: A setting that an exit check writes -- **WHEN** an exit check of the step writes `credential.helper` into the configuration of the clone and fails, and no repair round is left -- **THEN** the item stops with the class `git_config`, and the comment names `credential.helper` and holds no value +- **WHEN** an exit check of the step makes the `shallow` file of the clone a link and fails, and no repair round is left +- **THEN** the item stops with the class `git_config`, and the comment names `shallow` ### Requirement: The runner image holds the scanners of a review The runner image SHALL hold Gitleaks, Pluto, osv-scanner, golangci-lint and Semgrep from the devtools image, at the versions of the installed tools. Each of the five SHALL be an entry of `RUNNER_TOOLS` with the source `ToolSource.DEVTOOLS` and SHALL NOT be an entry of `NOT_IN_RUNNER`. Each binary of the analyzer table of the review SHALL be an entry of `RUNNER_TOOLS`. From 3105a9f7b1716e1614629f31aaa6950ed787648d Mon Sep 17 00:00:00 2001 From: Daniel Petty Date: Sat, 21 Nov 2026 17:22:39 +0000 Subject: [PATCH 3/3] fix(roadmap): correct the review findings of the scan removal Delete the pushurl case, which OriginGit never reaches. Put back the Git LFS limit, rename the spec titles to the link at the shallow file, and make the texts of the design and of _commit true. --- SECURITY.md | 1 + docs/ROADMAP_WORKFLOW.md | 2 +- .../design.md | 2 +- .../proposal.md | 4 ++-- .../specs/roadmap-implement-runner/spec.md | 15 ++++++++++----- .../tasks.md | 2 +- openspec/specs/roadmap-implement-runner/spec.md | 10 +++++----- .../roadmap/implement/implement_step.py | 4 ++-- .../test_roadmap_implement_git_isolation.py | 9 ++++----- 9 files changed, 27 insertions(+), 22 deletions(-) diff --git a/SECURITY.md b/SECURITY.md index b94336e03d..c7a017608e 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -53,6 +53,7 @@ All code authored in or evaluated by DevOps CLI must strictly adhere to the foll - **A timeout.** Each child that gets the session's token starts in a session of its own. A timeout kills its whole process group, so no helper that the child started, such as `git-remote-https`, keeps the token in its environment. - **The implement job.** The agent of a step runs as the user of the Job, so it can write the git configuration of the home folder and of the clone, the hooks and the attribute files. Each git call of the job that reaches `origin` runs through `OriginGit` (`src/devops_cli/roadmap/implement/git_isolation.py`): in a new bare git folder that links the objects of the clone, with `GIT_CONFIG_GLOBAL=/dev/null`, `GIT_CONFIG_NOSYSTEM=1`, an empty home folder, an empty `credential.helper` before the trusted helper, no hooks, and the URL of `origin` that the job read before its first step. The job ends every leftover process before it makes the folder and again before the call. The new git folder gets a copy of the `shallow` file of a shallow clone, which the job opens with `O_NOFOLLOW`: a link there stops the item with `git_config`. A fetch that changes the file writes it back through a new file with a random name and `os.replace`, so the write follows no link. A verification command of a plan runs git only as the negative search `! git grep`, which reaches no remote: in the checkout, any other git call would read the configuration that the agent can write. - **Every child with the token in a runner.** The job also runs code of the checkout that the agent wrote: the tests, the hooks of `pre-commit` and the exit checks. In a runner, the process runner ends every leftover process of the job before and after each child that gets the session's token (a gh child, or a git child that reaches a remote), and before the token folder of a gh child exists. The sweep ends every descendant of the job, so a runner runs its children that get the token one at a time. A process that survives stops the item. + - **Limits.** A repository that keeps files in Git LFS cannot use the implement Job: `OriginGit` pushes with `core.hooksPath=/dev/null` and `--no-verify`, so no LFS object goes to the server, and the runner image sets up no `git-lfs`. - **The risk that stays.** The token is in the environment or in a file of the same user while a child runs, so a process of that user could read it. The job ends every process that it started before and after such a child, and the root file system and the folders of `PATH` of the runner image are read-only. `ensure_checkout` and `plan_implement` fetch in the clone with the token, before any step of an agent runs. A process that is killed while a gh child runs can leave the folder of that call: in a runner it is on an `emptyDir` that ends with the pod, and on a workstation it stays until a person removes it. The two-container Job of #3700 moves the token out of the reach of the agent. - **The tests.** `tests/core/test_process.py`, `tests/roadmap/implement/test_roadmap_implement_git_isolation.py` and `tests/roadmap/implement/test_roadmap_implement_token_isolation.py` fail when any of this breaks. diff --git a/docs/ROADMAP_WORKFLOW.md b/docs/ROADMAP_WORKFLOW.md index 073b9a9114..715538ba2b 100644 --- a/docs/ROADMAP_WORKFLOW.md +++ b/docs/ROADMAP_WORKFLOW.md @@ -462,7 +462,7 @@ The runner Job runs the checks that a person runs in the devcontainer, from the - **After the push.** The Job sets the title and the body of the draft, comments the steps on it, records `implement.result` as `drafted`, sets Status In Review and ends (#6559). It watches no check and marks nothing ready. The checks of the pull request stay the gate. Before the end, the Job asks `draft_readiness` with no check runs, as its step `ready` did: a missing change, a group that is not ticked, a change that is not archived or a stage prompt with no eval scores stops the item. In mode `on` of `roadmap.fix_checks.mode`, the watch row runs the ready path of the step `fix-checks` on a green draft and starts a fix-checks Job for a failed check whose name gives the class `test`, `lint` or `types`; modes `off` and `plan` leave a green draft a draft. A failed or cancelled check, or a conflict, has a repair owner only when the mode is `on`, the class is one of these, and the fix-checks unit of the head and the check has not ended with no repair. In each other case the watch row stops the item: Status Blocked, `implement.stopped` at `pull request`, the class, `implement.result` stopped, and one stop comment that names the check or the conflict. The row judges the latest run of each check name. It leaves a draft that an owner label claims. A stopped item gets no ready mark and no fix-checks Job until `implement: retry` clears the stop. A Staged item that delivers on its plan pull request gets the same rules. - **Time.** The hooks add about 10 s to each step, and the install about 9 s. The scoped checks add about 35 s for the first two, and for the tests at most 30 test modules. On 2 CPUs, as in a Job, 12 test modules of the roadmap ran in 88 s, so the tests add at most about 3.5 minutes. The comment on the pull request gives the seconds of each scoped check. -- **Target repositories.** A shallow clone, which a run with `--source` can name, works: the network calls copy its `shallow` file. +- **Target repositories.** A shallow clone, which a run with `--source` can name, works: the network calls copy its `shallow` file. A repository that keeps files in Git LFS cannot use the implement Job: `OriginGit` pushes with `core.hooksPath=/dev/null` and `--no-verify`, so no LFS object goes to the server, and the runner image sets up no `git-lfs`. - **gh calls.** The Job, and each `devops` command, runs gh with a configuration folder of its own that holds only the token ([SECURITY.md](../SECURITY.md), item 15). A gh call reads no gh configuration of the person: no alias, pager, editor or `git_protocol`, and no login for a host other than github.com. Tests hold the drift: each local hook runs a tool that the runner image holds, each scoped row is a row of `devops ci`, and the branches of the Job pass the branch-name hook. diff --git a/openspec/changes/archive/2026-11-21-6638-delete-check-settings/design.md b/openspec/changes/archive/2026-11-21-6638-delete-check-settings/design.md index 13ca5816ce..250a05dcc5 100644 --- a/openspec/changes/archive/2026-11-21-6638-delete-check-settings/design.md +++ b/openspec/changes/archive/2026-11-21-6638-delete-check-settings/design.md @@ -3,7 +3,7 @@ ## Decisions - **`GitSettingsError` and `git_config` stay.** `_read_shallow` raises the error for a link, or anything but a regular file, at the `shallow` file of the clone. That handling stays until #3700, so the error, the class and the stop paths in `implement_run.py` stay for it. The tests of these stop paths now make the `shallow` file a link in place of a refused key. - **One sweep before the folder.** `OriginGit` ran a sweep, the scan and a second sweep. With no scan, the two sweeps ran one after the other, so one goes. The sweep before the call with the token stays. -- **`_git` loses `isolated`.** Only the scan read the configuration of the clone, with `isolated=False`. Each other call ran isolated. +- **`_git` loses `isolated`.** Only the scan read the global and the system configuration (`isolated=False`). Each other call turns them off. ## Rejected alternatives - **Keep the scan as a signal.** The audit of the git use of the roadmap Jobs and the owner decision on #6638 found that the scan protects no call with the token. It also starts a `core.fsmonitor` program before it refuses it, and it refuses Git LFS repositories, blobless clones and the `--shared` evaluation clone. diff --git a/openspec/changes/archive/2026-11-21-6638-delete-check-settings/proposal.md b/openspec/changes/archive/2026-11-21-6638-delete-check-settings/proposal.md index 8cc76ea83b..f8cb9e1acc 100644 --- a/openspec/changes/archive/2026-11-21-6638-delete-check-settings/proposal.md +++ b/openspec/changes/archive/2026-11-21-6638-delete-check-settings/proposal.md @@ -10,14 +10,14 @@ The scan protects no call with the token. `OriginGit` runs each fetch and push i - Delete the scan after each turn of the agent in `implement_step.py`, and the second sweep of `OriginGit` that ran after the scan. - Keep `OriginGit`, its isolated configuration, the sweeps, the `shallow` file handling and the URL pin until #3700. - Keep `GitSettingsError` and the class `git_config` for their one other raiser: a `shallow` file of the clone that is a link or is not a regular file. The stop paths in `implement_run.py` stay for it, and the message of the error names that file. -- Add tests that an `insteadOf`, a `pushInsteadOf`, a `pushurl` and a `pre-push` hook in the hooks folder of the clone get no request and do not run. +- Add tests that an `insteadOf`, a `pushInsteadOf` and a `pre-push` hook in the hooks folder of the clone get no request and do not run. - The change is observable: an item no longer stops on a git setting, so the spec `roadmap-implement-runner` gets a delta. ## Capabilities - `roadmap-implement-runner`: remove the requirement of the scan, and change the requirements of the sweeps, of the checkpoint and stop push, and of the network call. ## Impact -- A target repository with Git LFS, a blobless clone or a driver of its own can use the implement Job. +- An item no longer stops on a git key, an attribute driver, a blobless clone or an alternates file. A repository that keeps files in Git LFS still cannot use the implement Job: `OriginGit` pushes with `core.hooksPath=/dev/null` and `--no-verify`, so no LFS object goes to the server, and the runner image sets up no `git-lfs`. - The class `git_config` now comes only from a link at the `shallow` file. - The change fits one pull request. diff --git a/openspec/changes/archive/2026-11-21-6638-delete-check-settings/specs/roadmap-implement-runner/spec.md b/openspec/changes/archive/2026-11-21-6638-delete-check-settings/specs/roadmap-implement-runner/spec.md index 15894c3b1e..1e2a9dd2b4 100644 --- a/openspec/changes/archive/2026-11-21-6638-delete-check-settings/specs/roadmap-implement-runner/spec.md +++ b/openspec/changes/archive/2026-11-21-6638-delete-check-settings/specs/roadmap-implement-runner/spec.md @@ -1,3 +1,8 @@ +## RENAMED Requirements + +- FROM: `### Requirement: A refused setting at a checkpoint or stop push stops the item at once` +- TO: `### Requirement: A link at the shallow file at a checkpoint or stop push stops the item at once` + ## MODIFIED Requirements ### Requirement: A network git call of the implement job reads no file that the agent can write @@ -28,7 +33,7 @@ The implement job SHALL run each git call that reaches `origin`, also the calls - **THEN** the branch is on the bare repository, and the hook did not run #### Scenario: A URL that the home folder or the clone names -- **WHEN** the home folder and the configuration of the clone hold an `insteadOf`, a `pushInsteadOf` or a `pushurl` that names a loopback server that asks for credentials, and the job pushes to a bare repository on disk +- **WHEN** the home folder and the configuration of the clone hold an `insteadOf` or a `pushInsteadOf` that names a loopback server that asks for credentials, and the job pushes to a bare repository on disk - **THEN** the branch is on the bare repository, and the server receives no request ### Requirement: The leftover processes end before each part of a network git call @@ -38,18 +43,18 @@ The implement job SHALL run each git call that reaches `origin`, also the calls - **WHEN** the job fetches a branch - **THEN** the leftover processes end before the new folder is made, again after the refs are copied, and only then the fetch with the token runs -#### Scenario: A refused setting before the call +#### Scenario: A link at the shallow file before the call - **WHEN** the `shallow` file of the clone is a link, and the job fetches a branch in a runner - **THEN** the leftover processes end first, the call raises `GitSettingsError` that names `shallow`, and the fetch with the token does not run -### Requirement: A refused setting at a checkpoint or stop push stops the item at once +### Requirement: A link at the shallow file at a checkpoint or stop push stops the item at once A `shallow` file of the clone that is a link, or is not a regular file, at the push of a checkpoint SHALL stop the item with the class `git_config` at once, before the job writes a record of the push. Such a file at the push of a stop SHALL give the stop the class `git_config`. -#### Scenario: A setting before a checkpoint push +#### Scenario: A link before a checkpoint push - **WHEN** the agent makes the `shallow` file of the clone a link in group 1 of a change of four groups, and group 1 passes - **THEN** the checkpoint before group 2 stops the item with the class `git_config`, and the job asks the model for nothing more -#### Scenario: A setting that an exit check writes +#### Scenario: A link that an exit check writes - **WHEN** an exit check of the step makes the `shallow` file of the clone a link and fails, and no repair round is left - **THEN** the item stops with the class `git_config`, and the comment names `shallow` diff --git a/openspec/changes/archive/2026-11-21-6638-delete-check-settings/tasks.md b/openspec/changes/archive/2026-11-21-6638-delete-check-settings/tasks.md index 73fe0ca4c1..5d8dd29c1b 100644 --- a/openspec/changes/archive/2026-11-21-6638-delete-check-settings/tasks.md +++ b/openspec/changes/archive/2026-11-21-6638-delete-check-settings/tasks.md @@ -2,7 +2,7 @@ ## 1. The tests of the network call (tests) -- [x] 1.1 Add tests that an `insteadOf`, a `pushInsteadOf` and a `pushurl` of the home folder and of the clone get no request, and that a `pre-push` hook in the hooks folder of the clone does not run. +- [x] 1.1 Add tests that an `insteadOf` and a `pushInsteadOf` of the home folder and of the clone get no request, and that a `pre-push` hook in the hooks folder of the clone does not run. - Verification: `$ uv run devops ci test tests/roadmap/implement/test_roadmap_implement_git_isolation.py` ## 2. The deletion of the scan (refactor) diff --git a/openspec/specs/roadmap-implement-runner/spec.md b/openspec/specs/roadmap-implement-runner/spec.md index 916fc2a7fb..e212c242a4 100644 --- a/openspec/specs/roadmap-implement-runner/spec.md +++ b/openspec/specs/roadmap-implement-runner/spec.md @@ -234,7 +234,7 @@ The implement job SHALL run each git call that reaches `origin`, also the calls - **THEN** the branch is on the bare repository, and the hook did not run #### Scenario: A URL that the home folder or the clone names -- **WHEN** the home folder and the configuration of the clone hold an `insteadOf`, a `pushInsteadOf` or a `pushurl` that names a loopback server that asks for credentials, and the job pushes to a bare repository on disk +- **WHEN** the home folder and the configuration of the clone hold an `insteadOf` or a `pushInsteadOf` that names a loopback server that asks for credentials, and the job pushes to a bare repository on disk - **THEN** the branch is on the bare repository, and the server receives no request ### Requirement: The leftover processes end before each part of a network git call @@ -244,7 +244,7 @@ The implement job SHALL run each git call that reaches `origin`, also the calls - **WHEN** the job fetches a branch - **THEN** the leftover processes end before the new folder is made, again after the refs are copied, and only then the fetch with the token runs -#### Scenario: A refused setting before the call +#### Scenario: A link at the shallow file before the call - **WHEN** the `shallow` file of the clone is a link, and the job fetches a branch in a runner - **THEN** the leftover processes end first, the call raises `GitSettingsError` that names `shallow`, and the fetch with the token does not run @@ -446,14 +446,14 @@ The shell of the agent of a step, the `pre-commit` runs, the scoped checks, the - **WHEN** a step builds the shell of its agent for a checkout - **THEN** the PATH of the shell starts with `node_modules/.bin` and `.venv/bin` of that checkout -### Requirement: A refused setting at a checkpoint or stop push stops the item at once +### Requirement: A link at the shallow file at a checkpoint or stop push stops the item at once A `shallow` file of the clone that is a link, or is not a regular file, at the push of a checkpoint SHALL stop the item with the class `git_config` at once, before the job writes a record of the push. Such a file at the push of a stop SHALL give the stop the class `git_config`. -#### Scenario: A setting before a checkpoint push +#### Scenario: A link before a checkpoint push - **WHEN** the agent makes the `shallow` file of the clone a link in group 1 of a change of four groups, and group 1 passes - **THEN** the checkpoint before group 2 stops the item with the class `git_config`, and the job asks the model for nothing more -#### Scenario: A setting that an exit check writes +#### Scenario: A link that an exit check writes - **WHEN** an exit check of the step makes the `shallow` file of the clone a link and fails, and no repair round is left - **THEN** the item stops with the class `git_config`, and the comment names `shallow` diff --git a/src/devops_cli/roadmap/implement/implement_step.py b/src/devops_cli/roadmap/implement/implement_step.py index 5fbbfccb20..d7e7a54adc 100644 --- a/src/devops_cli/roadmap/implement/implement_step.py +++ b/src/devops_cli/roadmap/implement/implement_step.py @@ -1946,8 +1946,8 @@ def _read_discarded_diff(source: Path, start: str, reason: str) -> tuple[str, bo def _commit(source: Path, message: str) -> tuple[str, str]: """Commit the staged changes. The commit, and why the step stops when git refuses it. The - hooks of the repository ran as an exit check (`_hooks_failure`), and the job installs no git - hook, so the commit runs none.""" + hooks of the repository ran as an exit check (`_hooks_failure`). A hook that the agent wrote + runs at the commit, and it gets no token.""" done = _git(source, "commit", "-m", message) if done.returncode != 0: return "", MESSAGES.roadmap.implement_stop_commit_failed.format(output=_tail(done)) diff --git a/tests/roadmap/implement/test_roadmap_implement_git_isolation.py b/tests/roadmap/implement/test_roadmap_implement_git_isolation.py index b30217e725..382345ff68 100644 --- a/tests/roadmap/implement/test_roadmap_implement_git_isolation.py +++ b/tests/roadmap/implement/test_roadmap_implement_git_isolation.py @@ -184,9 +184,8 @@ def test_a_push_to_a_server_that_asks_for_credentials_asks_no_planted_helper_and [ '[url "{url}"]\n\tinsteadOf = {origin}\n', '[url "{url}"]\n\tpushInsteadOf = {origin}\n', - '[remote "origin"]\n\tpushurl = {url}\n', ], - ids=["insteadOf", "pushInsteadOf", "pushurl"], + ids=["insteadOf", "pushInsteadOf"], ) def test_a_push_sends_nothing_to_a_url_that_the_home_folder_or_the_clone_names( stage_repo: StageRepo, @@ -196,9 +195,9 @@ def test_a_push_sends_nothing_to_a_url_that_the_home_folder_or_the_clone_names( challenge: tuple[str, list[dict[str, str]]], lines: str, ) -> None: - """An `insteadOf`, a `pushInsteadOf` or a `pushurl` in the home folder and in the clone names a - server that asks for credentials. The push goes to `origin`, and the server gets no request, so - it gets no token.""" + """An `insteadOf` or a `pushInsteadOf` in the home folder and in the clone names a server that + asks for credentials. The push goes to `origin`, and the server gets no request, so it gets no + token.""" url, seen = challenge planted(lines.format(url=url, origin=stage_repo.origin))