Repository navigation
fix(security): resolve a re-exported name through its owner, not a copy - #13933
Conversation
Design Review (Fable 5) — ✅ PASSDesign-level review of Design-Verdict: PASS Verify the deferred conftest disagreement-detector is filed as a follow-up: non-owned names (e.g. [DESIGN-REVIEWED] 82bc5c0 |
GPT 5.6 Review — ✅ no blocking findingsGPT 5.6 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
First Principles Review (Fable 5) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS The memo-free spelling is justified as "converging" with the six #13727 packages — which are pinned to the opposite spelling and keep the stale-owner defect this PR names. Not justified as shipped
What this change shipsInventory (10 items) — 9 justifiedIntent: FIX — a patch applied at a security control's owning submodule (or after a purge-and-reimport) now governs every reader that goes through the
[FIRST-PRINCIPLES-REVIEWED] 82bc5c0 |
Security Scope Review -- 🟡 CONCERNSWhich legitimate operations does Verdict basis: the reviewer's own judgement; no confirmed regression. Security scope review -- adjudicated candidates
No candidate flipped from allowed to refused. Scope-Verdict: CONCERNS TIGHTENING: the security facade's re-export protocol — eager name binding plus one-way write mirroring replaced by per-access resolution through an ADJUDICATED: 19 candidates, 0 confirmed newly-refused PLATFORM COVERAGE: posix, windows, and any. The diff itself adds no path, separator, interpreter, or environment-variable assumption — owner resolution is by dotted module name, identical on both hosts — but the composite it rewires embeds host-specific machinery ( UNADJUDICATED: the module-resolution guard itself, which no shell command line can reach. Guard: [SCOPE-REVIEWED] 82bc5c0 |
Opus 5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
f059b8e to
e6d8915
Compare
e6d8915 to
3f55ded
Compare
3f55ded to
ce39b89
Compare
Owed after this PR merges: one deletion from the ratchet baselineThis PR converts The exact edit, in one file on
Delete nothing else from that set. #13727 owes the same deletion for six other This is self-enforcing, so you do not have to remember it
This PR does not touch |
ce39b89 to
abe62d2
Compare
|
Rebased onto `main` (694f619) to clear the conflict. Two things the rebase decided, and one it did not. Conflict in `src/kiro_crew/security/init.py`. Taken as this PR intends: the explicit 490-line re-export block is gone and names resolve through `getattr` over `_EXPORTS`. A regression the rebase exposed, fixed here. `main` grew three re-exported names after this branch point that `_EXPORTS` did not carry, so the facade stopped exporting them: `canonical_path_refusal`, `_PERM_VERB_MENTION_PATTERNS` and `_perm_verb_mention_only`. `kiro_crew.artifacts` imports the first one from the facade, so collection failed repo-wide. All three are in `_exports.EXPORTED_NAMES`, so the frozen inventory already expected them. Added to `_EXPORTS` (new `perm_verb_mention` owner group) and to the `TYPE_CHECKING` mirror. `main` also added `_perm_verb_mechanism_for` and `_perm_verb_mention_narrows`, which read two of those names as BARE globals — which `getattr` never sees — so both now resolve through `_submodule(...)`, per this PR own rule. Verified: all 468 names `main` re-exported resolve on the facade, and `test_security_single_storage.py` passes 2846/2846 including `test_the_facade_reads_no_re_exported_name_as_a_bare_global`. Left for you: `test_the_package_stays_within_its_line_budget` is red and I did not move the constant. The package is 26215 lines against `_PACKAGE_LINE_BUDGET = 26_000`. Neither side breaks it alone — `main` is 25597 and this branch pre-rebase was 25257 — so the overage is the sum, not a fault in this diff. Raising a volume ratchet to fit your own growth is the deliberate edit the pin exists to force, and that call is yours: either bump it with a justification, or fold one of the three name lists (`_EXPORTS`, the `TYPE_CHECKING` mirror, `_exports.EXPORTED_NAMES`) so the total comes back under. Everything else in the security sweep is green (6690 passed, this the only failure). [operator: bolichen97] |
The security facade bound every re-exported name in its own namespace and kept a map of resolved owner module objects beside sys.modules, so one name had two storage locations for its value and two for its module. Both now resolve through the import system: the value is read from the owner on each access via a module __getattr__, and the owner is looked up with importlib.import_module from a name-to-module-NAME table. Measured on the base revision: an owner write was invisible through the facade for 465 of 465 re-exported names, so patch.object(<submodule>, ...) left a reader that went through the facade running the object the test believed it replaced. A read can now raise ImportError where it could not before. On a security predicate the hazard is an exception quietly becoming a falsy answer, so the facade raises ImportError for a table name whose owner will not import and AttributeError only for a name that does not exist -- getattr(..., default) swallows the second and not the first. Read the owner from sys.modules and import only on the miss, so a caller that rebinds importlib.import_module cannot answer a security gate. Derive __all__ from the export table, because a star import is resolved against a declared list and never reaches __getattr__. Prove the purge teardown restores both the store and this package's own attribute, which a submodule import rebinds. Repoint the nine facade sites for names this package does not define at the modules that read them. Restate the facade section of the security spec. Two shard reds this conversion caused are settled here, one per shard, and both failed on python and Windows alike because neither is environmental. test_only_baseline_modules_violate_the_rule[kiro_crew.security] is the one-storage ratchet reporting that the conversion worked. The baseline set records the modules that still hold a mapping to resolved owner MODULES, and it asserts in both directions, so a module that starts satisfying the rule reddens until it is de-listed. De-list it, which is what the assertion asks for, and correct the count in the module docstring from seven to six. That also promotes kiro_crew.security into COMPLIANT, so it picks up the purge cases with no edit there: it gains a fourth case, the sys.modules read that only compliant modules run. test_the_package_stays_within_its_line_budget is the package line ceiling. Resolving each re-exported name through its owner replaces one eager import block with two name lists, an owner table and a TYPE_CHECKING block at one line per exported name, which measured 618 lines at this surface: the facade goes from 3,035 lines to 3,653 and no other file in the package moves. That number's own comment defines the budget as the pre-split size plus room for the machinery, and this is the machinery it means, so the ceiling moves from main's 27,200 to 27,751. 27,751 is the package's measured total, not a figure above it. A ratchet with spare room admits exactly the unreviewed growth it exists to catch, so the number is pinned at the measurement and the comment says so: the next line added to this package fails this gate and has to be re-pinned deliberately. Proven tight rather than assumed -- appending three lines to security/vocabulary.py reddens the gate with "package grew to 27754 lines". The guards that actually detect a monolith growing back are untouched and hold with margin: the facade is 3,653 lines against a 4,500 per-file cap, and at 13% of the package it stays well inside the one-fifth share its own gate allows. The conversion leaves the export names written out in three places, and nothing checked the third, so add that pin. The TYPE_CHECKING block never executes, which is why no runtime assertion can notice it drifting: a name added to the owner table and forgotten there still resolves for every caller, and the only symptom is that type checkers and IDEs quietly stop knowing it. The new test reads the block from source and requires it to name every owned name, and to attribute each to the same module the owner table resolves it through. Two rebases have now proved that pin live, in both directions. The first: main added bounded_blocked_links and redact_exfiltration_urls_with_records to the eager import block this change removes, and both had to be entered in the owner table and the TYPE_CHECKING block. The second, onto #12879: main deleted _path_resolve_wedged and _wedged_workers from that block and from EXPORTED_NAMES, and the pin requires all three lists to agree, so both had to come out of the owner table and the TYPE_CHECKING block here. #12879 also rewrote test_security_path_resolve_bounded.py onto a subprocess-pool resolver that already patches security.paths rather than the facade, which is what this change asked of that file, so its version is taken unchanged and this branch no longer touches it.
045fc00 to
82bc5c0
Compare
bolichen97
left a comment
There was a problem hiding this comment.
Reviewed on behalf of the maintainers (sweep 2026-09-27): readiness passed, required checks green on 82bc5c0, no blocking review threads, security posture unchanged. Approving and merging.
…14543) The 7,925-line dashboard/handlers/source_providers.py held URL validation, the provider-CLI runner, three providers' reads, the ADF converter, two caches, the chip refresh loop and every write. Each now has one owner module under dashboard/source_providers/, moved verbatim. The handler keeps the /api/source/* routes, their audit and error mapping, and the dashboard owner gate. Every other name it defined still resolves there. Reads come from the owner and writes are forwarded to it, reusing the security package's re-export pattern (#13933), so existing imports and patches still reach the running code. Owners reach each other as modules and import only earlier owners, so the owners form no cycle. The owners that redact provider data join security_posture's non-egress allowlist in place of the handler. The spawn-audit tripwire now names runner._run_provider, the function that actually spawns. The dashboard spec records the owner map.
sandbox.py and platform_compat.py each held several separate responsibilities in one file. Five of them now live in their own modules, and each old module stays the import and patch surface: - sandbox_launcher: _build_launcher_script, the Linux namespace launcher program. - sandbox_seatbelt: the macOS Seatbelt profile and its builder. - sandbox_mount_sweep: the stale bind-mount source sweep that cleanup_stale_sandbox_profiles runs. - platform_lock_compat: the cross-process file locks and the persistence probe. - platform_owner_compat: account identity, the writability checks and the owner-only lockdown. Code moved verbatim. The builders and helpers import the tables, flags and helpers they read from the facade inside the function, so a patch on the facade still reaches them at call time. Both facades forward every moved name to its owner by resolution, reads and writes alike, following the security/ facade (#13933). Declared text edits on moved lines: - The generated launcher's docstring and one builder comment spell the product name as two words, as the brand gate requires. That docstring line is the only byte of the generated launcher that changes. - An owner-only docstring is reworded to satisfy the comment-history gate. - Comments and docstrings that placed moved code in its old file, or "above" it, now name the owner. New tests: - Pin both generated programs byte for byte against the pre-split builders, over a pinned host and pinned tables. - Pin the facade forwarding, the owner seams, the import direction and the loggers. - Refuse any create=True patch of a forwarded name. The owning specs (security.md, platform-compat.md) name the owners. Entry-scoped grants cover: - the platform-context.md owner citation; - the test_identity_topology registry key; - the darwin CI path filter; - the AUTOSDE file patterns; - the dogfood source-text guard, which now reads the ssh handling from the facade and both builder owners.
sandbox.py and platform_compat.py each held several separate responsibilities in one file. Five of them now live in their own modules, and each old module stays the import and patch surface: - sandbox_launcher: _build_launcher_script, the Linux namespace launcher program. - sandbox_seatbelt: the macOS Seatbelt profile and its builder. - sandbox_mount_sweep: the stale bind-mount source sweep that cleanup_stale_sandbox_profiles runs. - platform_lock_compat: the cross-process file locks and the persistence probe. - platform_owner_compat: account identity, the writability checks and the owner-only lockdown. Code moved verbatim. The builders and helpers import the tables, flags and helpers they read from the facade inside the function, so a patch on the facade still reaches them at call time. Both facades forward every moved name to its owner by resolution, reads and writes alike, following the security/ facade (#13933). Declared text edits on moved lines: - The generated launcher's docstring and one builder comment spell the product name as two words, as the brand gate requires. That docstring line is the only byte of the generated launcher that changes. - An owner-only docstring is reworded to satisfy the comment-history gate. - Comments and docstrings that placed moved code in its old file, or "above" it, now name the owner. New tests: - Pin both generated programs byte for byte against the pre-split builders, over a pinned host and pinned tables. - Pin the facade forwarding, the owner seams, the import direction and the loggers. - Refuse any create=True patch of a forwarded name. The owning specs (security.md, platform-compat.md) name the owners. Entry-scoped grants cover: - the platform-context.md owner citation; - the test_identity_topology registry key; - the darwin CI path filter; - the AUTOSDE file patterns; - the dogfood source-text guard, which now reads the ssh handling from the facade and both builder owners.
sandbox.py and platform_compat.py each held several separate responsibilities in one file. Five of them now live in their own modules, and each old module stays the import and patch surface: - sandbox_launcher: _build_launcher_script, the Linux namespace launcher program. - sandbox_seatbelt: the macOS Seatbelt profile and its builder. - sandbox_mount_sweep: the stale bind-mount source sweep that cleanup_stale_sandbox_profiles runs. - platform_lock_compat: the cross-process file locks and the persistence probe. - platform_owner_compat: account identity, the writability checks and the owner-only lockdown. Code moved verbatim. The builders and helpers import the tables, flags and helpers they read from the facade inside the function, so a patch on the facade still reaches them at call time. Both facades forward every moved name to its owner by resolution, reads and writes alike, following the security/ facade (#13933). Declared text edits on moved lines: - The generated launcher's docstring and one builder comment spell the product name as two words, as the brand gate requires. That docstring line is the only byte of the generated launcher that changes. - An owner-only docstring is reworded to satisfy the comment-history gate. - Comments and docstrings that placed moved code in its old file, or "above" it, now name the owner. New tests: - Pin both generated programs byte for byte against the pre-split builders, over a pinned host and pinned tables. - Pin the facade forwarding, the owner seams, the import direction and the loggers. - Refuse any create=True patch of a forwarded name. The owning specs (security.md, platform-compat.md) name the owners. Entry-scoped grants cover: - the platform-context.md owner citation; - the test_identity_topology registry key; - the darwin CI path filter; - the AUTOSDE file patterns; - the dogfood source-text guard, which now reads the ssh handling from the facade and both builder owners.
sandbox.py and platform_compat.py each held several separate responsibilities in one file. Five of them now live in their own modules, and each old module stays the import and patch surface: - sandbox_launcher: _build_launcher_script, the Linux namespace launcher program. - sandbox_seatbelt: the macOS Seatbelt profile and its builder. - sandbox_mount_sweep: the stale bind-mount source sweep that cleanup_stale_sandbox_profiles runs. - platform_lock_compat: the cross-process file locks and the persistence probe. - platform_owner_compat: account identity, the writability checks and the owner-only lockdown. Code moved verbatim. The builders and helpers import the tables, flags and helpers they read from the facade inside the function, so a patch on the facade still reaches them at call time. Both facades forward every moved name to its owner by resolution, reads and writes alike, following the security/ facade (#13933). Declared text edits on moved lines: - The generated launcher's docstring and one builder comment spell the product name as two words, as the brand gate requires. That docstring line is the only byte of the generated launcher that changes. - An owner-only docstring is reworded to satisfy the comment-history gate. - Comments and docstrings that placed moved code in its old file, or "above" it, now name the owner. New tests: - Pin both generated programs byte for byte against the pre-split builders, over a pinned host and pinned tables. - Pin the facade forwarding, the owner seams, the import direction and the loggers. - Refuse any create=True patch of a forwarded name. The owning specs (security.md, platform-compat.md) name the owners. Entry-scoped grants cover: - the platform-context.md owner citation; - the test_identity_topology registry key; - the darwin CI path filter; - the AUTOSDE file patterns; - the dogfood source-text guard, which now reads the ssh handling from the facade and both builder owners.
sandbox.py and platform_compat.py each held several separate responsibilities in one file. Five of them now live in their own modules, and each old module stays the import and patch surface: - sandbox_launcher: _build_launcher_script, the Linux namespace launcher program. - sandbox_seatbelt: the macOS Seatbelt profile and its builder. - sandbox_mount_sweep: the stale bind-mount source sweep that cleanup_stale_sandbox_profiles runs. - platform_lock_compat: the cross-process file locks and the persistence probe. - platform_owner_compat: account identity, the writability checks and the owner-only lockdown. Code moved verbatim. The builders and helpers import the tables, flags and helpers they read from the facade inside the function, so a patch on the facade still reaches them at call time. Both facades forward every moved name to its owner by resolution, reads and writes alike, following the security/ facade (#13933). Declared text edits on moved lines: - The generated launcher's docstring and one builder comment spell the product name as two words, as the brand gate requires. That docstring line is the only byte of the generated launcher that changes. - An owner-only docstring is reworded to satisfy the comment-history gate. - Comments and docstrings that placed moved code in its old file, or "above" it, now name the owner. New tests: - Pin both generated programs byte for byte against the pre-split builders, over a pinned host and pinned tables. - Pin the facade forwarding, the owner seams, the import direction and the loggers. - Refuse any create=True patch of a forwarded name. The owning specs (security.md, platform-compat.md) name the owners. Entry-scoped grants cover: - the platform-context.md owner citation; - the test_identity_topology registry key; - the darwin CI path filter; - the AUTOSDE file patterns; - the dogfood source-text guard, which now reads the ssh handling from the facade and both builder owners.
sandbox.py and platform_compat.py each held several separate responsibilities in one file. Five of them now live in their own modules, and each old module stays the import and patch surface: - sandbox_launcher: _build_launcher_script, the Linux namespace launcher program. - sandbox_seatbelt: the macOS Seatbelt profile and its builder. - sandbox_mount_sweep: the stale bind-mount source sweep that cleanup_stale_sandbox_profiles runs. - platform_lock_compat: the cross-process file locks and the persistence probe. - platform_owner_compat: account identity, the writability checks and the owner-only lockdown. Code moved verbatim. The builders and helpers import the tables, flags and helpers they read from the facade inside the function, so a patch on the facade still reaches them at call time. Both facades forward every moved name to its owner by resolution, reads and writes alike, following the security/ facade (#13933). Declared text edits on moved lines: - The generated launcher's docstring and one builder comment spell the product name as two words, as the brand gate requires. That docstring line is the only byte of the generated launcher that changes. - An owner-only docstring is reworded to satisfy the comment-history gate. - Comments and docstrings that placed moved code in its old file, or "above" it, now name the owner. New tests: - Pin both generated programs byte for byte against the pre-split builders, over a pinned host and pinned tables. - Pin the facade forwarding, the owner seams, the import direction and the loggers. - Refuse any create=True patch of a forwarded name. The owning specs (security.md, platform-compat.md) name the owners. Entry-scoped grants cover: - the platform-context.md owner citation; - the test_identity_topology registry key; - the darwin CI path filter; - the AUTOSDE file patterns; - the dogfood source-text guard, which now reads the ssh handling from the facade and both builder owners.
sandbox.py and platform_compat.py each held several separate responsibilities in one file. Five of them now live in their own modules, and each old module stays the import and patch surface: - sandbox_launcher: _build_launcher_script, the Linux namespace launcher program. - sandbox_seatbelt: the macOS Seatbelt profile and its builder. - sandbox_mount_sweep: the stale bind-mount source sweep that cleanup_stale_sandbox_profiles runs. - platform_lock_compat: the cross-process file locks and the persistence probe. - platform_owner_compat: account identity, the writability checks and the owner-only lockdown. Code moved verbatim. The builders and helpers import the tables, flags and helpers they read from the facade inside the function, so a patch on the facade still reaches them at call time. Both facades forward every moved name to its owner by resolution, reads and writes alike, following the security/ facade (#13933). Declared text edits on moved lines: - The generated launcher's docstring and one builder comment spell the product name as two words, as the brand gate requires. That docstring line is the only byte of the generated launcher that changes. - An owner-only docstring is reworded to satisfy the comment-history gate. - Comments and docstrings that placed moved code in its old file, or "above" it, now name the owner. New tests: - Pin both generated programs byte for byte against the pre-split builders, over a pinned host and pinned tables. - Pin the facade forwarding, the owner seams, the import direction and the loggers. - Refuse any create=True patch of a forwarded name. The owning specs (security.md, platform-compat.md) name the owners. Entry-scoped grants cover: - the platform-context.md owner citation; - the test_identity_topology registry key; - the darwin CI path filter; - the AUTOSDE file patterns; - the dogfood source-text guard, which now reads the ssh handling from the facade and both builder owners.
sandbox.py and platform_compat.py each held several separate responsibilities in one file. Five of them now live in their own modules, and each old module stays the import and patch surface: - sandbox_launcher: _build_launcher_script, the Linux namespace launcher program. - sandbox_seatbelt: the macOS Seatbelt profile and its builder. - sandbox_mount_sweep: the stale bind-mount source sweep that cleanup_stale_sandbox_profiles runs. - platform_lock_compat: the cross-process file locks and the persistence probe. - platform_owner_compat: account identity, the writability checks and the owner-only lockdown. Code moved verbatim. The builders and helpers import the tables, flags and helpers they read from the facade inside the function, so a patch on the facade still reaches them at call time. Both facades forward every moved name to its owner by resolution, reads and writes alike, following the security/ facade (#13933). Declared text edits on moved lines: - The generated launcher's docstring and one builder comment spell the product name as two words, as the brand gate requires. That docstring line is the only byte of the generated launcher that changes. - An owner-only docstring is reworded to satisfy the comment-history gate. - Comments and docstrings that placed moved code in its old file, or "above" it, now name the owner. New tests: - Pin both generated programs byte for byte against the pre-split builders, over a pinned host and pinned tables. - Pin the facade forwarding, the owner seams, the import direction and the loggers. - Refuse any create=True patch of a forwarded name. The owning specs (security.md, platform-compat.md) name the owners. Entry-scoped grants cover: - the platform-context.md owner citation; - the test_identity_topology registry key; - the darwin CI path filter; - the AUTOSDE file patterns; - the dogfood source-text guard, which now reads the ssh handling from the facade and both builder owners.
sandbox.py and platform_compat.py each held several separate responsibilities in one file. Five of them now live in their own modules, and each old module stays the import and patch surface: - sandbox_launcher: _build_launcher_script, the Linux namespace launcher program. - sandbox_seatbelt: the macOS Seatbelt profile and its builder. - sandbox_mount_sweep: the stale bind-mount source sweep that cleanup_stale_sandbox_profiles runs. - platform_lock_compat: the cross-process file locks and the persistence probe. - platform_owner_compat: account identity, the writability checks and the owner-only lockdown. Code moved verbatim. The builders and helpers import the tables, flags and helpers they read from the facade inside the function, so a patch on the facade still reaches them at call time. Both facades forward every moved name to its owner by resolution, reads and writes alike, following the security/ facade (#13933). Declared text edits on moved lines: - The generated launcher's docstring and one builder comment spell the product name as two words, as the brand gate requires. That docstring line is the only byte of the generated launcher that changes. - An owner-only docstring is reworded to satisfy the comment-history gate. - Comments and docstrings that placed moved code in its old file, or "above" it, now name the owner. New tests: - Pin both generated programs byte for byte against the pre-split builders, over a pinned host and pinned tables. - Pin the facade forwarding, the owner seams, the import direction and the loggers. - Refuse any create=True patch of a forwarded name. The owning specs (security.md, platform-compat.md) name the owners. Entry-scoped grants cover: - the platform-context.md owner citation; - the test_identity_topology registry key; - the darwin CI path filter; - the AUTOSDE file patterns; - the dogfood source-text guard, which now reads the ssh handling from the facade and both builder owners.
…es (#15309) sandbox.py and platform_compat.py each held several separate responsibilities in one file. Five of them now live in their own modules, and each old module stays the import and patch surface: - sandbox_launcher: _build_launcher_script, the Linux namespace launcher program. - sandbox_seatbelt: the macOS Seatbelt profile and its builder. - sandbox_mount_sweep: the stale bind-mount source sweep that cleanup_stale_sandbox_profiles runs. - platform_lock_compat: the cross-process file locks and the persistence probe. - platform_owner_compat: account identity, the writability checks and the owner-only lockdown. Code moved verbatim. The builders and helpers import the tables, flags and helpers they read from the facade inside the function, so a patch on the facade still reaches them at call time. Both facades forward every moved name to its owner by resolution, reads and writes alike, following the security/ facade (#13933). Declared text edits on moved lines: - The generated launcher's docstring and one builder comment spell the product name as two words, as the brand gate requires. That docstring line is the only byte of the generated launcher that changes. - An owner-only docstring is reworded to satisfy the comment-history gate. - Comments and docstrings that placed moved code in its old file, or "above" it, now name the owner. New tests: - Pin both generated programs byte for byte against the pre-split builders, over a pinned host and pinned tables. - Pin the facade forwarding, the owner seams, the import direction and the loggers. - Refuse any create=True patch of a forwarded name. The owning specs (security.md, platform-compat.md) name the owners. Entry-scoped grants cover: - the platform-context.md owner citation; - the test_identity_topology registry key; - the darwin CI path filter; - the AUTOSDE file patterns; - the dogfood source-text guard, which now reads the ssh handling from the facade and both builder owners.
Problem / Motivation
Goal: A test that patches a security control at its owner can trust that the code under test actually runs the patched control.
src/kiro_crew/security/__init__.pyis a facade: the security controls live in tensubmodules of the package while
kiro_crew.securitystays the import path, androughly forty modules reach the controls through it. It gave a re-exported name
two storage locations, and it did so for both halves of the name's identity.
The value. The facade bound every re-exported name in its own namespace eagerly,
with
from .paths import (...)and nine sibling statements. The submodule thatdefines the name held it too. The facade's copy answered every read, because the
facade had no module
__getattr__for those names.The owner.
_EXPORT_OWNERSmapped each name to the resolved owner moduleobject, and
_MirroringModule.__setattr__/__delattr__read owners out ofit. That is a second place a module is stored, beside
sys.modules.The forwarding ran in ONE direction. A write on the facade reached the owner;
nothing carried an owner write back, and no read consulted the owner. Measured on
the base revision, an owner write was invisible through the facade for 467 of
467 re-exported names -- not a future risk, the current behaviour on every name.
Why it matters
patch.object(<submodule>, ...)is how a test patches a control at its owner, andthe repository does it. After such a write, any reader that went through the
facade kept getting the pre-patch object: the test passes while the code under it
runs the control the test believes it replaced. Nothing reports the disagreement.
The owner half has a second shape. Purging a module from
sys.modulesandimporting it again is an ordinary test idiom, used in twenty files here. After the
purge,
_EXPORT_OWNERSstill held the discarded module, so a write through thefacade landed on a module nothing reads, while a direct importer saw the fresh one.
Measured on the base revision for a function name and a data name alike: the
facade's read matched the STALE module and not the fresh one, and a patch through
the facade did not reach the fresh module at all.
The failures surface far from the cause -- in another file, under some shard splits
and not others, with nothing pointing back.
Not a goal
__init__.py's own 2,929 lines of code into a submodule. That iswhat would let
kiro_crew.securityjointest/test_lazy_reexport_storage.py'sPACKAGESand retire this PR's pin file, and it is a separate change with itsown risk.
package DEFINES (
re,Path,SecurityEventLog,path_resolve_executor).There is no owner to resolve them through, so they stay ordinary attributes of
this module, with one storage location here.
conftesthook that fails any test leaving a module attributedisagreeing with its owner. That detector belongs beside the rule rather than
instead of it.
second storage location and would reintroduce exactly this defect.
What changed (motivation → approach → change)
Both halves now resolve through the import system, so there is one place the value
lives and one place the module lives. No mechanism keeps two copies in step,
because there is no second copy.
from .<submodule> import (...)statements move intoif TYPE_CHECKING:, so type checkers and IDEs keep every name while runtimebinds none of them.
_EXPORTSmaps each re-exported name to its owner submodule's NAME._submodule()resolves it by reading
sys.modules, the one place a module is stored, and callsimportlib.import_moduleonly on the miss -- the import POPULATES that store, itdoes not own the answer.
__getattr__reads the value off the owner on each access._ReExportModule.__setattr__/__delattr__forward a write to the owner, whichis what keeps a patch fixture's read-then-reassign round trip symmetric.
_EXPORT_OWNERS,_SUBMODULES,_export_owners()and_MirroringModulearegone. The spelling matches the six packages converted in fix: resolve a lazily re-exported name's owner through sys.modules #13727, including its
ban on a private owner mapping, so the two converge rather than needing
reconciliation later.
__all__is DERIVED from the table plus what this module binds, becausefrom kiro_crew.security import *is resolved by the import machinery against adeclared list and never reaches
__getattr__. Without it a star import carriedonly the names this module holds -- measured at 81 public names against the base
revision's 142, with
is_sensitive_path,redact_credentialsandCREDENTIAL_REDACTION_TAGSamong the missing, so a star importer's first usewould raise
NameError. Deriving it rather than writing it out is what keeps it aprojection of the table instead of a third list of names to keep in step.
Why the resolved read does not call
importlib.import_module. That function is anattribute of a module any caller can rebind, and callers do: three sites in this
repository install
patch("importlib.import_module")for reasons of their own. Withit on the resolved path, every read of every gate here was answered by whatever that
patch returned for as long as it was installed --
set(security._SENSITIVE_HOME_DIRS)became an empty set built from a
MagicMock, and the governance boot check refusedwith its trust-root paths reported missing. Reading
sys.modulesfirst removes thecoupling: the store answers, and no unrelated patch can stand between a security
predicate and its owner. A test that needs an unresolvable owner now makes one the
way the condition really occurs -- absent from
sys.modulesand refusing to import.The chain from symptom to root cause: a facade that BINDS a name has a copy; a copy
is only correct at the moment it is made; an owner write happens after that moment;
so the copy answers with a superseded object. Removing the binding removes the
copy, and there is then nothing that can be stale. The same argument one level up
for the module: a map of resolved module objects is a copy of
sys.modules, andimport_moduleissys.modules.Three things this change had to handle that a thin re-export shim does not.
__init__.pyholds 2,929 lines of its own code, and 74 of its own loadsites read a re-exported name. A function defined here resolves a bare global
through this module's namespace, which
__getattr__never sees, so those readswould only work if the facade bound the names -- the copy being removed. All 74
now ask for the owner and read the name off it. Enumerated by condition (any
Loadof a table name at any nesting depth), which is how the five sites insideStreamRedactorand the one inside a nested_reasonwere found rather thanthe twelve top-level functions that resemble each other.
is_deniedalone holds 38 of those sites, and it is the per-tool-callpredicate. It resolves its four owners ONCE per call rather than per read.
That is a one-shot build input, not a stored re-export, and it reads off the
submodule directly -- the resolver is defined later, with the rest of the
machinery, after this module has finished binding its own names.
Fail-closed, ruled on deliberately rather than left as a footnote. A read can now
raise
ImportErrorwhere it could not before, and on a security predicate thehazard is not the exception -- it is an exception quietly becoming a falsy answer.
getattr(security, "is_sensitive_path", None)swallowsAttributeErrorand letsImportErrorthrough, so the facade raisesImportErrorfor a table name whoseowner will not import, and
AttributeErroronly for a name that does not exist.A
Nonethat a caller reads as "not sensitive" would grant exactly what the gaterefuses, and cannot now be produced. The repository's own guards already rest on
that distinction:
spec_builder's parser wraps its import, and with no securitymodule its
is_sensitive_pathfallback answersTruefor every path.Organizational security guidance was consulted before writing this, and it says
what is pinned above: a component's default behaviour on failure must be to deny.
The tool that normally serves that guidance is not reachable from this session, so
the fail-closed default was taken rather than any policy being invented.
Disclosed cost, both revisions measured in one window with one harness, four
alternating runs each. A single read of a re-exported name through the facade costs
about 482 ns against the base's 42 ns, because it resolves the owner and reads the
name instead of hitting a local dict. No cache was added to hide that, for the
reason under Not a goal. End to end the hot predicate is unchanged:
is_deniedonthe same command measured 363 us per call on this branch against 358 us on the
base, about 1% and inside the base's own 5 us run-to-run spread on this box,
because it resolves each owner once per call rather than once per read.
Three test sites moved rather than being kept working by a sync mechanism, all one
class: a name the facade does not define, patched or enumerated on the facade, whose
reader is elsewhere. Six more were in
test_security_path_resolve_bounded.py,patching
security.pathsforpath_resolve_executor; #12879 rewrote that file ontoa subprocess-pool resolver that already patches
security.paths, so its version istaken unchanged and this branch no longer touches it. Of the three that remain, two
patch
security.exfilforSecurityEventLog, which comes fromkiro_crew.seland whichexfil._emit_oauth_extension_used_eventreads throughexfil's globals -- one of those two was failing loudly and the other was degradingsilently and writing real SEL events. One is the credential-redaction-tag ratchet,
which enumerated
vars(security)for_REDACTED_*_TAGconstants and now enumeratesvars(security.redaction), the namespace that defines them; left on the facade itfound nothing and stopped guarding the tag registry.
Two package-shape gates report this conversion, and both are answered as the gate
asks rather than muffled.
test_only_baseline_modules_violate_the_rule[kiro_crew.security]is the one-storageratchet reporting that the conversion WORKED. Its baseline set records the modules
that still map a name to a resolved owner module, and it asserts in both directions,
so a module that starts satisfying the rule reddens until it is de-listed. It is
de-listed here, and the module docstring's count corrected from seven to six. That
promotes
kiro_crew.securityintoCOMPLIANT, which earns it a fourth case with noedit there: the
sys.modulesread only compliant modules run.test_the_package_stays_within_its_line_budgetis the package line ceiling.Resolving each name through its owner replaces one eager import block with two name
lists -- an owner table and a
TYPE_CHECKINGblock, one line per exported name ineach -- which measured 618 lines at this surface: the facade goes from 3,035 lines
to 3,653 and no other file in the package moves. That ceiling's own comment defines
it as the pre-split size plus room for the machinery, and this is the machinery it
means, so it moves from main's 27,200 to 27,751.
27,751 is the package's measured total, not a figure above it. A ceiling with spare
room admits exactly the unreviewed growth the ratchet exists to catch, so the number
is pinned at the measurement and the comment says so: the next line added to this
package fails this gate and has to be re-pinned deliberately. Proven tight rather
than assumed -- appending three lines to
security/vocabulary.pyreddens it with"package grew to 27754 lines". The guards that actually detect a monolith growing
back are untouched and hold with margin: the facade is 3,653 lines against a
4,500 per-file cap, the largest file in the package is
argv_floor.pyat 4,132, andat 13% of the package the facade stays well inside the one-fifth share its own gate
allows.
docs/system-specs/modules/security.mdis updated in the same commit, as the owningspec for this module must be. Its facade section described the mechanism this change
replaces -- a frozen manifest plus patch mirroring, with
_SUBMODULESnamed -- andnow states re-export by resolution, where the value and the module each live, the
boundary for a name this package does not define, and the fail-closed
ImportErrorrule.
Backwards compatibility
Compatible on the public surface. The star-import surface goes from 142 public names
on the base to 143 here; the single addition is
importlib, which the runtimeresolution imports.
Anymoved underTYPE_CHECKING, where postponed annotationsneed it, so it adds nothing. Every other name is carried name for name.
Two changes are real and deliberate, and neither has a reader outside this package.
_EXPORT_OWNERS,_SUBMODULES,_export_owners()and_MirroringModuleareremoved. Writer sweep on origin/main @
c203fac29e4b, whole repository: no readeroutside
src/kiro_crew/security/and this PR's own diff._export_ownershas noreader anywhere;
_SUBMODULESappears indocs/system-specs/modules/security.mdand
test/test_security_facade.py, and_MirroringModuleintest/test_security_facade.py-- all three files are updated in this PR. The_EXPORT_OWNERShits elsewhere aredev_fleet/server.py's own unrelated symbol ofthe same name, not a reader of this one.
A read of a table name can now raise
ImportErrorwhere it previously could not.This TIGHTENS behaviour for a caller using
getattr(security, name, default)andrelying on the default: the default no longer absorbs an unimportable owner. That is
the point, argued under fail-closed above -- a swallowed failure on a security
predicate grants what the gate refuses.
AttributeErrorfor a name that does notexist is unchanged, so
getattrwith a default still behaves as before for the caseit was written for.
Tests
test/test_security_single_storage.pyis new and holds the rule. Its cases aregenerated from the package's own
_EXPORTStable, so the subject is the condition-- every re-exported name -- and not the sites this change happened to touch.
2,869 cases pass with
test_security_facade.py.It asserts single storage rather than the edits: the facade binds no table name and
a read does not bind one; a read answers with the owner's object; an owner write is
seen through the facade and a facade write reaches the owner; the table holds no
module object; a replaced owner and a genuinely purged-and-reimported owner are both
seen at once by a read AND by a write; a resolved owner is read without calling
importlib.import_moduleat all, asserted by refusing that call outright; thefacade's own code reads no table name as a bare global; every public table name is
declared and resolvable while no private one is, and the declared list is derived
from the table rather than written out; no submodule this package binds disagrees
with
sys.modules; and each of five path gates raisesImportErrorrather thananswering when its owner will not resolve, including through
getattr(..., default).test_the_type_checking_block_names_every_owned_nameintest/test_security_facade.pyis new and pins the third copy of the name list. The conversion leaves the export
names written out in three places, and nothing checked the
TYPE_CHECKINGblock.That block never executes, which is why no runtime assertion can notice it drifting:
a name added to the owner table and forgotten there still resolves for every caller,
and the only symptom is that type checkers and IDEs quietly stop knowing it. The
test reads the block from source and requires it to name every owned name, and to
attribute each to the same module the owner table resolves it through. Rebasing this
branch proved it live: main added
bounded_blocked_linksandredact_exfiltration_urls_with_recordsto the eager import block this changeremoves, and the pin is what required both to be entered in the owner table and the
TYPE_CHECKINGblock rather than silently lost from one of them.The star-import cases assert the contents of
__all__rather than running a starimport. What the import statement does with that list is the language's; what is in
it is this module's. Running one also meant
exec, which the SAST lane flags as afinding in its own right, and suppressing a security rule to test a security module
is the wrong trade when the same properties are directly assertable.
A purge test changes two things, not one, and both are restored together by one
context manager the file's purge cases share.
sys.modulesis the obvious one. Theother is this package's own attribute:
importlibfinishes a submodule import bysetting it on the parent package, and that leaf name is an
_EXPORTSVALUE ratherthan a key, so the write lands on the package itself. A restore of
sys.modulesalone therefore left
security.pathspointing at a module no reader runs, and everylater
monkeypatch.setattr(security.paths, ...)in that worker would have patchedthe dead copy. That is this issue's own defect reproduced inside the harness meant
to catch it, so the teardown proves itself rather than being trusted: on the path
where the body succeeded, the context manager reads the binding back and asserts it
is the object
sys.modulesholds, and a separate case reads every submodule bindingthe same way, so a leak left by any case in the worker fails here instead of
surfacing later as a patch that reaches nobody.
Mutation, with a passing control and a hash proving each patch applied. Eleven
mutations, each re-introducing a second storage, removing a declared surface, or
weakening the harness's own teardown from a DIFFERENT place, and the pin went red for
all eleven. Control: the selected cases pass unmutated. Every mutation changed the
file's hash, and each file was restored to its reference hash afterwards.
globals()AttributeError__all__is deleted, so a star import loses the re-exports__all__is written out as a literal list of namessys.modulesonlyM3 is worth naming: its first form inserted the module object at the top of the
dict literal, where the later literal key for the same name overrode it. The hash
changed but the mutation had no effect, and it scored as MISSED. Replacing the
existing entry instead made it real, and the pin caught it. A mutation harness
without a hash check and a control would have read that as a weak pin.
A separate four-mutation harness covers the two package-shape gates: restoring the
line budget to its pre-change value, re-listing
kiro_crew.securityin the ratchetbaseline, dropping one
TYPE_CHECKINGimport, and misattributing one. All four wentred, with a green control. Each substitution was asserted to match exactly one site,
and restores come from pristine copies held outside the repository so a re-run cannot
revert working tree changes.
Suites run, on the rebased tree against base
c203fac29e4b:test_security_single_storage.py,test_security_facade.pyandtest_mirrored_owner_storage.py(2,890 together),test_security_gate_liveness.py(10),test_security_path_resolve_bounded.py(82) -- #12879's own file, unchanged herebut run because this change is what it reads a re-exported name through --
test_push_branch_gate.py,test_denied_commands_security.pyandtest_cli.py::TestMcpBuiltinDispatch(1,398 together, 1 skipped), andtest_security.pyscoped by node id to the three tests this change touches (3).4,383 passed, 1 skipped, 0 failed. Gates: black, isort and flake8 clean on all
six changed Python files, and mypy reports nothing in any of them. mypy does follow
imports into two files this change never touches:
src/kiro_crew/transcribe.py(2,byte-identical to main) and
test_security.pyitself (21) -- main's own copy ofthat file reports the identical 21, error text for error text. The full suite is
CI's.
Before and after on one probe, run against both revisions:
Manual verification
N/A -- unit coverage sufficient. This change has no user-visible surface: it alters
how one package resolves its own re-exported names, and every property claimed above
is asserted by a test rather than observed by hand. The one thing a human could check
that a test cannot -- that type checkers still see all 468 names -- is covered by
mypy running clean over the facade plus the new
TYPE_CHECKINGpin.Related Issues
Fixes #13784
Pattern harvest
Rule candidate: when one value is mirrored into two places with one-way
synchronisation, delete the second place and derive it, rather than adding the
missing direction. A second copy kept in sync is a cross-file contract someone has
to remember; the direction that is missing today is evidence the contract already
decayed. Here the missing direction was owner-to-facade, and adding it would have
left the copy and needed a third mechanism for the purge case. Removing the copy
closed both halves at once.
Rule candidate: enumerate a fix's sites by the CONDITION that defines them, read
off the source, not by resemblance to the site the report named. The condition here
was "any
Loadof a table name at any nesting depth", which found six sites insidea class method and a nested function that a sweep of top-level functions missed --
each of which would have been a
NameErroron a path no test may cover.Rule candidate: when a value is read on demand rather than held, read the STORE and
let the populating call answer only the miss.
sys.modulesis where a module lives;importlib.import_moduleis how it gets there, and it is a rebindable attribute ofanother module. Putting the populating call on the resolved path made an unrelated
patch("importlib.import_module")in a test able to answer a security gate's read,and the reader could not tell. The same shape applies to any lazily resolved value
whose resolver is reachable and replaceable by a third party.
Rule candidate: a conversion that writes the same list of names into more than one
place needs a pin per copy, and the copy that needs it most is the one that never
executes. A
TYPE_CHECKINGblock cannot be checked by any runtime assertion, so itdrifts silently and the only symptom is a type checker quietly losing a name. This
rebase demonstrated the failure mode on live code.
Not generalizable: the choice to resolve
is_denied's four owners once per callrather than per read is specific to a predicate that reads 38 names on a per-tool-
call path. Elsewhere in this change a per-read resolution is both simpler and
cheap enough.
Checklist
docs/system-specs/modules/security.md)