Skip to content

Owner moves: cached org policy content is verified against its pin before use - #4315

Merged
Daniel Meppiel (danielmeppiel) merged 15 commits into
mainfrom
danielmeppiel-h-a2-policy-cache-pin
Nov 21, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 15 commits into
mainfrom
danielmeppiel-h-a2-policy-cache-pin

Conversation

@danielmeppiel

Copy link
Copy Markdown
Collaborator

Description

Part of the 0.37 trust and integrity consistency hardening (owner consolidation):

  • Cached org policy content is verified against its pin through the policy discovery owner before any command uses it. The single 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 already report the hash mismatch outcome, which policy outcome routing (Owner moves: one policy-outcome routing owner for every policy reader #4151) always blocks.
  • Closed-world guard install-deployment-policy-cache-pin: only policy/discovery.py locates the policy cache, and only _read_cache_entry parses a cached document, after verification. One mutation case. Owner entry cached-policy-shape extended.

Issue and approved scope

Fixes #4218 -- scope record: #4218 (comment)

Completes the issue.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)

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 next apm install stays exit 0 with the project unchanged).
Owner: tests/unit/policy/test_cache_merged_effective.py::test_altered_cached_policy_document_is_ignored.

Changelog

  • One line in one section under ## [Unreleased] in CHANGELOG.md.
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

apm-spec-waiver: integrity hardening of the existing policy hash pin; cached policy content is verified before use, no new normative behaviour

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]>
@danielmeppiel Daniel Meppiel (danielmeppiel) added this to the 0.37.0 milestone Nov 20, 2026
Copilot AI balanced review requested due to automatic review settings 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]>

Copilot AI 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.

🟡 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

Comment thread src/apm_cli/policy/discovery.py Resolved
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]>
…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
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]>
@danielmeppiel Daniel Meppiel (danielmeppiel) added the full-integration Run the full integration suite (ci-integration.yml) on this PR before merge label Nov 20, 2026
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 0ea4d13 into main Nov 21, 2026
102 of 104 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-h-a2-policy-cache-pin branch November 21, 2026 05:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full-integration Run the full integration suite (ci-integration.yml) on this PR before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Trust and integrity consistency: cached policy content is verified against its pin

2 participants