Set an org policy
You own what coding agents may load across your organization. This page gets you from
no policy to a blocking one: one file, apm-policy.yml, that APM finds from each
repository’s git remote and applies at apm install and in apm audit --ci.
A policy restricts where packages may come from, which MCP servers and transports are allowed, and which harnesses (agent tools such as Claude Code or GitHub Copilot) may be targeted. It governs what gets installed, not what an agent does at runtime. Every field is in the policy schema.
Write and roll out the policy
Section titled “Write and roll out the policy”Priya, on the Contoso platform team, starts in warn so nothing breaks on day one.
-
Write the policy in your org policy repository. Start with one allow rule and one deny rule:
contoso/.github/apm-policy.yml name: contoso-agent-policyversion: "1.0.0"enforcement: warndependencies:allow:- "github.com/contoso/**"- "github.com/microsoft/**"deny:- "github.com/untrusted-org/**"*matches one path segment,**any depth. A host-qualified pattern such asgithub.com/contoso/**matches that host and no other, which closes the gap where a same-named repository on another host would also match.denyalways wins overallow, and both apply to transitive dependencies too. For a local bundle (apm install <bundle>), both judge the packages its embeddedapm.lock.yamlrecords.denyalso matches the bundle’s own name (_local/<name>);allownever does, because the bundle author picks that name. Under an allow list, a bundle that records no packages is a violation:warnreports it,blockrefuses the install before any file is written. -
Test the draft from a member repository before you commit it:
Terminal window apm policy status --policy-source ./apm-policy.yml --check --json{..."enforcement": "warn","outcome": "found","rule_summary": ["1 dependency denies","2 dependency allow patterns"],"source": "file:apm-policy.yml",...}--checkexits 1 when no usable policy resolves, so the same command works as a CI pre-check. -
Preview what it would flag in that repository:
Terminal window apm audit --ci --policy ./apm-policy.yml...| [!] | dependency-allowlist | 1 dependency(ies) not in allow list (enforcement: warn) |...16 check(s) passed; 1 reports violations under 'enforcement: warn' and fail once the policy switches to block.Under
warn, a violation is reported and the command still exits 0. Here a transitive dependency fromgithub.com/github/...is outside the allow list. Decide now whether to allow it or ask the team to drop it. -
Commit the policy to
contoso/.githuband protect it: CODEOWNERS for your team, branch protection, required review. That repository is now your trust root. -
Confirm discovery from any member repository:
Terminal window apm policy status --checkOutcomemust readfoundandSourcemust name your organization’s policy repository. Anything else means discovery failed; see Debug a policy failure. -
Move to block once the warnings are triaged:
contoso/.github/apm-policy.yml enforcement: warnenforcement: blockfetch_failure: blockNow
apm installexits 1 before deploying any file, andapm audit --cifails the pull request.fetch_failure: blockmakes a failed refresh of a cached policy fail instead of proceeding. A machine with no cached copy cannot read that setting, so also setpolicy.fetch_failure_default: blockin each repository’sapm.yml, and runapm policy status --checkin CI (Gate pull requests).
Where it lives
Section titled “Where it lives”APM derives the organization from the checkout’s git remote (origin, or the only remote
when there is no origin; with several remotes and no origin, install stops and names them)
and looks for apm-policy.yml in these repositories, in this order. The earliest match wins.
| Host | Discovery order |
|---|---|
| GitHub, GitHub Enterprise Server, GHE.com | 1. <org>/.github-private 2. <org>/.github 3. <org>/.apm 4. <org>/_apm |
| Azure DevOps | 1. Repository apm-policy in project apm 2. Legacy _apm/_apm, tried after a 404 from the primary location, with a migration warning |
| GitLab (gitlab.com and self-managed) | An apm-policy project in the top-level group and in every subgroup down to the project; all found policies combine, top-level group outward. APM_GITLAB_POLICY_REPO renames the project |
Prefer .github-private: policy rules are internal. APM recognizes self-managed
GitLab when GITLAB_HOST or APM_GITLAB_HOSTS names it. GitLab answers 404 for a private
project the token cannot read, so give the CI token read access to every apm-policy
project in the group path. For other hosts, pass the source explicitly; see
Enforce a policy discovery cannot reach.
Enforce a policy discovery cannot reach
Section titled “Enforce a policy discovery cannot reach”apm install --policy <source> and apm update --policy <source> enforce a policy
that discovery cannot reach: a plain git remote, another host, or an air-gapped
install. The source is a local path, owner/repo, or an https:// URL.
apm install --policy ./vendor/apm-policy.yml # air-gapped: no networkapm install --policy https://policies.corp.example/apm-policy.yml- Adds, never removes. The source combines with any discovered org policy under the tighten-only merge below. It cannot re-allow what the org policy denies or lower its enforcement.
- Fails closed. A source that cannot be loaded (unreachable, missing, malformed, or
publishing no policy) stops the command before anything is written, whatever
policy.fetch_failure_defaultsays. A cached copy within the stale-cache window counts as loaded. A failed discovered policy still followsfetch_failure_default. - Reported. The effective sources print at any verbosity, for example
[i] Policy: org:contoso/.github + file:/repo/vendor/apm-policy.yml -- enforcement=warn. policy.hashpins the discovered org policy, not the explicit source.--policyis not valid with--globalor--no-policy.
apm audit --ci --policy <source> keeps its own meaning: it audits against that one
source instead of the discovered policy, and fails closed when the source cannot load.
Inherit policies without loosening them
Section titled “Inherit policies without loosening them”A policy can extends: a parent, such as an enterprise baseline that several
organizations share. A child can tighten, never loosen: allow lists intersect, deny lists
union, enforcement and fetch_failure take the stricter value. Cross-host extends:
is rejected, and an unreachable parent fails closed.
graph LR E["Enterprise baseline<br/>enforcement: warn"] -->|extends| O["contoso/.github/apm-policy.yml<br/>adds deny, enforcement: block"] O --> X["Effective policy<br/>enforcement: block"] R["Repository apm.yml<br/>policy.hash, fetch_failure_default"] -.->|pins| O
A repository cannot loosen the org policy. Its apm.yml can pin the policy bytes
(policy.hash) and choose to fail closed (policy.fetch_failure_default: block);
nothing more. Merge
rules per field: policy schema.
Local bypasses, and why CI is the gate
Section titled “Local bypasses, and why CI is the gate”A developer can skip policy on their machine: apm install --no-policy for one command,
or APM_POLICY_DISABLE=1 apm <command> (never export it in CI). A fork under a personal account
discovers the fork owner’s policy, not yours. User-scope installs (apm install -g)
do not inherit the project’s policy (see the caution above). None of this changes the pull request: a
required apm audit --ci --policy org check re-runs the policy in CI, where the
bypass is not set. See Gate pull requests.
Debug a policy failure
Section titled “Debug a policy failure”apm compile applies the same dependency rules to installed packages before it writes
agent context, so a package the policy no longer allows is never compiled in.
A blocked apm install prints one [x] Policy violation: <dependency> -- <reason>
line per finding, then Blocked by org policy at <source> (<check>). apm audit --ci
shows the same check as an [x] row followed by its details. Then:
- Which policy ruled? Run
apm policy status.Outcome,Source,EnforcementandExtends chainanswer it. Add--no-cacheif an admin changed the policy in the last hour (the default cache TTL is 3600 seconds). - Wrong policy or none? Check
git remote -v: discovery follows the owner oforigin(or of the only remote). Test another source with--policy-source <owner>/.github. - Why is a hook or MCP server parked?
apm policy explain <pkg>shows the executable-trust decision and which layer made it. - Fix the right side. Change the dependency in
apm.yml, or open a pull request against the policy repository with the rationale. The policy history is your exception log.
Related
Section titled “Related”- Policy schema: every field and default.
apm policy:statusandexplainoptions.- Control executables: the
executables:section of the policy.
Copyright (c) Microsoft Corporation. General documentation: CC-BY-4.0. Software, code examples and OpenAPM: Apache-2.0. See scope and exclusions.