Skip to content

fix: load an admission policy or governance profile saved with a bom - #35384

Merged
bolichen97 merged 1 commit into
mainfrom
fix/32687-governance-bom
Nov 12, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/32687-governance-bom

Conversation

@bolichen97

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A fleet admission policy or governance profile saved as UTF-8 with a byte-order mark loads as written, instead of failing closed to deny-all.

Windows editors and PowerShell 5.1 Set-Content -Encoding UTF8 save UTF-8 with a leading byte-order mark (BOM). When the admission policy carries one, load_admission_policy logs admission policy at <path> is unreadable; failing closed and returns the fail-closed policy: mode enforce, an empty allowlist and a required signature. When a governance profile carries one, ProfileStore logs profile <name>.json is invalid; falling back to deny-all (fail-closed) and the profile's surface resolves to deny-all. The same files without the mark load fine.

Why it matters

An operator who edits either file with an ordinary Windows editor gets every plugin refused (an edition with a companion plugin does not start), or the profile's surface denied, and a governed fleet whose profile has no recoverable bind refuses to boot. The log says "unreadable" or "invalid", so nothing points at the file's encoding.

Not a goal

What changed (motivation → approach → change)

An admission policy or governance profile saved with a BOM now loads as written instead of as deny-all. Both readers decoded the file as strict UTF-8, which keeps the mark as the first character U+FEFF, then handed the text to bare json.loads, which refuses it ("Unexpected UTF-8 BOM").

load_admission_policy (platform/admission.py) and ProfileStore._reload (platform/governance_profiles.py) now parse with user_json.loads_user_json, the helper the hand-saved config readers use; the security policy reader moved to it in #28425. It drops exactly one leading mark and is otherwise json.loads with the same exceptions, so every fail-closed path is untouched. The admission seed check still hashes the same text. governance.md's byte-order-mark paragraph names the two readers.

Backwards compatibility

Compatible: only a file that differs from valid UTF-8 JSON by one leading BOM changes, and it now loads exactly the policy or profile it holds instead of deny-all; every other input reads as before.

Removes nothing: both readers accept one more spelling of the same document and refuse everything they refused before.

Tests

test/test_user_json_bom.py:

  • TestAdmissionPolicyReader::test_the_policy_loads_as_authored (BOM file and plain control): load_admission_policy returns the authored policy.
  • TestAdmissionPolicyReader::test_anything_else_still_fails_closed (UTF-16, BOM before invalid JSON, two marks): it still returns enforce, an empty allowlist and a required signature.
  • TestGovernanceProfileReader::test_the_profile_parses (BOM file and plain control): the store holds the parsed profile, with nothing unrecoverable and no deny-all fallback.
  • TestGovernanceProfileReader::test_anything_else_still_falls_back_to_deny_all (the same three inputs): the profile still falls back to deny-all.

Determinism: the two new classes (10 ids) passed 20 runs at -n0, 10 runs at -n 4 --dist loadgroup --max-worker-restart=2 beside test/test_platform_admission.py and test/test_governance_profiles.py, and the whole file in a shuffled order (seed 32687, 59 ids).

Proof: PROVEN test/test_user_json_bom.py::TestAdmissionPolicyReader::test_the_policy_loads_as_authored[utf8_bom], test/test_user_json_bom.py::TestGovernanceProfileReader::test_the_profile_parses[utf8_bom] (head 3492bf3)

Manual verification

N/A — unit coverage sufficient: the change is one parse call in each reader, and the tests drive the real readers on the file bytes the issue reports.

Screenshots / video

N/A — no user-visible frontend surface changes.

Related Issues

Closes #32687

Sibling sweep

Swept: git grep -nE "json.loads(" -- 'src/kiro_crew/platform/.py' 'src/kiro_crew/platform/**/.py'
Sibling: src/kiro_crew/platform/admission.py:746 -- changed here
Sibling: src/kiro_crew/platform/governance_profiles.py:765 -- changed here
Sibling: src/kiro_crew/apps/admission.py:142 -- not affected -- already parses with the same helper (#34185)
Sibling: src/kiro_crew/platform/governance.py:738 -- not affected -- its text comes from read_endorsed_config_text, which already strips one mark

The sweep's other hits are not affected: admission.py:819 (read_policy_trust_root) hands json.loads raw bytes, whose encoding detection drops the mark; :859 and :866 read a plugin manifest packaged in an installed distribution, app_update_request.py and update_stepup.py read records the gateway writes, and the policy_distribution_*, enterprise_policy_* and wheel_engine.py hits parse network bodies, an env var or a wheel.

Pattern harvest

Rule candidate: semgrep
Pattern: a hand-saved config file read with read_text(encoding="utf-8") and parsed with bare json.loads instead of user_json.loads_user_json

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

An admission policy or governance profile saved as UTF-8 with a
byte-order mark (the default for Notepad's "UTF-8 with BOM" and
PowerShell 5.1 Set-Content -Encoding UTF8) failed closed to deny-all:
both readers decoded strict UTF-8, kept U+FEFF, and handed it to bare
json.loads, which refuses it.

Parse both with user_json.loads_user_json, the helper every hand-saved
JSON reader uses and the one the security policy reader moved to in
PR #28425. It drops one leading mark and is otherwise json.loads, so
the fail-closed arms are unchanged: invalid JSON after a mark, two
marks and UTF-16 still fail closed. The admission seed check still
hashes the same bytes.

Closes #32687
@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners November 11, 2026 16:26
@bolichen97
bolichen97 requested a review from Zedmor November 11, 2026 16:26
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 3492bf37b72ed4458473bc94b4da94af5ddfa15a touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 3492bf37b72ed4458473bc94b4da94af5ddfa15a — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: both readers now go through the existing BOM helper, and every other input still fails closed.

[DESIGN-REVIEWED] 3492bf3

Description read

[DESCRIPTION-READ] 3c436a55ba7bd1df45dbfcaab27091cce1134a8ed2f65056bdaffaa0d2aad9e7

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 3492bf37b72ed4458473bc94b4da94af5ddfa15a — 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 does not.

First-Principles-Verdict: PASS

Nothing blocks. Both readers now parse through the existing user_json.loads_user_json helper, which fixes the reported BOM failure at its source and adds no new surface. One keystone sibling is still unfixed.

Notes

  • Item 1 — symptom-level sibling: one of the 4 keystone ceiling files is still read with a bare json.loads(eff.decode("utf-8")) at src/kiro_crew/computer_use/enable_state.py:83, so a computer_use.json saved with a BOM reads as disabled. The PR's sibling sweep looked only under platform/. Of the 16 json\.loads\( hits under platform/, this PR fixes 2 and its description accounts for the other 14. Fixing enable_state.py belongs in a separate change.

What this change ships

Inventory (3 items) — 3 justified

Intent: a fleet admission policy or governance profile saved with a UTF-8 BOM by a Windows editor loads as written instead of failing closed to deny-all. This is a FIX (#32687).

  1. An admission policy file with one leading BOM loads as authored instead of failing closed — justified
  2. A governance profile with one leading BOM parses instead of falling back to deny-all — justified
  3. The governance spec's paragraph on the byte-order mark now names both readers — justified

[FIRST-PRINCIPLES-REVIEWED] 3492bf3

Description read

[DESCRIPTION-READ] f4a09f939a2e99114bf7649ffb7d4ea9ee8a799fc61dde9e3ce0e0642ecd589f

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 3492bf37b72ed4458473bc94b4da94af5ddfa15a — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 3492bf3

Verdict parsed from the review's SHA-scoped output markers for commit 3492bf37b72ed4458473bc94b4da94af5ddfa15a.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 3492bf37b72ed4458473bc94b4da94af5ddfa15a false-positive: <reason, 20 to 500 characters>

@github-actions

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 3492bf37b72ed4458473bc94b4da94af5ddfa15a and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 3492bf3

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 3492bf37b72ed4458473bc94b4da94af5ddfa15a false-positive: <reason, 20 to 500 characters>

@bolichen97
bolichen97 enabled auto-merge (squash) November 11, 2026 16:48

@buluoray buluoray 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.

Approve on 3492bf3. An admission policy or governance profile saved with one UTF-8 BOM now loads as authored instead of deny-all; UTF-16, two marks and invalid JSON still fail closed, and no reader can load a file as looser than its contents. Decisive lines: src/kiro_crew/platform/admission.py:746, src/kiro_crew/platform/governance_profiles.py:765, src/kiro_crew/user_json.py (loads_user_json = json.loads(text.removeprefix("\ufeff")))

@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 Nov 11, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] CodeQL / Analyze (python) on 3492bf3 failed at the SARIF upload step with API rate limit exceeded for installation, on attempt 1 and again on attempt 2 (https://github.com/kirodotdev/KiroCrew/actions/runs/43058430605). Main's own CodeQL push run hit the same limit today at 13:09Z (https://github.com/kirodotdev/KiroCrew/actions/runs/43220204043). This is the shared Actions token quota tracked in #28761, not this diff; every other check on this head is green. Rerunning only the failed job now that uploads succeed again; no code change.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention labels Nov 12, 2026
@bolichen97
bolichen97 merged commit fe813c2 into main Nov 12, 2026
102 of 104 checks passed
@bolichen97
bolichen97 deleted the fix/32687-governance-bom branch November 12, 2026 14:09
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants