Repository navigation
[0.38] feat(policy): add --policy to apm install and apm update (#1925) - #4001
Merged
Daniel Meppiel (danielmeppiel) merged 13 commits intoNov 22, 2026
Merged
Conversation
Daniel Meppiel (danielmeppiel)
force-pushed
the
danielmeppiel-literate-carnival
branch
2 times, most recently
from
November 19, 2026 23:57
1feee19 to
35b2a16
Compare
Closed
5 of 14 tasks
Daniel Meppiel (danielmeppiel)
force-pushed
the
danielmeppiel-literate-carnival
branch
3 times, most recently
from
November 21, 2026 10:08
1784138 to
17f80e7
Compare
10 of 14 tasks
Daniel Meppiel (danielmeppiel)
force-pushed
the
danielmeppiel-literate-carnival
branch
2 times, most recently
from
November 21, 2026 11:25
c08e4b6 to
9539d49
Compare
Closed
9 of 14 tasks
Daniel Meppiel (danielmeppiel)
marked this pull request as ready for review
November 21, 2026 11:38
Daniel Meppiel (danielmeppiel)
requested a review
from Sergio Sisternes (sergio-sisternes-epam)
as a code owner
November 21, 2026 11:38
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Empty-project install and update paths bypass policy preflight, allowing commands with missing explicit policy sources to succeed despite blocking fetch-failure settings.
5 open issues
What changed in this PR
Adds explicit policy sources to apm install and apm update, extending install-time governance to plain-git, other-host and air-gapped projects for #1925.
Changes:
- Adds shared
--policyhandling and tighten-only composition with discovered policy. - Routes unavailable sources through
policy.fetch_failure_defaultand expands policy-source reporting. - Adds regression coverage, architecture guards, documentation and proposed OpenAPM amendment 0.1.75; spec adoption remains pending.
| File | Description |
|---|---|
tests/unit/scripts/test_architecture_runner.py |
Registers the new guard in the expected inventory. |
tests/unit/policy/test_help_consistency.py |
Checks install/update policy help consistency. |
tests/unit/policy/test_explicit_policy_source.py |
Tests composition, failure routing and reporting. |
tests/unit/policy/test_explicit_policy_flags.py |
Tests rejected flag combinations. |
tests/unit/core/test_no_policy_bypass_advice.py |
Allows the mutual-exclusion usage message. |
tests/spec_conformance/test_policy_reqs.py |
Adds req-pl-022 conformance coverage. |
tests/lifecycle/journeys/goldens/E01/03.txt |
Records audit’s policy-source banner. |
tests/lifecycle/generator/rules.py |
Updates audit source-line citations. |
tests/integration/test_explicit_policy_source_lifecycle.py |
Exercises enforcement and unavailable-source behavior through the CLI. |
tests/integration/test_architecture_owner_rule_mutations.py |
Tests detection of reversed composition order. |
src/apm_cli/security/trust.py |
Marks partially loaded policy as unavailable for trust decisions. |
src/apm_cli/policy/project_config.py |
Receives the hash-pin parsing helper. |
src/apm_cli/policy/outcome_routing.py |
Classifies and reports unavailable composed sources. |
src/apm_cli/policy/explicit_source.py |
Owns invocation binding and policy composition. |
src/apm_cli/policy/discovery.py |
Integrates explicit-source composition into discovery. |
src/apm_cli/policy/_help_text.py |
Defines shared explicit-policy help text. |
src/apm_cli/core/command_logger.py |
Adds explicit-source and unavailable-source reporting. |
src/apm_cli/commands/update.py |
Exposes --policy for update. |
src/apm_cli/commands/install.py |
Exposes --policy for install. |
src/apm_cli/commands/audit.py |
Reports effective policy in text mode. |
src/apm_cli/commands/_helpers.py |
Binds the source and validates flag combinations. |
scripts/architecture_linter/checks/install_policy_intent.py |
Registers the explicit-policy ownership rule. |
scripts/architecture_linter/checks/install_policy_explicit_source.py |
Guards binding, composition and merge order. |
packages/apm-guide/.apm/skills/apm-usage/governance.md |
Documents explicit-policy governance semantics. |
packages/apm-guide/.apm/skills/apm-usage/commands.md |
Adds policy options to command guidance. |
docs/src/content/docs/specs/openapm-v0.1.md |
Proposes composition and failure-handling requirements. |
docs/src/content/docs/reference/cli/update.md |
Documents update’s policy option. |
docs/src/content/docs/reference/cli/install.md |
Documents install’s policy option. |
docs/src/content/docs/enterprise/registry-proxy.md |
Adds explicit policy to disconnected-install guidance. |
docs/src/content/docs/enterprise/apm-policy.mdx |
Explains policies beyond auto-discovery. |
docs/public/specs/manifests/openapm-v0.1.requirements.yml |
Lists proposed req-pl-022. |
CONFORMANCE.md |
Adds human-readable requirement coverage. |
CONFORMANCE.json |
Adds machine-readable requirement coverage. |
CHANGELOG.md |
Announces explicit install/update policies. |
.apm/architecture/owners/install-deployment.json |
Registers the explicit-policy canonical owner. |
Review effort: Balanced
6 of 17 tasks
Daniel Meppiel (danielmeppiel)
force-pushed
the
danielmeppiel-literate-carnival
branch
from
November 21, 2026 13:05
9539d49 to
c01d9a4
Compare
Daniel Meppiel (danielmeppiel)
added a commit
that referenced
this pull request
Nov 21, 2026
Co-authored-by: Copilot App <[email protected]>
Collaborator
Author
|
CEO sign-off: OpenAPM spec amendment 0.1.75 (D5) This records a CEO-signed spec amendment, not an org-level scope approval.
|
An explicit policy source (local path, owner/repo, https URL) is bound per invocation and composed with auto-discovered org policy through the existing tighten-only inheritance merge, so it can only add constraints. A source that cannot be loaded follows policy.fetch_failure_default. Effective policy sources are reported by install, update and audit --ci. Owner: policy/explicit_source.py, guarded by install-deployment-explicit-policy-source-owner. Co-authored-by: copilot-swe-agent[bot] <[email protected]>
#1925) On main the routing owner classifies first (classify_discovery_outcome); a composed --policy source that did not load now leaves the route unresolved (DiscoveryRoute.unavailable_source) and blocks when that source alone would block, so update reconcile, exec gate and MCP admission see a partial policy as unresolved with no change of their own. The update no-change path already routes through the preflight (#4458), so route_unavailable_explicit_sources is dropped. _TrustReaderLog forwards policy_source_unavailable (red-first test). The outcome sets move to outcome_routing.py; _split_hash_pin moves to project_config.py to keep discovery.py under the length cap. Tests: tm006 markers, injected resolve instead of patching discovery (AQ004), observable lifecycle assertions (AQ003), CLI flag test in its own component module. Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…or install/update (#1925) Proposed OpenAPM v0.1 amendment 0.1.70 (provisional number, renumbered at merge). Adds req-pl-022: an install or update operation that accepts an explicit policy source composes it tighten-only with discovered policy, uses it alone when nothing is discovered, applies the consumer policy.fetch_failure_default when it cannot be loaded, and reports every policy source in effect. Scopes req-pl-001 and req-pl-021 to an explicit --policy that replaces discovery (audit --ci --policy), which is unchanged. Informative note records the warn fail-open risk. Droppable: this commit carries the spec text, manifest row, Appendix C row, CONFORMANCE regeneration and req-pl-022 conformance tests only. Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…1925) The --policy/--no-policy mutual-exclusion usage error declares the escape hatch, so explicit_policy_option joins the RA-015 allowlist. E01 step 3 golden regenerated with regen_goldens.py: audit --ci text mode now names the effective policy source. Co-authored-by: Copilot App <[email protected]>
#4559 keeps 0.1.74 per the program ruling. Co-authored-by: Copilot App <[email protected]>
…ine (#1925) Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Per the approved #1925 record (Regent ruling, option 2): a named --policy source that cannot be resolved, fetched or parsed, or publishes no policy, exits non-zero before any deployment write whatever policy.fetch_failure_default says; a valid stale cached copy counts as loaded. A failed discovered policy keeps its own routing. Diagnostics name whether the explicit or the discovered source failed. Spec 0.1.75 req-pl-022 (c) now fails closed and req-pl-021 stays as written; docs, apm-usage governance.md/commands.md, help text and CHANGELOG updated. Co-authored-by: Copilot App <[email protected]>
#1925) - install and update with no APM dependencies still load and route an active --policy source (fail closed); the owner decides when (explicit_source_needs_standalone_check) - an explicit policy source is always named, even with enforcement off - each unavailable-source line prints once per invocation - spec count sites (Section 1.3, Appendix C) say 152 (147 MUST) Co-authored-by: Copilot App <[email protected]>
…1925) D5 signed: the 0.1.75 row, the statement-count sentence, the adoption paragraph and the requirements-manifest note now record adoption by editor decision (#4001 issuecomment-7065857135). The [Unreleased] bullet moves to changelog.d/4001.added.md (#4599). Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel)
force-pushed
the
danielmeppiel-literate-carnival
branch
from
November 21, 2026 16:46
1115d2a to
23f4472
Compare
Daniel Meppiel (danielmeppiel)
added a commit
that referenced
this pull request
Nov 21, 2026
…4295) 0.1.75 is claimed by #4001 (req-pl-022) and 0.1.74 by #4559. Supersedes: #4603 Co-authored-by: Copilot App <[email protected]>
Merged
10 of 14 tasks
Daniel Meppiel (danielmeppiel)
added a commit
that referenced
this pull request
Nov 21, 2026
…4295) 0.1.75 is claimed by #4001 (req-pl-022) and 0.1.74 by #4559. Supersedes: #4603 Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel)
added a commit
that referenced
this pull request
Nov 21, 2026
Daniel Meppiel (danielmeppiel)
added a commit
that referenced
this pull request
Nov 21, 2026
governance.md still said an unloadable explicit source follows policy.fetch_failure_default (the superseded fail-open wording). After the fail-closed ruling it always blocks before any write; only a failed discovered policy follows that default. Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel)
added a commit
that referenced
this pull request
Nov 21, 2026
Daniel Meppiel (danielmeppiel)
added a commit
that referenced
this pull request
Nov 21, 2026
This was referenced Nov 21, 2026
Daniel Meppiel (danielmeppiel)
deleted the
danielmeppiel-literate-carnival
branch
November 22, 2026 08:21
Daniel Meppiel (danielmeppiel)
added a commit
that referenced
this pull request
Nov 22, 2026
#4001 passes the fetch result's explicit flag to logger.policy_resolved. Assert it for both explicit and discovered sources. Co-authored-by: Copilot App <[email protected]>
This was referenced Nov 22, 2026
Merged
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
apm install --policy <source>andapm update --policy <source>enforce a policy that auto-discovery cannot reach: plain git remotes, other hosts, and air-gapped installs (a local path needs no network). The source takes the same forms asapm audit --ci --policy: a local path,owner/repo, or anhttps://URL.inheritance.merge_policies, so it can add constraints but never re-allow a denied dependency or lowerenforcement.--policycannot be resolved, fetched or parsed, or publishes no policy, install and update exit non-zero before any write, whateverpolicy.fetch_failure_defaultsays, with a diagnostic that names the explicit source (credentials redacted) and the cause. A valid stale cached copy counts as loaded. A failed discovered policy keeps followingpolicy.fetch_failure_default, and its diagnostic says it is the discovered source.--policyis used, for example[i] Policy: org:contoso/.github + file:/repo/p.yml -- enforcement=block.apm audit --cinow prints the policy it enforced in text mode; JSON and SARIF already did.--policyis rejected with--global(user-scope policy is User-scope (-g) org policy source: govern global installs consistently #3703) and with--no-policy.apm audit --ci --policykeeps its current meaning: it audits against that one source instead of the discovered one, and fails closed if the source cannot be loaded.Design
policy/explicit_source.pyholds the per-invocation source and the composition. It is registered asexplicit-policy-sourcein.apm/architecture/owners/install-deployment.jsonand guarded byinstall-deployment-explicit-policy-source-owner. The guard checks that discovery composes exactly once, that the merge order is tighten-only, and that only the shared--policyoption binds the source.catalog_freshness_scope. Every install-time policy reader then sees the same effective policy: the pipeline gate, the--mcpand--dry-runpreflights, executable trust and lifecycle scripts.discover_policyfetch owners (_fetch_from_url,_fetch_from_repo), so auth fallback, redirect handling, caching andextends:host pinning are unchanged.apm.ymlfield.discovery.pygrows by 28 lines (2056 to 2084), with headroom left for [FEATURE] Persist marketplace object-form deps; accept SHA catalog pins #2903.Ruling: fail closed (Regent v3, option 2)
The earlier proposal let an unloadable explicit source follow
fetch_failure_default(fail open underwarn). The ruling and the new approved record choose fail closed: a named--policysource that cannot load always stops the command before any write; there is no fail-open setting. Tighten-only composition with discovered policy is kept. Spec amendment 0.1.75 adds req-pl-022 with clause (c) failing closed, revises req-pl-001 and the Section 6.1 lead to admit composition, and leaves req-pl-021 as written. It lands after #4559 (0.1.74).D5 signed (CEO): amendment 0.1.75 is adopted by editor decision; record: #4001 (comment). The 0.1.75 row, manifest note and CONFORMANCE reflect adoption. Changelog entry is
changelog.d/4001.added.md.Issue and approved scope
Issue: Fixes #1925
Dependency order: lands after #4559 (spec 0.1.74). If #4559 lands first and adds a statement, this PR rebases and updates the 0.1.75 row's statement count; no code dependency on any open PR.
Human scope-approval comment: #1925 (comment) (new approve record; replaces the withdrawn 7012791773)
This PR completes the issue's approved scope. Out of scope per that record: a policy reference field in
apm.yml(#3297 design), new policy schema fields, and user-scope policy sources (#3703).Type of change
Testing
Lifecycle tests:
tests/integration/test_explicit_policy_source_lifecycle.pyruns the realapmbinary against loopback fixtures and covers the three "done when" conditions:--policy ./org-policy.ymlblocks a denied dependency at install. The policy is a local file and nothing is written.enforcement: off/allow: contoso/*policy cannot re-allow a dependency the discovered org policy denies, and enforcement staysblock.--policyURL and a missing--policyfile each exit non-zero with apm.yml, the lockfile and deployed files unchanged, under bothfetch_failure_default: warnandblock, forinstall,install --mcpandapm updatewith nothing to change (test_unloadable_explicit_policy_fails_closed_whatever_the_default[install|install-mcp|update]).fetch_failure_default:warninstalls and names the discovered source,blockexits 1 with no writes (test_discovered_failure_with_loaded_explicit_follows_the_default).Previously: The no-change shortcut skips the install gate, so the source is routed at that exit through
policy/explicit_source.route_unavailable_explicit_sources.update's executables check andMcpAdmissionalso treat a failed composed source as unknown policy, viaoutcome_routing.unavailable_policy_outcome.Unit tests:
tests/unit/policy/test_explicit_policy_source.pycovers scope normalization, local file without a remote, the tighten-only merge, per-default routing, a missing file, URL credential redaction, and rejected flag combinations. A mutation that swaps the merge order breaks both the unit test and lifecycle test 2.Commands run:
APM_BINARY_PATH=.venv/bin/apm uv run --extra dev pytest -q tests/integration/test_explicit_policy_source_lifecycle.pyapm update --policy <unreachable>with nothing to change:warnreports it and exits 0;blockexits 1, lockfile unchanged)uv run --extra dev pytest -q -n auto tests/unit/policy tests/unit/install/test_no_policy_flag.py(with the lifecycle file)uv run --extra dev pytest -q -n auto tests/unit/install/test_mcp_preflight_policy.py tests/unit/install/test_transitive_mcp_policy.py tests/unit/test_cli_consistency.py tests/unit/test_mcp_command.py tests/unit/commandsuv run --extra dev pytest tests/integration/test_architecture_owner_rule_mutations.py -k explicit-policy-source-owneruv run --extra dev pytest -q tests/unit/scripts/test_architecture_runner.pyuv run --extra dev pytest -q -n auto tests/unittest_unix_install_ownership,test_public_release_metadata,test_isolated_network_guard, git cache tests). They fail the same way on the base commit in this sandbox, which signs git commits and has no network. CI is authoritative.uv run --extra dev pytest -q tests/spec_conformance/test_policy_reqs.py -k "req_pl_022 or explicit_install or spec_scopes or explicit_policy_ref"uv run --extra dev python -m tests.spec_conformance.orphan_checkruff check+ruff format --check(src, tests, architecture linter)pylint --enable=R0801 ...bash scripts/lint-auth-signals.shbash scripts/lint-architecture-boundaries.shChangelog
## [Unreleased]inCHANGELOG.md:user-visible effect first, 25 words or fewer, ending with
(#PR);breaking changes only under upgrade notes; no Highlights; see
.github/instructions/changelog.instructions.md.Spec conformance (OpenAPM v0.1)
docs/src/content/docs/specs/openapm-v0.1.mdupdated(new/changed
<a id="req-XXX"></a>anchor + prose + Appendix Crow). New
req-pl-022;req-pl-001andreq-pl-021revised in place; proposed amendment 0.1.75.docs/public/specs/manifests/openapm-v0.1.requirements.ymlupdated.
@pytest.mark.req("req-XXX")test undertests/spec_conformance/added or extended (test_policy_reqs.py, req-pl-022).CONFORMANCE.{md,json}regenerated viauv run --extra dev python -m tests.spec_conformance.gen_statementand committed.
Docs re-home after #3996
Apart from the spec artifacts (in the spec commit), all
docs/**andpackages/apm-guide/**changes are in the last commit (docs: ...), written against the currentmainlayout. After the 0.37 tag, redo that commit on the #3996 layout:reference/cli/install.md--policy SOURCErow in "Policy and trust"enterprise/policy-reference/#explicit-policy-sourcemoves toenterprise/apm-policy/#explicit-policy-source.reference/cli/update.md--policy SOURCErowenterprise/policy-reference.md(removed in #3996)enterprise/apm-policy.mdx, a short "Explicit policy source" section after "Where it lives". Also change that page's "For other hosts, pass the source explicitly:apm audit --ci --policy" line to mentionapm install --policy.enterprise/governance-guide.md(removed in #3996)apm install --policy ./vendored-policy.yml. Section 14 (known gaps): removes the closed gap and points plain-git remotes at--policy.enterprise/registry-proxy.md, next to itsapm audit --ci --policy ./vendor/apm-policy.ymlexample. Known gap: nothing to port (the gap is closed).packages/apm-guide/.apm/skills/apm-usage/commands.md--policy SOURCEadded to theapm installandapm updaterowspackages/apm-guide/.apm/skills/apm-usage/governance.md--policy)" subsection after "Escape hatches"Rebase onto 0.37 main: decisions (S15, P1)
--policysource that did not load now makesclassify_discovery_outcomereturn an unresolved route, withDiscoveryRoute.unavailable_source. The route blocks when that source alone would block underfetch_failure_default. Update reconcile, the exec gate and MCP admission (trust.py additionally flagsunavailable_source) treat a partial policy as unresolved without any routing code of their own.route_discovery_outcomeand thereforeroute_unavailable_sources. The PR'sroute_unavailable_explicit_sourcesis dropped, and no_DISCOVERY_CALLERSregistration is needed._TrustReaderLog.policy_source_unavailableforwards to the command logger, with a neutral[!]fallback. The red-first test istest_trust_reader_routes_an_unavailable_explicit_source; without the forwarder it fails with AttributeError.explicit_source.pyintooutcome_routing.py(POLICY_NOT_PUBLISHED_OUTCOMES);_as_unavailableasksclassify_discovery_outcome._split_hash_pinmoved toproject_config.py, which owns the pin format, sodiscovery.pystays at 2095 lines (cap 2100).enterprise/apm-policy.mdx, in "Enforce a policy discovery cannot reach". It is linked from "Where it lives",registry-proxy.mdand theinstall.md--policyrow.req-pl-001(switch toreq-pl-022once it is in the catalog). The composition tests injectresolveinstead of patching discovery (AQ004). The CLI flag test moved totest_explicit_policy_flags.py(component). The lifecycle module asserts on stdout/stderr (AQ003).Rebase onto main 0c349e0 (P1 v2)
tests/unit/core/test_no_policy_bypass_advice.py:('commands/_helpers.py', 'explicit_policy_option')joins the RA-015 escape-hatch allowlist. Its only bypass literal is the usage error "--policy and --no-policy are mutually exclusive", which declares the option, never advises it (fixed Build & Test shard 1 and Windows 1/3).tests/lifecycle/journeys/regen_goldens.py E01:audit --citext mode now names the effective policy source ([i] Policy: org:contoso/.github -- enforcement=warn), the intended [FEATURE] Support policy enforcement on non-GitHub remotes: add --policy to apm install (and/or auto-discovery for GitLab/ADO/plain git) #1925 behaviour (fixed Lifecycle Smoke shard 3).pytest tests/unit/core/test_no_policy_bypass_advice.py tests/unit/policy tests/lifecycle/journeys/test_journeys.py::test_journey[E01] tests/integration/test_explicit_policy_source_lifecycle.py tests/spec_conformance/test_policy_reqs.py(APM_E2E_TESTS=1, APM_BINARY_PATH=.venv/bin/apm) -> 1508 passed.Fail-closed change (P1 v2, after the ruling)
policy/explicit_source.pymarks the failed explicit componentexplicit=True;policy/outcome_routing.pyblocks on it unconditionally (classify_discovery_outcomeand_route_unavailable_source), and keepsfetch_failure_defaultrouting for a failed discovered component. Diagnostics readExplicit policy source .../Discovered policy source ...; the block error readsInstall blocked: explicit policy source <source> could not be loaded (<cause>); a named --policy source must load whatever policy.fetch_failure_default says.test_unloadable_explicit_policy_fails_closed_whatever_the_default[install]and 6 unit cases fail (warn proceeded); all pass now.tests/unit/policy/test_explicit_policy_source.py::test_stale_cached_explicit_url_counts_as_loadedfetches a URL source, backdates its cache past the TTL, makes the transport refuse, and assertscached_stale, no unavailable source, and the cached deny still enforced underfetch_failure_default: block.tests/spec_conformance/test_policy_reqs.py::test_unloadable_explicit_install_source_fails_closed[warn|block].--policyhelp text, apm-usage governance.md and commands.md; CHANGELOG line updated. CONFORMANCE regenerated.pytest tests/unit/policy/test_explicit_policy_source.py tests/integration/test_explicit_policy_source_lifecycle.py(APM_E2E_TESTS=1, APM_BINARY_PATH=.venv/bin/apm) -> 20 passed.pytest -n 2 tests/unit/policy tests/spec_conformance tests/unit/core/test_no_policy_bypass_advice.py tests/unit/test_audit_policy_command.py-> 2280 passed; 43 failures only in installed-CLI spec files this PR does not touch (test_unmanaged_skill_preflight_reqs,test_lockfile_cli_behavior_reqs,test_hook_package_selection_reqs,test_manifest_cli_behavior_reqs: output-oracle I6/I9 from the local terminal binary), CI is authoritative. Lint chain clean.