Repository navigation
Owner moves: cached org policy content is verified against its pin before use - #4315
Merged
Daniel Meppiel (danielmeppiel) merged 15 commits intoNov 21, 2026
Merged
Conversation
The policy cache reader (policy/discovery.py _read_cache_entry) checks a cached policy document against the fingerprint recorded with it before parsing, and parses the verified text. An altered document is never applied: the policy is fetched again and checked against the project policy.hash pin; cache-only reads of a pinned project report the existing hash mismatch outcome. Closed-world guard install-deployment-policy-cache-pin with one mutation case; ledger row. Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel)
requested a review
from Sergio Sisternes (sergio-sisternes-epam)
as a code owner
November 20, 2026 12:45
apm-spec-waiver: integrity hardening of the existing policy hash pin; cached policy content is verified before use, no new normative behaviour Co-authored-by: Copilot App <[email protected]>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
A pinned-cache integrity failure can allow installation without organization policy enforcement when refresh fails, and the linter does not reliably enforce rejection or verification before parsing.
2 open issues
What changed in this PR
This PR strengthens org-policy cache integrity in APM’s shared discovery reader, addressing #4218 as part of the trust and integrity hardening work.
Changes:
- Checks cached policy text against its recorded fingerprint before parsing.
- Adds an architecture guard and extends the cache owner contract.
- Adds unit and installed-CLI regression coverage, mutation coverage, and release notes.
| File | Description |
|---|---|
tests/unit/scripts/test_architecture_runner.py |
Registers the new guard in the expected rule inventory. |
tests/unit/policy/test_cache_merged_effective.py |
Tests rejection of altered cached policy documents. |
tests/integration/test_policy_cache_pin_lifecycle.py |
Tests installed-CLI recovery after cached policy alteration. |
tests/integration/test_architecture_owner_rule_mutations.py |
Adds a mutation removing cache verification. |
tests/fixtures/lifecycle_bug_ledger.json |
Records the issue and regression coverage. |
src/apm_cli/policy/discovery.py |
Verifies cached text and parses that same text. |
scripts/architecture_linter/checks/install_policy_cache_pin.py |
Adds checks for cache ownership and verification. |
scripts/architecture_linter/checks/install_deployment_analyzers.py |
Registers the cache-verification guard. |
CHANGELOG.md |
Announces the cache-integrity change. |
.apm/architecture/owners/contracts-tooling.json |
Extends the cache owner contract and links its guard. |
Review effort: Balanced
Co-authored-by: Copilot App <[email protected]>
…per step Co-authored-by: Copilot App <[email protected]>
…dger sorted _read_cache_entry asks _cached_policy_verified (pin and recorded fingerprint) once, within the Stage 2 return limit. The 4218 ledger row sits in issue order. The mutation case drops the fingerprint check only. Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]> # Conflicts: # tests/fixtures/lifecycle_bug_ledger.json
… hash mismatch When a pinned project's persisted policy cache entry fails verification and the policy cannot be fetched again, discovery reports the blocking hash_mismatch outcome instead of a fetch failure, across every org policy candidate. The cache-pin guard checks the reader's AST: the rejecting branch precedes load_policy on the verified text. Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
…tadata together A reader now rejects a cached document whose recorded fingerprint differs, so concurrent in-process writers of one cache key must not interleave the document of one write with the metadata of another. Co-authored-by: Copilot App <[email protected]>
discovery.py stays under the file-length guardrail: the verification helpers and pinned-cache outcomes move to a sibling module that discovery re-exports; _read_cache_entry stays the only cache reader. The cache-pin guard checks both files. The patched offline unit test is dropped (the installed-CLI offline test covers it) and the owner unit test observes the cache document it leaves behind. Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]> # Conflicts: # tests/fixtures/lifecycle_bug_ledger.json
This was referenced Nov 20, 2026
Co-authored-by: Copilot App <[email protected]> # Conflicts: # tests/fixtures/lifecycle_bug_ledger.json
Daniel Meppiel (danielmeppiel)
added a commit
that referenced
this pull request
Nov 20, 2026
… against its pin before use Co-authored-by: Copilot App <[email protected]> # Conflicts: # scripts/architecture_linter/checks/install_deployment_analyzers.py # tests/fixtures/lifecycle_bug_ledger.json
This was referenced Nov 20, 2026
The policy-hash-pin disk-or-cache cells for install, frozen and audit-ci were strict expected failures pending cached policy verification; the fix verifies a cached document against its recorded fingerprint before use, so they are plain required cells now. Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel)
added a commit
that referenced
this pull request
Nov 20, 2026
…4485, #4294, #4315, #4505 Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel)
merged commit Nov 21, 2026
0ea4d13
into
main
102 of 104 checks passed
Daniel Meppiel (danielmeppiel)
deleted the
danielmeppiel-h-a2-policy-cache-pin
branch
November 21, 2026 05:24
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Description
Part of the 0.37 trust and integrity consistency hardening (owner consolidation):
policy/discovery.py_read_cache_entry) checks a cached policy document against the fingerprint recorded with it before parsing, and parses the verified text. An altered document is never applied: the policy is fetched again and checked against the projectpolicy.hashpin. Cache-only reads of a pinned project already report the hash mismatch outcome, which policy outcome routing (Owner moves: one policy-outcome routing owner for every policy reader #4151) always blocks.install-deployment-policy-cache-pin: onlypolicy/discovery.pylocates the policy cache, and only_read_cache_entryparses a cached document, after verification. One mutation case. Owner entrycached-policy-shapeextended.Issue and approved scope
Fixes #4218 -- scope record: #4218 (comment)
Completes the issue.
Type of change
Testing
Installed CLI:
tests/integration/test_policy_cache_pin_lifecycle.py::test_altered_cached_policy_is_not_applied(pinned org policy over the loopback HTTPS fixture; the cached document is edited to deny the installed package; the nextapm installstays exit 0 with the project unchanged).Owner:
tests/unit/policy/test_cache_merged_effective.py::test_altered_cached_policy_document_is_ignored.Changelog
## [Unreleased]inCHANGELOG.md.Spec conformance (OpenAPM v0.1)
apm installtime, not only inapm audit --ci#827) now also covers the cached policy document.apm-spec-waiver: integrity hardening of the existing policy hash pin; cached policy content is verified before use, no new normative behaviour