Skip to content

fix(dashboard): owner-gate the skills CRUD write endpoints (#7344) - #7393

Merged
bolichen97 merged 1 commit into
mainfrom
fix/skills-crud-guards-7344
Sep 17, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/skills-crud-guards-7344

Conversation

@patrigao

@patrigao patrigao commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

The dashboard skills CRUD write handlers in src/kiro_crew/dashboard/handlers/prompts.py — api_skills_create (POST /api/skills) and the PUT/DELETE branches of api_skill_detail — performed writes with no owner gate, no app-token refusal, and no SEL audit. Any non-owner dashboard session or app-token-bearing caller could create, edit, or delete skills.

Why it matters

Skill content is injected into agent context, so a skill write is an instruction-injection surface. The sibling surfaces already treat it that way: the skill-trust handlers in the same file gate on owner + app-token via _deny_non_owner_skill_trust, and ask_question.py carries _deny_app_token / _deny_non_owner. Leaving the CRUD writes open made the guard set asymmetric: the trust ledger was protected while the content it vouches for was not.

What changed (motivation → approach → change)

Symptom: unguarded skill writes. Root cause: the guard helper was scoped to the skill-trust operations only, so the CRUD handlers had nothing to call. Change: generalize the same-file helper _deny_non_owner_skill_trust → _deny_non_owner_skill_operation (parameterized on the operation label), and apply it at the top of api_skills_create, the PUT and DELETE branches of api_skill_detail, and — per the first-principles review round — the rest of the mutating skill-handler family: api_skill_pending_approve (promotes candidate content into the live catalog, the same instruction-injection surface), api_skill_pending_dismiss, api_skills_pending_dismiss_all, api_skill_pin, and api_skill_inject_on_trigger. Add per-outcome SEL audit records (denied and ok) via the _sel().log_tool_invocation pattern already used by api_prompts. GET behavior is unchanged (it already carries the foreign-app-slot guard for kiro-workspace names). The CAS/descriptor-pin half of the asymmetry is tracked separately in #5028 and is deliberately out of scope here.

Same-commit spec updates: docs/system-specs/modules/learn-cron-dashboard.md and docs/system-specs/modules/memory-skills-hooks.md now document the write-path guard.

Tests

New test/test_skill_write_guard.py (fixtures and request-identity setup follow the existing skill-trust guard tests):

  • non-owner write → 403, for create, update, and delete
  • app-token caller → denied, for all three write paths
  • owner happy path still works (create/update/delete succeed)
  • SEL events emitted per outcome (denied and ok records asserted)
  • TestSkillLifecycleEndpointsAreGated: pending approve/dismiss/dismiss-all, pin, and inject-on-trigger each refuse app tokens and non-owner subjects with the audited 403, and the loader records zero calls (no mutation happens before the gate)

test/test_skill_trust_store.py updated for the renamed helper; test/test_skill_pending_api.py runs its business-logic cases as the owner (the gate has its own dedicated coverage). Focused suites: 160 passed; broader prompts/skills selection: 571 passed.

Manual verification

N/A — unit coverage sufficient: the change is a handler-level guard with no UI surface, and every denied/allowed path plus its SEL record is asserted directly.

Related Issues

Closes #7344

Pattern harvest

Rule candidate: review-prompt
Pattern: guard set applied to the read/trust surface of a resource but not to its sibling write handlers — check every mutating branch of a resource's handler family when one member carries an owner/app-token gate.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|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

@patrigao
patrigao requested review from a team and chenmingwei23 August 31, 2026 23:55
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Aug 31, 2026
@github-actions

github-actions Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Opus 4.8 Review — ✅ no blocking findings

Reviewed 3556797125654cef577ca4c24fea03fda733a36d — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 3556797

Verdict parsed from the review's SHA-scoped output markers for commit 3556797125654cef577ca4c24fea03fda733a36d.

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

@github-actions

github-actions Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

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

Design-Verdict: PASS

Confirm no shipped App Kit or companion flow writes skills through these endpoints with an app token — those callers now receive audited 403s.

Suggestions

  • The original bug's root cause (a new mutating skill handler can land ungated) still recurs with per-handler call sites; a test that enumerates the /api/skills route table and asserts every mutating route is gated would pin the family, not the current members.

[DESIGN-REVIEWED] 3556797

@github-actions

github-actions Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — 🟡 CONCERNS

Premise-level review of 3556797125654cef577ca4c24fea03fda733a36d — 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: CONCERNS

The PR's own invariant — "any skill mutation … only the dashboard owner may perform it" — leaves the discover-module skill install ungated, with no recorded deferral.

Not justified as shipped

What this change ships

Inventory (7 items) — 5 justified

Intent: keep dashboard skill mutations owner-only so non-owner sessions and app tokens cannot inject instructions via skill content — a FIX (closes #7344).

  1. Creating a skill now requires the dashboard owner; app tokens get an audited 403 — justified
  2. Editing or deleting a skill now requires the owner, denial audited before the territory check — justified
  3. Pending approve/dismiss/dismiss-all, pin, and inject-on-trigger now require the owner — rides along, point patch (1 unfixed sibling, above)
  4. Every skill create/update/delete outcome now leaves a SEL record — rides along (see above)
  5. Guard helper renamed _deny_non_owner_skill_trust → _deny_non_owner_skill_operation (old name: 0 remaining references) — justified
  6. Pending/territory/migration test suites now run as the owner, gate covered in its own suite — justified
  7. Both owning specs updated in the same commit — justified

[FIRST-PRINCIPLES-REVIEWED] 3556797

@github-actions

github-actions Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of 3556797125654cef577ca4c24fea03fda733a36d and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 3556797

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

@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 1, 2026
@patrigao
patrigao force-pushed the fix/skills-crud-guards-7344 branch from b6995e0 to 559628f Compare September 1, 2026 01:02
@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 1, 2026
@patrigao

patrigao commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Disposition: fixed in 559628f89 — the First Principles CONCERNS on the 5 unfixed mutating siblings.

5 counted unfixed siblings, same file, same root cause — api_skill_pending_approve, api_skill_inject_on_trigger, api_skill_pin, api_skill_pending_dismiss, api_skills_pending_dismiss_all were reachable without the owner gate.

The finding is legitimate and in scope: api_skill_pending_approve promotes candidate content into the live catalog — exactly the instruction-injection surface this PR gates — and the PR's own harvested pattern ("check every mutating branch of a resource's handler family") demanded the sweep. All five handlers now call _deny_non_owner_skill_operation before touching state or the loader, with the same SEL-audited allowed/denied outcomes. New TestSkillLifecycleEndpointsAreGated pins the widened coverage (app-token + non-owner refusal per endpoint, zero loader calls before the gate); test_skill_pending_api.py business-logic cases now run as owner. Spec docs and the PR body updated to match the true coverage. Focused suites 160 passed, mypy clean.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 1, 2026
@patrigao
patrigao force-pushed the fix/skills-crud-guards-7344 branch from 559628f to d623352 Compare September 1, 2026 01:30
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 1, 2026
@patrigao

patrigao commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author
  • First-use SEL initialization blocks the event loop — span=6f77c3fb4ba7 (prompts.py:801)

Disposition: rebutted — the synchronous SEL call inside an async handler is the file's pre-existing, file-wide idiom, not something this diff introduces or makes newly reachable.

Fresh gateway -> mutation handler -> synchronous SEL key/directory I/O -> all gateway tasks stall.

Evidence: _deny_non_owner_skill_operation and its sync _sel().log_api_access calls exist on main today, invoked by the skill-trust endpoints; this PR only adds call sites. The same file carries ~30 pre-existing synchronous _sel().log_tool_invocation calls in async handlers, including api_prompts_list (prompts.py:207), which runs on every dashboard prompt listing — first-use SEL initialization therefore already fires on ordinary GET traffic on main long before any skill mutation, so this diff does not change when or where that one-time init cost is paid. This lane passed the identical calls in the three CRUD handlers on the round-1 head. Converting only these 8 call sites to asyncio.to_thread while the rest of the file stays synchronous would fork the idiom mid-file; the consistent fix is a file-wide (arguably codebase-wide) async-SEL refactor, which is disproportional to an owner-gate PR. Happy to file that refactor as a follow-up if maintainers want it.

@patrigao

patrigao commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author
  • Audit initialization failure reports 500 after deletion — span=6f77c3fb4ba7 (prompts.py:1198)

Disposition: fixed in d623352d2.

Invalid/unreadable SEL key -> gate suppresses initialization failure -> deletion commits -> audit retries and raises -> client receives 500 for a completed mutation.

Legitimate: the three post-mutation outcome audits this PR added (create/update/delete) were naked, while the file's own convention — the guard helper — explicitly swallows SEL failures to preserve the response. A raised audit after delete_skill committed would have returned a 500 for a completed mutation. All three audits are now wrapped in try/except with a debug log, mirroring the guard's comments ("the mutation is committed; never 500 on an audit write"). New TestAuditFailureNeverBreaksACommittedMutation pins the contract: with log_tool_invocation raising, create/update/delete all still return 200.

@patrigao

patrigao commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author
  • Spec claim overstates the gated surface — span=c3b0cae4175d (learn-cron-dashboard.md:1088)

Disposition: fixed in d623352d2.

the added claim so no skill mutation is reachable by an app token or non-owner subject (#7393 first-principles round) is false: api_skills_discover_install … refuses only request.get("internal_auth"), never is_owner_…

Confirmed against discover.py:238: the discover-install endpoint refuses internal-secret callers only, by design (it keeps registry installs a deliberate dashboard action while letting agents read via skill_fetch), and is not owner-gated. Both spec docs now scope the claim precisely: the owner gate covers every mutating skill handler in prompts.py, and the discover-module install endpoint is named explicitly with its own guard model. Gating discover-install under the owner check would change a different module's deliberate auth design and belongs to its own review if maintainers want it.

@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 1, 2026
@patrigao

patrigao commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author
  • Docstring says "every mutating skill handler" while pending-list GET prunes expired candidates ungated — span=dd99d2a43380 (prompts.py:61)

Disposition: rebutted — the enumerated claim is exact, and TTL pruning is outside the threat model the gate (and the spec sentences) address.

"every mutating skill handler" is false because pending-list GET calls prune_pending, deleting expired candidates without this gate

The docstring phrase is immediately qualified by its colon-enumerated list — CRUD writes, pending approve/dismiss/dismiss-all, pin, inject-on-trigger — which is the precise covered set; prune_pending is not a handler but opportunistic TTL housekeeping inside the read endpoint (prompts.py:700, pre-existing design). The gate exists because skill mutations are an instruction-injection surface: content flowing into agent context. Pruning cannot inject anything — it removes candidates already expired per pending_ttl_days, age measured from filesystem mtime specifically so a caller cannot influence what is deleted (skills.py:3958 documents that hardening). A non-owner GET can neither author, promote, nor select content through it. Narrowing the prose to exclude a non-injectable, non-caller-controlled expiry sweep would trade accuracy in the threat-model sense for pedantry in the state-change sense, at the cost of re-arming a fully green review round.

@bolichen97

Copy link
Copy Markdown
Contributor

Open PR relationship audit

This is a consolidated, point-in-time code-level audit note. It compares complete merge-base diffs and current/merged code; it does not treat a shared topic as duplication or partial coverage as completion.

Relationship findings

  • PR #7105 is OVERLAPPING relative to this PR. The goals differ or the implementations can complement each other; this is not a duplicate claim. Recommended action for PR #7105: MERGE_DISCUSSION. Independent and complementary concerns in the same handlers; only the refusal ordering is worth a note when both land, and no code needs to change in this PR for it. Files: src/kiro_crew/dashboard/handlers/prompts.py.
  • This PR is OVERLAPPING with PR #5161. The goals differ or the implementations can complement each other; this is not a duplicate claim. Recommended action for PR #7393: REBASE. Same campaign, no code conflict, but they entrench two different owner-gate spellings and error codes. Worth one maintainer decision on whether the skills family should land on the shared _shared.py boundary; that decision should not block 7393, since 5161 gives the skills routes no coverage at all. Files: src/kiro_crew/dashboard/handlers/_shared.py.
  • This PR is OVERLAPPING with PR #8259. The goals differ or the implementations can complement each other; this is not a duplicate claim. Recommended action for PR #7393: REBASE. Complementary guards on the same handlers; both are needed and neither is redundant. The second to land needs a mechanical rebase of the shared insertion points and the shared spec paragraphs. Files: src/kiro_crew/dashboard/handlers/prompts.py, docs/system-specs/modules/learn-cron-dashboard.md.

No PR, Issue, label, branch, or review state was changed by the relationship-note portion of this audit.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Sep 8, 2026
@patrigao
patrigao force-pushed the fix/skills-crud-guards-7344 branch from d3f8264 to bc8fc1a Compare September 16, 2026 06:12
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 16, 2026
@patrigao
patrigao force-pushed the fix/skills-crud-guards-7344 branch from bc8fc1a to 119cfc1 Compare September 16, 2026 06:32
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 16, 2026
POST /api/skills and the PUT/DELETE branches of /api/skills/{name}
performed writes with no owner gate, no app-token refusal, and no SEL
audit. Skill content is injected into agent context, so a skill write is
an instruction-injection surface — the same rationale that already
guards the skill-trust endpoints in this file.

Generalize _deny_non_owner_skill_trust into
_deny_non_owner_skill_operation (is_owner_dashboard_request already
refuses app tokens and non-owner subjects, and the helper SEL-audits
both outcomes) and apply it at the top of api_skills_create and of the
PUT and DELETE branches of api_skill_detail. Each write outcome
(ok/rejected) now also emits a SEL log_tool_invocation record, matching
the sibling skill handlers. GET behavior is unchanged.

Closes #7344
@patrigao
patrigao force-pushed the fix/skills-crud-guards-7344 branch from 119cfc1 to 3556797 Compare September 16, 2026 06:49
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 16, 2026
@patrigao

Copy link
Copy Markdown
Contributor Author
  • Read-only skill names bypass owner auditing — disposition: fixed in 3556797.
    self-added: yes
    mechanism: owner gate now runs before the read-only-territory guard for PUT and DELETE

Confirmed legitimate (adjudicator-upheld): the read-only-prefix guard returned 405 before _deny_non_owner_skill_operation, so an app-token PUT/DELETE of a kiro-user/* name skipped the denied-owner SEL audit event — an audit gap in this PR's own gate.
Fix: authorization moved ahead of the territory refusal for both verbs; a non-owner caller is denied-and-audited first (403 + SEL event), an owner hitting a read-only name still gets the 405. Repair delegated to a GPT-family model (gpt-5.6-sol; served model unverified).
Red-first: parametrized PUT+DELETE regression asserting exactly one denied skill_update/skill_delete SEL record failed on 119cfc1, passes on 3556797; full guard suite 24/24 green including owner read-only 405s.

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

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed the full diff on head 3556797 as part of the 2026-09-17 readiness audit (evidence: pr-ready-audit-20260917-0835). Verified before approving: readiness: passed in place, required status PR Readiness success on this head, no CHANGES_REQUESTED, no unresolved human hold, main-drift checked against files this PR touches, last push by patrigao. Merge follows through the normal protected path (no bypass).

@bolichen97
bolichen97 merged commit f391f7d into main Sep 17, 2026
116 of 117 checks passed
@bolichen97
bolichen97 deleted the fix/skills-crud-guards-7344 branch September 17, 2026 09:38
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 17, 2026
@NicholasRBowers NicholasRBowers removed the drive-to-green PR claimed by drive-to-green pipeline label Sep 18, 2026
amadsalmon pushed a commit to amadsalmon/KiroCrew that referenced this pull request Sep 22, 2026
…v#7344) (kirodotdev#7393)

POST /api/skills and the PUT/DELETE branches of /api/skills/{name}
performed writes with no owner gate, no app-token refusal, and no SEL
audit. Skill content is injected into agent context, so a skill write is
an instruction-injection surface — the same rationale that already
guards the skill-trust endpoints in this file.

Generalize _deny_non_owner_skill_trust into
_deny_non_owner_skill_operation (is_owner_dashboard_request already
refuses app tokens and non-owner subjects, and the helper SEL-audits
both outcomes) and apply it at the top of api_skills_create and of the
PUT and DELETE branches of api_skill_detail. Each write outcome
(ok/rejected) now also emits a SEL log_tool_invocation record, matching
the sibling skill handlers. GET behavior is unchanged.

Closes kirodotdev#7344

Co-authored-by: Patrick Gao <patrigao@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.

Adopt the prompt-write guard set on the skills CRUD handlers

4 participants