Skip to content

fix(auto-improvement): owner-gate the routes that drive agents or publish - #14652

Merged
kyleseaman merged 2 commits into
mainfrom
fix/owner-gate-round11-autoimp
Sep 28, 2026
Merged

kyleseaman merged 2 commits into
mainfrom
fix/owner-gate-round11-autoimp

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Only the dashboard owner can make Auto-Improvement drive the owner's agents or publish under the owner's name.

Seven Auto-Improvement routes checked only that the app is on. They never checked who was calling. Any dashboard token reached them. That includes a channel user on the allow list, who is not the owner.

Route What a non-owner could do
POST setup-clone point the agents at a repo they pick
PUT config set the risk consent flags acceptUnsandboxedAgentRisk and watcherAcceptEgressRisk
POST run, POST calibrate start the owner's agents
POST watchers/{fp}/start start a PR watcher
POST findings/{fp}/commit push a commit with the owner's git credentials
POST draft-pr/{fp} open a draft PR as the owner on GitHub

Why it matters

A non-owner could run the owner's agents on any repo. They could turn off the sandbox consent for those agents. They could publish code as the owner.

Not a goal

  • Gating POST findings/{fp}/forget, POST findings/{fp}/purge and POST findings/purge-dead. These change or delete the local findings ledger.
  • Gating PUT sessions/{key} and DELETE sessions/{key}. These link or unlink a chat slot.
  • Gating POST run/stop and POST watchers/{fp}/stop.
  • Any change to the shared owner gate or to token handling.

What changed (motivation → approach → change)

The symptom: a non-owner could reach all seven routes above. The cause: register_routes wraps them only in _require_enabled, and that wrapper checks the app switch, not the caller.

GET /watchers has the same hole. Its reconcile sweep starts watcher agents when watcherAutoStart is on, and marks drafts ready when autoPublish is on.

The fix follows _handle_deps_install in the same file. Each of these eight handlers in src/kiro_crew/apps/builtins/auto_improvement/backend/routes.py now calls require_owner_dashboard_request first. It does this before reading the body or the fingerprint. App tokens are refused too, because no app-token caller exists. The page in the dashboard runs as the owner, so it still works. The loop, the watchers and the MCP server do not go through these routes, so they are not touched.

The gate already logs each refusal to SEL. A new _audit_owner_route_allowed logs each allowed call. It runs off the event loop, in the same shape as _audit_deps_install_allowed.

Backwards compatibility

Breaking: non-owner dashboard tokens and app tokens now get 403 on the eight routes (the seven above plus GET /watchers). Writer sweep on origin/main @ 631f8e6: the only callers are the owner's dashboard page (SetupPanel.tsx, AutoImprovementPage.tsx), which sends the owner's token and keeps working. No page, skill, agent or MCP tool calls GET /watchers, POST calibrate, POST draft-pr or POST watchers/{fp}/start.

Tests

  • test/test_auto_improvement_owner_gate.py (new) tests all eight handlers. The owner reaches the body and one allowed call is logged. A non-owner with app == "" gets 403. An app token gets 403. For both refusals the body never runs and nothing is logged as allowed. Removing any one gate makes its refusal rows fail.
  • test/test_ai_backend_routes_coverage.py: _request() now carries the owner's identity. No assertion changed.
  • src/kiro_crew/apps/builtins/auto_improvement/tests/test_finding_detail.py: _client() now stamps the owner's identity. No assertion changed.
  • mypy test/test_ai_backend_routes_coverage.py reports 2 func-returns-value errors (lambdas using list.append). They are on untouched lines and appear the same on origin/main (lines 1503 and 1558 there). CI's mypy gate covers src/kiro_crew/ only.

Manual verification

N/A. Unit tests cover it: the gate is one call, and the tests drive the real handlers for all three kinds of caller.

Related Issues

Security audit round 11, findings F85 and F86.

Pattern harvest

Rule candidate: review-prompt
Pattern: a mutating app route wrapped only in _require_enabled, with no owner gate.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

…lish

Seven auto-improvement routes were wrapped only in _require_enabled, so any
dashboard token could reach them. A non-owner could clone a repository of
their choice, grant the unsandboxed-agent consent flags, start a run or a
calibration, start a PR watcher, push a one-click commit with the owner's git
credentials, or open a draft PR under the owner's GitHub identity.

Each handler now calls require_owner_dashboard_request first, the same shape
as _handle_deps_install: app tokens are refused too, since no app-token caller
exists. Allowed decisions are recorded in SEL off the event loop; refusals are
audited by the gate itself.
@iamwhatever
iamwhatever requested a review from a team as a code owner September 28, 2026 07:37
@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of 6ade12315fe80af8ec75f3068a6da8cec518ad8f and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 6ade123

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 6ade12315fe80af8ec75f3068a6da8cec518ad8f: <one-sentence reason>

@github-actions github-actions Bot added the readiness: action required A blocking check or review needs attention label Sep 28, 2026
@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — ✅ PASS

Premise-level review of 6ade12315fe80af8ec75f3068a6da8cec518ad8f — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: PASS

Verify the rfc-perpetual-agent draft→accepted flip and the two macOS test hunks are base-drift from #14662/#14651 — not decisions this PR is silently recording.

Not justified as shipped

What this change ships

Inventory (6 items) — 3 justified

Intent: only the dashboard owner can drive Auto-Improvement's agents or publish under the owner's name — a FIX.

  1. Non-owner and app tokens now get 403 on 8 routes (put_config, setup_clone, run, calibrate, watcher_start, watchers_list, commit, draft_pr) — justified
  2. Allowed owner calls to those routes now logged to SEL via _audit_owner_route_allowed — justified
  3. rfc-perpetual-agent.md flipped draft→accepted + new decision section — undeclared (base-drift docs: accept owner-controlled perpetual mode #14662)
  4. hop-port-guard tests made hermetic on macOS — undeclared (base-drift test(instances): make three hop-guard cases hermetic on macOS #14651)
  5. remote-crew test stubs diagnosis to avoid macOS timeout — undeclared (base-drift test(instances): make three hop-guard cases hermetic on macOS #14651)
  6. Test harnesses stamp owner identity so gated routes reach their body — justified

[FIRST-PRINCIPLES-REVIEWED] 6ade123

@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

Design-level review of 6ade12315fe80af8ec75f3068a6da8cec518ad8f — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Nothing to check. Owner gate reuses the shared require_owner_dashboard_request pattern (mirrors _handle_deps_install), targets a real MULTIPLE-HUMANS boundary (channel allow-list users ≠ owner), and gates the side-effecting GET /watchers sweep with a documented compat story and tests for all three caller kinds.

[DESIGN-REVIEWED] 6ade123

@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5 Review — ✅ no blocking findings

Reviewed 6ade12315fe80af8ec75f3068a6da8cec518ad8f — this comment is updated in place on each push.

Review details

No blocking issues.

FINDING — docs/system-specs/modules/auto-improvement.md:31 — the owning spec still states the route table's only authorization as "Every handler is wrapped in _require_enabled (403 when the app is disabled)", while this diff adds require_owner_dashboard_request to eight of the 32 rows (PUT /config, POST /setup-clone, POST /run, POST /calibrate, POST /draft-pr/{fp}, POST /findings/{fp}/commit, GET /watchers, POST /watchers/{fp}/start) and leaves sibling mutating rows (POST /run/stop, /findings/{fp}/forget, /findings/{fp}/purge, /findings/purge-dead, /watchers/{fp}/stop, PUT/DELETE /sessions/{key}) ungated, so the owner/non-owner split has no written contract for the next change to preserve → Fix: in this commit, extend ## Routes to name which handlers call require_owner_dashboard_request and why the rest deliberately do not, and add the matching D-row.

[OPUS-REVIEWED] 6ade123

Verdict parsed from the review's SHA-scoped output markers for commit 6ade12315fe80af8ec75f3068a6da8cec518ad8f.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 6ade12315fe80af8ec75f3068a6da8cec518ad8f: <one-sentence reason>

@iamwhatever

iamwhatever commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor Author
  • Untouched ledger and session routes stay ungated (span=f118c785345a) — rebutted

Deliberately out of scope for this PR: it fixes the agent-driving and publish-as-owner routes only, and the maintainer ruled the remaining routes are not gated here.
forget, purge, purge-dead, sessions PUT/DELETE, run/stop and watchers stop are listed under "Not a goal" with what each does, and are queued for the next security audit round (round 12).
The shared owner gate is unchanged; gating any of them later is the same one-call change this PR makes.

@iamwhatever

iamwhatever commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor Author
  • Fold allow-auditing into the shared owner gate (span=face25b50493) — rebutted

dashboard/handlers/_shared.py is a forbidden path for this fix, and changing require_owner_dashboard_request would change audit volume for every owner-gated route in the product; that belongs in its own PR.
Here the per-app helper copies the existing _audit_deps_install_allowed shape in the same file, so this app has one allow-audit pattern, not two.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 28, 2026
…atchers

GET /watchers runs a reconcile sweep. With watcherAutoStart on it starts
watcher agents, and with autoPublish on it marks the owner's draft PRs ready.
A non-owner could reach both through this read, around the new gate on
POST /watchers/{fp}/start. The handler now takes the same owner gate first;
no dashboard page or agent calls this route.
@iamwhatever

iamwhatever commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor Author
  • GET /watchers sweep bypasses the watcher_start gate (span=08f2c8c9497a) — fixed in 6ade123

_handle_watchers now calls require_owner_dashboard_request(request, "auto_improvement.watchers_list") first, the same shape as the other gated handlers, so a non-owner or app token gets 403 before the reconcile sweep can start watchers or mark drafts ready.
test/test_auto_improvement_owner_gate.py adds the owner / non-owner / app-token rows for it; removing the gate turns both refusal rows red.
The ledger routes (forget, purge, purge-dead) stay out of this PR and are listed under Not a goal.

@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • Module spec still describes only _require_enabled (span=c18a353fa3a1) — accepted as a follow-up, outside this minimal fix

The owner gate adds a 403 owner_only / 401 stale_session_reauth refusal to eight Auto-Improvement routes.
The spec docs/system-specs/modules/auto-improvement.md is outside this security fix's contract; its access-contract sentence and route table are updated in a follow-up docs PR.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: passed Eligible automated validation passed for the current revision labels Sep 28, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • RFC status flip in rfc-perpetual-agent.md is not in this PR (span=341462b64ce2) — rebutted

The lane itself names this as base drift from merged #14662; git diff origin/main...6ade12315fe80af8ec75f3068a6da8cec518ad8f touches only four files: auto_improvement/backend/routes.py, its tests/test_finding_detail.py, test/test_ai_backend_routes_coverage.py and test/test_auto_improvement_owner_gate.py.
Nothing here changes that file; no action is needed in this PR.

@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • test_hop_port_guard.py hermeticity change is not in this PR (span=127a0c33670c) — rebutted

The lane itself names this as base drift from merged #14651; git diff origin/main...6ade12315fe80af8ec75f3068a6da8cec518ad8f touches only four files: auto_improvement/backend/routes.py, its tests/test_finding_detail.py, test/test_ai_backend_routes_coverage.py and test/test_auto_improvement_owner_gate.py.
Nothing here changes that file; no action is needed in this PR.

@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • test_remote_crew_chaining.py diagnosis stub is not in this PR (span=8ad0490a567e) — rebutted

The lane itself names this as base drift from merged #14651; git diff origin/main...6ade12315fe80af8ec75f3068a6da8cec518ad8f touches only four files: auto_improvement/backend/routes.py, its tests/test_finding_detail.py, test/test_ai_backend_routes_coverage.py and test/test_auto_improvement_owner_gate.py.
Nothing here changes that file; no action is needed in this PR.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Sep 28, 2026
@kyleseaman
kyleseaman enabled auto-merge (squash) September 28, 2026 16:16
@kyleseaman
kyleseaman merged commit 59f0d89 into main Sep 28, 2026
97 checks passed
@kyleseaman
kyleseaman deleted the fix/owner-gate-round11-autoimp branch September 28, 2026 16:23
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 28, 2026
bolichen97 pushed a commit that referenced this pull request Oct 1, 2026
…0.8.0

Backport of #14658, #14652, #14650, #14775, #14656, #14900, #14898, #14894, #14891, #14948, #15046, #15332, #15333, #15331 to release/0.8.0, cherry-picked in main's merge order.

* fix(dashboard): owner-gate the host-file reader routes (#14658)
  (cherry picked from commit 778b51a)
* fix(auto-improvement): owner-gate the routes that drive agents or publish (#14652)
  (cherry picked from commit 59f0d89)
* fix(dashboard): owner-gate POST /api/memory/enable-embeddings (#14650)
  (cherry picked from commit bd2a9c0)
* fix(dashboard): owner-gate GET /api/file-search (#14775)
  (cherry picked from commit a0b9de6)
* fix(apps): owner-gate app install, update and registry-write routes (#14656)
  (cherry picked from commit 4f5cb65)
* fix(meetings): owner-only meeting write routes (#14900)
  (cherry picked from commit 6b9a56c)
* fix(auto-improvement): owner-gate forget, purge, stop, session links and PR status (#14898)
  (cherry picked from commit ee051d9)
* fix(apps): require the dashboard owner for app register, uninstall, disable (#14894)
  (cherry picked from commit 42894c3)
* fix(dashboard): require the owner for cron job update, run, enable and delete (#14891)
  (cherry picked from commit ccb78e6)
* fix(apps): require the dashboard owner to enable an app (#14948)
  (cherry picked from commit 41de374)
* fix(dashboard): let an app token manage only its own cron jobs (#15046)
  (cherry picked from commit 95a78b1)
* fix(issue-radar): owner gate on every forge-write route (#15332)
  (cherry picked from commit 4b6ab60)
* fix(ops-mission-control): owner-gate provider secret save and revoke (#15333)
  (cherry picked from commit e5f61b2)
* fix(meetings): owner-gate dictionary add and remove (#15331)
  (cherry picked from commit e5ba84e)

Co-authored-by: Joe Guo <zejiangg@amazon.com>
Co-authored-by: zejiangg <zejiangg@amazon.com>
bolichen97 added a commit that referenced this pull request Oct 1, 2026
…0.8.0 (#15621)

Backport of #14658, #14652, #14650, #14775, #14656, #14900, #14898, #14894, #14891, #14948, #15046, #15332, #15333, #15331 to release/0.8.0, cherry-picked in main's merge order.

* fix(dashboard): owner-gate the host-file reader routes (#14658)
  (cherry picked from commit 778b51a)
* fix(auto-improvement): owner-gate the routes that drive agents or publish (#14652)
  (cherry picked from commit 59f0d89)
* fix(dashboard): owner-gate POST /api/memory/enable-embeddings (#14650)
  (cherry picked from commit bd2a9c0)
* fix(dashboard): owner-gate GET /api/file-search (#14775)
  (cherry picked from commit a0b9de6)
* fix(apps): owner-gate app install, update and registry-write routes (#14656)
  (cherry picked from commit 4f5cb65)
* fix(meetings): owner-only meeting write routes (#14900)
  (cherry picked from commit 6b9a56c)
* fix(auto-improvement): owner-gate forget, purge, stop, session links and PR status (#14898)
  (cherry picked from commit ee051d9)
* fix(apps): require the dashboard owner for app register, uninstall, disable (#14894)
  (cherry picked from commit 42894c3)
* fix(dashboard): require the owner for cron job update, run, enable and delete (#14891)
  (cherry picked from commit ccb78e6)
* fix(apps): require the dashboard owner to enable an app (#14948)
  (cherry picked from commit 41de374)
* fix(dashboard): let an app token manage only its own cron jobs (#15046)
  (cherry picked from commit 95a78b1)
* fix(issue-radar): owner gate on every forge-write route (#15332)
  (cherry picked from commit 4b6ab60)
* fix(ops-mission-control): owner-gate provider secret save and revoke (#15333)
  (cherry picked from commit e5f61b2)
* fix(meetings): owner-gate dictionary add and remove (#15331)
  (cherry picked from commit e5ba84e)

Co-authored-by: Joe Guo <zejiang.guo@gmail.com>
Co-authored-by: Joe Guo <zejiangg@amazon.com>
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