A repository policy
A repository’s committed .moat/policy.yaml adds deny and review rules for everyone who works in it, whatever agent they use; its allow rules apply only for a person who trusted that exact file, or where a key they trusted signed it. How it combines with each person’s policy: Repository policies.
Example
Section titled “Example”-
Add a policy to the repository
Create
.moat/policy.yamlat the root of the repository and commit it:version: 1deny:- id: no-prod-configreason: production settings stay with the release pipelinefs.write: ["${project}/deploy/prod/**"]review:- id: migrationsreason: database migrations change shared datashell: ["npm run migrate*"]Only
version,deny,reviewandalloware accepted (ask, the name before 0.14.0, is still read);defaults,executables,sandboxand any other key make the file invalid, and every call in the project is then denied (kernel-error) until it is fixed. The agent cannot write the file (kernel-selfdenies writes under.moat/): edit it yourself. -
Everyone gets the deny and review rules at once
They apply to everyone who works in the repository, whatever agent they use, and show up as
repo:<id>, such asrepo:no-prod-config. Per action the stricter of the two policies wins: from 0.16.0 a repository’sreviewrule never softens adenyyour own policy gives, soreview: [{net: ['*']}]cannot turn the hosts yournet: denydefault refuses into reviews a person could approve. -
Each person trusts the allow rules
A repository is untrusted input, so by itself it can only make your policy stricter. Its
allowrules apply after you review and trust that exact file:Terminal window openmoat trust # in the repository; prints the allow rules it lets inopenmoat trust --revokeIt asks
Trust this file? [y/N]before it trusts anything.openmoat allowedlists the repositories you trusted. What it prints: Use it in your projects.
Check a rule before you commit it
Section titled “Check a rule before you commit it”openmoat policy check "npm run migrate" --cwd ~/work/app # decides with the repository's policy, as the hook doesopenmoat status # in the repository: the file, its digest and which form appliesLeave out --policy: with it, only the file you name decides, without your policy or the repository’s. openmoat policy lint .moat/policy.yaml checks the rule syntax, but not the keys only a repository may not set; openmoat status in the project reports those.
Review a change to it
Section titled “Review a change to it”A pull request that edits .moat/policy.yaml drops the file back to deny and review only, for everyone who trusted it, until each trusts it again. To review it:
git diff origin/main -- .moat/policy.yaml # what the change addsopenmoat status # in the project: whether its allow rules applyopenmoat trust # shows the file, its digest and every rule it adds, then asksopenmoat trust asks Trust this file? [y/N] before it trusts anything; openmoat allowed lists the repositories you trusted, and openmoat trust --revoke takes it back. Under require_signed_repo_policy: true (Signed policy packs), openmoat status says trusted: signed by alice@example.com, or not signed by a trusted key: tightening only, allow rules ignored (…).
Check it in CI
Section titled “Check it in CI”openmoat policy check exits 0 for allow or defer, 2 for deny and 3 for an unresolved review, so a CI job can assert what the repository’s rules decide. On a runner, openmoat init without a terminal writes the default policy to ~/.moat and changes no agent’s files:
openmoat init # default policy in ~/.moat; no agent is changedopenmoat policy check "npm run migrate" --cwd . # exits 3: review, repo:migrationsopenmoat policy check "$PWD/deploy/prod/app.yaml" --kind fs-write --cwd . # exits 2: deny, repo:no-prod-configInstall openmoat on the runner as in the Quick start. A job that runs these in a shell with set -e stops at the first non-zero exit: check the code yourself, for example openmoat policy check "npm run migrate" --cwd . || test $? -eq 3. The runner decides with the default policy, not each person’s, so it checks the repository’s rules, not what a given person gets.
To check every pull request for changes to CI workflows, git hooks, agent settings, .env files or added tokens, with the repository’s rules read as the base branch has them, use openmoat policy check-diff and the GitHub Action: Check a pull request.