Skip to content

fix: harden protected refs and credential environment auditing - #1382

Merged
max-sixty merged 5 commits into
mainfrom
codex/standard-hardening
Sep 22, 2026
Merged

max-sixty merged 5 commits into
mainfrom
codex/standard-hardening

Conversation

@max-sixty

@max-sixty max-sixty commented Sep 22, 2026 •

Copy link
Copy Markdown
Owner

Extract the general security hardening found while building #1172 so it can ship independently of yolo merge authority.

tend check now requires protected branches to restrict creation, updates, and deletion. --fix retains existing target patterns and exclusions alongside configured refs, so repair can strengthen protection without making old refs writable or unexpectedly restricting excluded work branches. Unreadable existing rulesets remain unverified rather than being reported as a definite policy failure.

Credential auditing compares environment names case-insensitively and no longer treats a ref-qualified reusable workflow as the current tree's copy. Setup validation also rejects action inputs attached to a run step. Installer instructions and regression tests match the tightened checks.

The standard workflow, proxy cache, runtime preflight, and bot merge authority are unchanged. This PR retains the existing single admin-gated Merge access ruleset; the two-mode policy stays in #1172. Merge this PR first, then update #1172 from main so yolo can be reverted independently. Both PRs target main because Tend's reviewer credential environment only admits that branch.

Validation: full Python and worker test suites, TypeScript typecheck, all pre-commit hooks, and independent review of the extraction and ruleset repair ordering.

This was written by Codex on behalf of max-sixty

@max-sixty max-sixty mentioned this pull request Sep 22, 2026

@tend-agent tend-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

tend check --fix can no longer repair branch protection on a repo whose Merge access ruleset covers a ref that protected_branches does not name — including this repo, today.

Live state here: repos/max-sixty/tend/rules/branches/main returns [{"type":"update"}], so check_branch_protection now fails on the new creation/deletion requirement. That ruleset's targets are ["~DEFAULT_BRANCH", "refs/heads/v1"], while .config/tend.yaml sets no protected_branches, so _put_ruleset's new gate sees a target the replacement would retire and returns before issuing the API call. Driving fix_branch_protection against that ruleset shape:

passed: False
message: Failed to set ruleset: Cannot safely retire or change existing protected refs. First remove or independently gate their access to credential environments (including tend), then manually retire the old ruleset targets. No rulesets changed.

check --fix leaves fixed_any false and exits 1 having changed nothing, so tend check is red and no --fix clears it. The message asks the admin to strip v1's credential access and hand-retire the target — giving up protection on v1 as a precondition for gaining it on main, which is the opposite of what this PR is for.

The narrower rule the gate is reaching for is "never drop a ref the ruleset already covers", and that is expressible as a union rather than a refusal: carry current["conditions"]["ref_name"]["include"] into the replacement body and re-serialize before the PUT. Nothing is retired, so the hazard in the docstring ("a newly writable branch with access to secrets") becomes unconstructible rather than merely reported, the admin needs no manual step, and preserved_refs — which exists only so an old literal refs/heads/<default> survives the swap to ~DEFAULT_BRANCH — goes away with it. It stays safe on the environment side because admitted_refs derives the deployment policy from branch-protection checks that passed, so a ref carried forward in the ruleset but absent from config is never admitted to tend.

Two smaller things at the same site, both resolved by that form:

  • The gate also refuses when the existing ruleset has a non-empty exclude, or any conditions key beyond ref_name. Replacing a ruleset that carries an exclude with one that carries none only widens coverage, so it retires nothing — the refusal is broader than the rationale it is documented with.
  • .claude/skills/running-tend/references/integration-test.md still stands up its Merge access fixture with "rules": [{ "type": "update" }], the shape check_branch_protection now rejects. The install-tend recipe was updated; this one was missed, so the weekly end-to-end test exercises an install that tend check would fail.

Happy to push the union change and the fixture line if you want them — say the word and I will.

What I verified against live GitHub

The tightened check depends on a GitHub behavior the test suite only fakes: whether creation and deletion rules are listed for a branch that already exists. They are. Standing up a creation/update/deletion ruleset on ~DEFAULT_BRANCH in tend-agent/tend-integration and reading rules/branches/main returned all three rules; the same endpoint for a non-existent branch returned []. The probe ruleset was deleted afterwards and that repo now lists none.

The conditions shape the gate pattern-matches on ({"ref_name": {"include": [...], "exclude": [...]}}, and nothing else) is what the repo-scoped ruleset endpoint returns, so the match itself is sound — the problem is only what it does when the match fails.

@tend-agent tend-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

--fix now preserves existing targets by unioning the include list, but it still writes exclude: [], so a repair widens the ruleset by exactly the branches the old exclusions kept out. Where the existing Merge access ruleset carries a broad include, that is every branch in the repo. Driving fix_branch_protection against include: ["~ALL"], exclude: ["refs/heads/tend/*"]:

passed: True
message: Replaced 'Merge access' ruleset — only admins can merge (main)
written conditions: {"ref_name": {"include": ["~DEFAULT_BRANCH", "~ALL"], "exclude": []}}
written rules: ['creation', 'update', 'deletion']

By this PR's own premise — update stops the bot pushing a covered branch and creation stops it making one — that ruleset leaves the bot unable to push or create the branches it opens PRs from, while --fix returns passed: True naming only main. The shape is reachable: I created include: ["~ALL"], exclude: ["refs/heads/dev/*"] as a branch-target ruleset on a repo I admin and read it back unchanged, so GitHub accepts it.

Carrying exclude forward as well drops the widening without giving up the retention property (inline suggestion). What that concedes is an exclusion exempting a configured protected branch — and that case is already safe: repos/{repo}/rules/branches/{branch} lists no rules for an excluded branch, so check_branch_protection reports it unverified, admitted_refs never admits it, and the environment policy never names it. A red check is the better failure mode than a silent repo-wide lockout that reports success. It also makes the exclude arm of supported_targets load-bearing: today those entries are validated and then discarded, so the only thing that validation can do is refuse a repair over a field the replacement drops. One test assertion moves with it — test_fix_branch_protection_preserves_existing_targets expects exclude: [].

Separately, the success message lists [default_branch] + extra from the config, so it never names the refs the repair carried forward — against this repo's current ruleset it retains refs/heads/v1 and prints (main). Now that retiring a target is a deliberate manual step, that message is the one place a maintainer would see the list; surfacing it means returning the written include from _put_ruleset, which is a third return value for a log line, so your call whether it earns that.

Happy to push the exclude change plus the test assertion if you want it.

Comment thread generator/src/tend/checks.py Resolved
Comment thread generator/src/tend/checks.py Resolved
@max-sixty
max-sixty merged commit 60c7445 into main Sep 22, 2026
12 checks passed
@max-sixty
max-sixty deleted the codex/standard-hardening branch September 22, 2026 19:58
max-sixty added a commit that referenced this pull request Sep 22, 2026
Add opt-in `merge: yolo` alongside the default `merge: maintainer`. Yolo
lets Tend merge ordinary pull requests without maintainer approval. The
bot receives a PR-only bypass on the default branch, with merges pinned
to the expected head SHA; it cannot push directly, administer the
repository, or update extra protected branches and tags.

Control-plane changes still require fresh maintainer CODEOWNER approval:
Tend protects workflows, `.config/tend.yaml`, CODEOWNERS, and agent
instructions. Before granting merge authority, `tend check` verifies the
effective ownership file, non-bypassable review rule, and exact
generated workflows. Yolo rejects runner-side setup and workflow/job
overrides so ordinary source edits cannot become privileged setup code.
Existing target selectors are retained in maintainer mode; a yolo
transition fails closed if it cannot safely split old protected targets
into admin-only coverage.

The agent still controls ordinary source code, including code that later
runs outside Tend. This mode is for repositories whose maintainers
accept that risk. The isolated runner and credential boundaries remain
in place; maintainer mode retains its setup support and shared proxy
cache.

The general branch-lifecycle and credential-audit hardening was merged
separately in #1382, so reverting this PR can leave those protections
intact. This branch now includes main. Nightly regeneration and
install-test also cover effective root or `docs/CODEOWNERS` files, which
yolo `init` may update.

Validation: full Python and worker suites, TypeScript typecheck, all
pre-commit hooks, and independent security review of the combined branch
and CODEOWNERS repair.

> _This was written by Codex on behalf of max-sixty_
@max-sixty max-sixty mentioned this pull request Sep 22, 2026
max-sixty added a commit that referenced this pull request Sep 22, 2026
Bumps the generator to 0.3.0, syncs `uv.lock`, and adds the `## 0.3.0`
CHANGELOG section.

Headline: opt-in `merge: yolo` (#1172). #1382 tightens `tend check`, so
an existing install may need `tend check --fix`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

> _This was written by Claude Code on behalf of max-sixty_

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
max-sixty pushed a commit to max-sixty/worktrunk that referenced this pull request Sep 23, 2026
Regenerates the nine `tend-*.yaml` workflows from tend 0.3.1, up from
0.2.15. Behavior here is unchanged: the only substantive diff is two new
action inputs, `merge: maintainer` and `control_plane_owner: ""`, both
of which are the action's own defaults. `maintainer` is the merge
authority this repo already runs under — the bot proposes, a maintainer
merges.

What the upgrade changes for this repo:

- **`tend check` audits protected refs and credential environments more
strictly**
([max-sixty/tend#1382](max-sixty/tend#1382)). A
protected branch must now restrict creation, update and deletion
together rather than update alone, and the credential audit no longer
treats a ref-qualified reusable workflow as this tree's copy. This repo
does not clear the new bar yet — the nightly filed #4242 with the single
ruleset gap and the remediation.
- **Yolo merge mode exists, and is off**
([max-sixty/tend#1172](max-sixty/tend#1172),
[#1390](max-sixty/tend#1390)). The new inputs
are how a repo would opt into letting the bot merge its own PRs; leaving
them at the defaults keeps the current arrangement, and the `merge:
maintainer` value is what the mitmproxy cache step is now gated on.
- **`review-runs` sees the whole night**
([max-sixty/tend#1377](max-sixty/tend#1377)).
Run listing now pages to the Actions ceiling instead of stopping at the
first page, so a busy night's early runs stop falling out of the census;
[#1374](max-sixty/tend#1374) keeps each
correction row's author alongside it.
- **CI polling is bounded by elapsed time, not iteration count**
([max-sixty/tend#1376](max-sixty/tend#1376),
reinstating [#1371](max-sixty/tend#1371) after
[#1375](max-sixty/tend#1375) reverted it). A
settle loop against slow checks now stops on a sleep budget, so a long
matrix can't quietly stretch a session.
- **Install-test drift detection tightened**
([max-sixty/tend#1381](max-sixty/tend#1381)):
generator output a PR never committed now fails tend's own drift check,
which is the check that makes a regeneration PR like this one
trustworthy.

Full comparison:
[0.2.15...0.3.1](max-sixty/tend@0.2.15...0.3.1).

This PR does not touch `.config/tend.yaml`, whose `sandbox_setup:` key
0.3.1 now warns "will be refused in a later release". That migration is
a separate change.


#4240 overlaps this completely: it was generated with the same 0.3.1, so
it carries the identical headers and the identical `merge: maintainer` /
`control_plane_owner: ""` on the same lines, underneath a Claude → Codex
harness swap. The only thing that distinguishes the two is which harness
the action runs. Whichever lands first leaves the other conflicting on
the eight `uses:` lines, resolved by regeneration rather than by hand.
So this PR is worth landing on its own only for as long as the Codex
cutover stays in draft — if that lands first, close this one.

Verified by regenerating in the merged tree: `uvx [email protected] init`
reproduces these nine files byte-for-byte, and the action declares
`default: maintainer` and `default: ""` for the two new inputs at
`0.3.1`, so neither changes behavior.

Co-authored-by: worktrunk-bot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants