Repository navigation
Closed
Labels
enhancementLegacy classification name; prefer type/feature. Retained for history.policyLegacy classification name; prefer area/audit-policy. Retained for history.securityLegacy classification name; prefer theme/security. Retained for history.
Description
Summary
apm install does not enforce apm-policy.yml. Today, organisational policy is only enforced by apm audit --ci. A developer running apm install on their workstation can pull and integrate dependencies that the org policy explicitly denies, with no warning and no failure.
The discovery, parsing, and enforcement primitives all already exist in src/apm_cli/policy/ — they just aren't wired into the install pipeline.
Evidence
src/apm_cli/commands/install.py— no references todiscover_policy,run_policy_checks, orApmPolicy.src/apm_cli/install/phases/resolve.py— same: zero policy hooks. The only policy-adjacent code (install/insecure_policy.py) handles the unrelated HTTP-dependency consent prompt.src/apm_cli/commands/audit.py:507-540— the only call site ofdiscover_policy()+run_policy_checks(). Honoursenforcement: block | warn | off.src/apm_cli/policy/policy_checks.py:702-760—run_policy_checks()already evaluates dependency allowlist, denylist, required packages, required version, etc. againstapm.yml+ lockfile.
Impact
The current model relies on apm audit --ci being a required CI check on every PR. That assumption is brittle:
- Local-only workflows bypass the gate entirely. Developers running
apm installagainst a private branch, a fork, or a personal scratch repo never hit CI, so banned packages install silently. - Transitive dependencies bypass the gate at install time. A policy-allowed direct dep can pull a denied transitive dep; the user only learns at audit time, after the file system already has the integrated content (and
.github/files have been deployed). - The integration step has already happened by the time CI fails. Files have been written to
.github/prompts/,.github/skills/, etc. CI tells you "this should not have been installed" but the developer's working tree is already polluted. - Mismatch with developer mental model. Coming from
npm,pip,cargo, users reasonably expect the package manager itself to enforce org policy at install time, not a separateauditcommand.
Proposed approach (high level)
- Call
discover_policy(project_root)early ininstall/phases/resolve.py, afterapm.ymlparse and after the dependency graph is resolved (so transitive deps are also evaluable). - Run the dependency-scoped subset of
run_policy_checks(_check_dependency_allowlist,_check_dependency_denylist,_check_required_package_version, plus the MCP equivalents) against the resolved set. - Map
enforcementlevels:block-> fail the install before any download or file integration.warn-> print a deferred-diagnostics summary and continue.off-> skip entirely.
- Honour an escape hatch (e.g.
--no-policyflag plus anAPM_POLICY=offenv var) for offline / break-glass scenarios. Log loudly when used. - Use the existing policy cache (
apm_modules/.policy-cache/) so the install path is not network-bound on every invocation. - Apply the gate uniformly to:
apm install,apm install <pkg>,apm install --mcp, andapm update. (Currently onlyaudit --cigates these.)
Open questions
- Default-deny on policy fetch failure? If the org policy URL is unreachable (offline, network error), do we fail closed or fall back to permissive? Audit today errors out (
commands/audit.py:526); install probably wants the same behaviour when a project has previously seen a policy (cache hit), and a configurable behaviour when no cache exists. apm install --no-cachebehaviour? Should it also bust the policy cache, or keep policy cached separately to avoid surprise enforcement changes mid-install?- First-run UX. When a developer clones a repo for the first time and runs
apm install, the policy fetch is the very first network call. We should make sure errors here are clearly distinguished from dependency-download errors. - Where does the gate live architecturally? Most natural: a new phase between
resolveanddownload(e.g.install/phases/policy_gate.py), composed into the existing pipeline (install/pipeline.py). Mirrors the_check_insecure_dependenciespattern that already runs at the end of resolve. - Telemetry / diagnostics surface. Use
DiagnosticCollector+CommandLogger.error()so blocked installs render a grouped, scannable summary consistent with the rest ofapm installoutput.
Out of scope for this issue
- Changes to the policy schema itself (
policy/schema.py) — thedependenciesfield is already sufficient. - Changes to
apm audit --cibehaviour — it stays the source of truth for CI gating; install enforcement is additive. - Discovery model changes (auto-discovery via
<org>/.github/apm-policy.yml) — already correct, just needs to be invoked.
References
- Docs: https://microsoft.github.io/apm/enterprise/policy-reference/#dependencies
- Existing audit wiring:
src/apm_cli/commands/audit.py:507-540 - Policy discovery:
src/apm_cli/policy/discovery.py - Policy checks:
src/apm_cli/policy/policy_checks.py:702-760
Metadata
Metadata
Assignees
Labels
enhancementLegacy classification name; prefer type/feature. Retained for history.policyLegacy classification name; prefer area/audit-policy. Retained for history.securityLegacy classification name; prefer theme/security. Retained for history.
Activity
fix(policy): in-PR resolution of #834 (warn-mode rendering) and #831 …
docs(changelog): record in-PR resolution of #834 and #831 under #827
fix(policy): address review-panel pre-merge findings (#827)
feat(policy): ship enterprise hardening pack on top of #827
docs(policy): address doc-writer review BLOCKERs (#827)
docs(policy): address doc-writer HIGH+LOW findings (#827)
fix(policy): address PR review panel logging+arch findings (#827)
test(policy): use urllib.parse for host assertions to silence CodeQL (#…
feat(policy): enforce apm-policy.yml at install time (#832)
chore: prepare v0.9.1 release
chore: prepare v0.9.1 release (#838)
feat(policy): enforce apm-policy.yml at install time (#832)
chore: prepare v0.9.1 release (#838)