User guide: contents

Policy packs in observe mode

A policy pack is a set of rules that is asked at the important moments of a run. The answers are recorded, and a run does not stop because of them, with one exception: a mandatory pack that cannot be read or evaluated stops the steps that sign in or write (see When the mandatory policy cannot be read).

  • The baseline. The Foundry has a built-in pack, foundry.baseline. It is asked at every boundary of every run, with no setting. Its version is the Foundry's version. The Foundry owns it: an administrator cannot change, replace or remove it; an administrator can only add stricter packs next to it. It is built for each run from protected_branches, secret_scan and the run's repository. Its rules, in order:

    • a push of the shipped hotfix flow's push_main to a protected branch is allowed (branch.hotfix-exception);
    • a push to a protected branch is denied (branch.protected), with the patterns of protected_branches;
    • a push that would add secrets is denied (secret.detected); this rule is left out when secret_scan: false;
    • a push without a committer name and e-mail that git can find is denied (identity.missing);
    • a push, or a sign-in for a repository other than the run's, is denied (repository.not-allowed); this rule is left out when the run has no repository;
    • an agent write by a user without a sandbox is denied (sandbox.required); a shell step of a user's run is denied the same way (sandbox.required at step.before) unless the OS sandbox is on or the step has a Docker image;
    • a run whose changed files match the run's forbidden_paths gets path.forbidden after the step that changed them (see below);
    • an in-place run by a user is denied (workspace.admin-only);
    • a user's run that gets the machine's credential is denied (credential.scope-exceeded);
    • a shell step whose output is over its limit gets a warning (output.limit-exceeded). Every shell step has a limit: 20,000 by default; the check_round step of refine-round has 150,000, and the risk_gate step of issue-deliver and issue-gitflow has 60,000. The output is counted in bytes, so a warning can come before the output is cut;
    • a step that runs longer than its timeout is denied (timeout.exceeded). The limit is the step's timeout_sec, or the flow's default. It covers shell and agent steps. Time spent waiting for a test slot does not count, up to FACTORY_TEST_SLOT_WAIT_SEC (see "A few test runs at a time" above);
    • a step whose cost is over its step budget is denied (budget.step-exceeded). The limit is the step's max_budget_usd, or the flow's default. These budget rules need cost_limits (not false);
    • a run whose cost is over the flow's max_cost_usd is denied (budget.run-exceeded);
    • a run whose day's cost is over daily_budget_usd is denied (budget.daily-exceeded).

    The limit rules exist only when their limit is in effect, and a rule is only for the steps that have that limit. A sub-flow step is judged by the limits of its own flow. elapsedMs is the process time of the final attempt of an agent step, not the time of its earlier retries. If a baseline has more than 500 rules, for example from very many distinct limits, it is policy.invalid: for the whole run, or only for the steps of that sub-flow. Then the steps that sign in or write are stopped, as described below.

    All of them are observed only. Protected branch patterns with ?, [, ] or \, or longer than 255 characters, cannot be matched the way the hook matches them, so they are not in the baseline. The run logs one ! line for them. The hook still blocks those pushes, and they show as policy.input-incomplete. A push to a remote that is not on GitHub is not asked about the repository. The pack's hash (packSha256) depends on these settings and on the run, so two runs with different settings have different hashes.

    Changed paths (path.forbidden). The baseline reads the run's forbidden_paths variable as written, with the same split on spaces and new lines as protected_branches. Each entry is matched against the whole path, and * is the only wildcard: write docs/* to match the files in docs, and a.txt to match only that file. The guard step still treats each entry as a prefix, so the two can differ. Entries with ?, [, ] or \, spaces, control characters, or over 255 characters are not in the baseline; the run logs one ! line for them, and the guard step still checks them. A changed file counts from the run's starting commit: committed changes, staged files, unstaged edits, new files, deleted files, both sides of a rename, and the changes of merged branches. A dirty in-place folder counts too. Files that are ignored and were never staged do not count. The Foundry runs git without fetching: a missing object is not fetched. The result is policy.input-incomplete (not an allow) when:

    • the workspace has no checkout yet, or it is the clone step of an empty workspace;
    • the starting commit could not be read when the checkout appeared, or the run was resumed without it. The run stays incomplete from then on, so the base never moves forward;
    • git is missing objects, takes longer than 30 seconds, or the run was cancelled;
    • there are more than 5000 changed files;
    • the run was started before this version, and so has no record of its starting commit.

    The baseline only observes: nothing is stopped by path.forbidden. Its decisions are in the evidence, and a line ! policy foundry.baseline: forbidden path patterns … in the run log names any pattern that was left out.

    Nothing else is built in. The id foundry.baseline is reserved: policy.packs, policy.mandatory and policy.repositories refuse it.

  • Turn packs on. Put a pack in the data folder as policies/<id>.json (a plain file, at most 1 MiB), then list its id in config.yaml. Packs are read only from the data folder, never from a repository. There are three layers:

    policy:
      mandatory: [org-overlay]          # asked for every run, after the baseline
      repositories:                     # asked for the runs of that repository only
        acme/app: [app-rules]
      packs: [team-extras]              # optional packs, asked for every run

    A repository key is owner/name in lower case. Each list has at most 20 ids, with no id twice in a list. Only mode: observe is accepted. A pack in enforce mode is refused for now. The settings are not in the web interface; an older build rejects the policy key.

  • Pack format. A pack has version: 2 (a version 1 pack is still read, and it is never rewritten). Each rule may have its own mode: a rule with mode: observe is observed while the pack is in observe, and a rule without mode takes the pack's mode. A rule with mode: enforce, or a pack in enforce, is refused when the pack is loaded or restored. A mode on a rule of a version 1 pack is refused. The baseline writes mode: observe on every rule.

  • Which answer counts. For each boundary the Foundry takes the most restrictive answer of all packs (from least to most restrictive: allow, warn, require_approval, deny). On a tie the higher layer wins: mandatory, then repositories, then packs. Inside one layer, a tie goes to the first pack. A repository pack can only make things stricter: it cannot allow what the baseline denies. The answer does not depend on the order of the lists.

  • When it is asked. The start of the run; before the workspace is made; before a step starts in the repository's checkout; before and after every step (also the steps inside a parallel step or a sub-flow); before a write-capable agent step; for each push a step makes; when an approval is used; and when the run succeeded. This is the same for built-in and custom flows.

  • Observe and block mode. A pack and each rule are in observe mode: the answer is recorded and nothing is stopped, except as described under When the mandatory policy cannot be read. A pack or rule in enforce mode, from an overlay file, is not available yet: such a pack or rule is refused when it is loaded or restored, and a deny in an overlay is only a record, with the line observe only, nothing was stopped. The built-in baseline's rules can decide in enforce mode with policy.enforce; see Enforcing a baseline rule.

  • What you see. Every run has a line in the live log for each answer, at each boundary, also when no pack is configured. The line names the layer, and the answer that counts has · wins. For example:

    · policy foundry.baseline 0.1.0 [mandatory] · push: deny (secret.detected, rule secret-detected) · wins — observe only, nothing was stopped
      Why: The new commits contain something that looks like a secret. What to do: Nothing was stopped: this policy only observes. In block mode the step would be stopped.

    The Why: line (with What to do:) follows the first time a decision with the same policy, layer, boundary, outcome, reason code, mode and rule is seen in a start of the run. A repeat of it is not hidden: its own line ends with · seen N times, first at <time>, now <time>, so the count and the times stay in the log. The same decision at another step counts too. The log shows a user the outcome, the reason, the reason code, the policy id and version, and what to do; the layer, the rule and · wins are for administrators. Each answer is also an event policy.decided in evidence.jsonl (see Evidence of a run). The evidence view of the run shows Policy decisions: one entry per kind of decision, with the outcome, the reason, what to do, the number of times with the first and last time, and the steps (at most 10 are named; the rest are counted). Older runs with no decisions say "No policy decisions recorded". When the event record cannot be read whole, the list says it may be short.

  • When a pack cannot be used. A missing, unreadable, linked, invalid or enforce pack (the pack or one of its rules) is logged as ! policy <id>: …, and the run gets a policy.unavailable or policy.invalid decision. For a repository or optional pack, the run's result is the same as without the pack. For a mandatory pack, see When the mandatory policy cannot be read.

  • Pushes. The Foundry's pre-push hook records each pushed branch, the number of secrets its scan found and whether git can find a committer identity. The baseline is asked at push only when the hook is there: when a branch is protected, the secret scan is on, or packs are configured. With both guards off and no packs, there is no hook and pushes are not observed. The hook still refuses pushes to protected branches and pushes the secret scan rejects; it never blocks a push for an observation.

  • Without the secret scan (secret_scan: false), the secret rule is not in the baseline, since the number of secrets is never known. Pushes are then decided by the other rules, with no policy.input-incomplete for it.

  • Evidence format. It is unchanged since #142. The baseline adds policy.decided events to every run. An older build cannot read the evidence of a run that has policy.decided events, so keep this build for those runs.

When the mandatory policy cannot be read#

A mandatory pack is one in policy.mandatory, or the built-in baseline. If that pack is missing, linked, not a plain file, not valid JSON, has another id, is set to mode: enforce (on the pack or on a rule), is too large, or cannot be evaluated, the Foundry stops the steps that need trust. It does not carry on quietly.

  • What is stopped. A step that signs in to the repository with the machine's login or a stored repository token, an agent step that writes, and an approval that is used. Everything else runs as before: the start and end of a run, the steps before and after each step, pushes, steps with no sign-in, and the workspace. An isolated read-only agent step and an isolated shell step without repo_access run too. An isolated agent step that writes is stopped.

  • What is not stopped. A broken or missing pack in policy.repositories or policy.packs never stops a step. A valid mandatory pack whose rule denies is only recorded.

  • What you see. The run ends failed and the step does not run, unless an admin's break-glass is active. on_failure is not followed. The error and the log say:

    mandatory policy org-overlay cannot be used (policy.unavailable): repository.access is denied

    The live log also has the load line (! policy org-overlay: … — recorded as policy.unavailable; this mandatory policy denies steps with a sign-in and writing agents), and the policy line of the step ends with — enforced: the step is stopped. The evidence has a step.denied event with the policy's id and version unknown, and it still verifies. No token is fetched when the run starts, so a run that is stopped this way does not use the bot's sign-in.

  • What to do. Fix the file in policies/<id>.json (it must be a plain file with valid JSON, the same id, and mode: observe), or remove the id from policy.mandatory in config.yaml if the overlay is no longer wanted. A run reads the packs when it starts or resumes, so start the run again after the fix.

Restore the last-known-good copy#

Each time a run starts, the Foundry saves a copy of every valid mandatory overlay in the data folder, at policies/last-known-good/<id>.json. The folder is private (mode 0700) and the file is 0600. The copy is written in one step, so a crash never leaves a half-written file. The baseline, repository packs and optional packs get no copy. An invalid overlay keeps the copy from the last valid start. If a copy cannot be saved, the run logs ! policy <id>: the last-known-good copy could not be saved and goes on.

To put the copy back when policies/<id>.json is broken:

  1. Run scf policy restore <id>. For example, scf policy restore org-overlay.
  2. The command checks the copy before it touches policies/. It refuses, and writes nothing, when the id is not valid or is foundry.baseline, when there is no copy, when the copy is a link or not a plain file, when its SHA-256 does not match the stored one (it was changed), when it is over 1 MiB as compact JSON, or when policies/<id>.json is a folder.
  3. If policies/<id>.json is valid, the command also refuses. Add --force to replace it: scf policy restore org-overlay --force.
  4. The copy is written as compact JSON and replaces policies/<id>.json with one rename. The file that was there is kept as policies/<id>.json.replaced-<time>, for example org-overlay.json.replaced-2026-10-20T10-11-12Z. A second backup in the same second gets -1, -2 and so on. An earlier backup is never overwritten.
  5. The command prints ✔ restored policy org-overlay (sha256 …) and, when a file was kept, kept the replaced file as policies/<name>. It exits 0. A refusal prints ✘ and the reason, and exits 1. The messages do not show the data-folder path or the file contents.
  6. Start the run again. The restore is written to audit.jsonl as policy-restore, with result: "ok". A refusal after the lock is taken is written as result: "failed". A refused id writes no line.

The SHA-256 check catches a change made by mistake. It is not a signature: someone who can write to policies/ can change the copy and its hash together. Restore only from a copy you trust, and keep the .replaced-<time> files until you no longer need them.

Break-glass#

A break-glass is a short, audited exception for a mandatory-policy outage: the policy cannot be used, but privileged work must go on until it is fixed. Use it only when the fix cannot wait. It is not a way around a policy that works: a rule that denies (for example secret.detected) still denies while a break-glass is active, and so does any other layer's pack.

  • When it applies. Only a denial of a privileged step by a mandatory pack that cannot be loaded or evaluated, as described in When the mandatory policy cannot be read: the code is policy.unavailable or policy.invalid. The steps it covers are the ones that step stops: a sign-in with the machine's login or a stored repository token, a writing agent step, and an approval that is used. A denial that has no recorded decision is not covered.

  • Start it. On the server machine, give a reason and a duration:

    scf policy break-glass --reason "org-overlay broken, fix in progress" --for 2h

    The reason is required: up to 200 characters, no control characters or line break, and no credential-like text. The duration is required, from 1m to 4h. A start is refused while a break-glass is active. If the file has expired, the start first writes the expiry line.

  • End it early. scf policy break-glass --end ends the active break-glass now and writes its audit line. It exits 1 when none is active.

  • Limits. There is no API route and no config.yaml key: the record can only be changed on the server machine. A file that is not valid, or is a link, is not an active break-glass, so the steps stay denied.

  • What changes. For each covered step, the decision is warn with reason policy.break-glass instead of deny, and the step goes on. The live log has the line ! policy: break-glass active until <expiresAt> (<reason>) — <pack> <code> allowed, and the policy line of the step ends with — break-glass: the step goes on. The evidence has a policy.decided event with outcome: warn, reasonCode: policy.break-glass, version unknown and no pack hash, and it verifies. No step.denied event is written for that step. The decision must be recorded in the evidence first; if it cannot be, the step is denied as before.

  • What the server shows. The server checks the record at startup and once a minute. While the break-glass is active, it logs ! policy: break-glass active until <t> (<reason>) — a mandatory policy that cannot be used does not stop privileged steps at the first check, for each new break-glass, and every 15 minutes.

  • What is audited. Starting writes policy-break-glass-start to audit.jsonl (the expiry time as the target, the reason as the detail). Ending writes policy-break-glass-end with the detail ended, expired or invalid. The reason is only in the audit and the log lines, never in run evidence.

  • How it ends. At the expiry time, the next read of the record, or the server's check, writes the expired line and removes the record. The server logs policy: break-glass ended (expired), and from then on the steps are denied again: the Foundry fails closed by itself, nothing needs to be reset. A break-glass that is ended with --end is logged as policy: break-glass ended by the server's next check. If the policy is still broken, the steps that need trust stay stopped. Fix or restore the policy first when you can; see Restore the last-known-good copy.

Enforcing a baseline rule#

By default every rule of the built-in baseline only observes. policy.enforce lists the rules that decide: a denial by one of them stops the step or the run. The list is empty by default, and then every run behaves as before.

policy:
  enforce: [path-forbidden, sandbox-required]
  • Valid ids. branch-hotfix-exception, branch-protected, secret-detected, identity-missing, repository-not-allowed, sandbox-required, workspace-admin-only, credential-scope-exceeded, output-limit-exceeded, timeout-exceeded, budget-step-exceeded, budget-run-exceeded, budget-daily-exceeded, path-forbidden and context-uncited. Any other id is ignored.

  • Before you add an id. Keep the rule in observe mode first and read its decisions: the Policy decisions of a run in Details › Evidence, or the policy.decided events in evidence.jsonl. Compare each deny with what really happened in that run. A deny on a run that succeeded would have stopped it.

  • What each boundary does. An enforced denial:

    BoundaryWhat happens
    run.startThe run fails before any step. Its evidence has one step.denied with no step.
    step.beforeThe step is refused: its command does not run, it is recorded as failed, and on_failure is not followed. An approval is not used.
    step.afterThe step is recorded as failed, and on_failure is not followed. The run fails. The checkout is left as it is, with no rollback.
    run.completeA run that succeeded is marked failed. Work it already pushed stays pushed.
    repository.access, agent.write, approval.consumeAs before: the step is stopped.
    pushOnly recorded. The pre-push hook is what blocks a push.
  • Each denial is recorded. The run log gets a ! line with the reason, and the evidence gets a step.denied with the reason code, the policy id and version, and packSha256. For example, a step that writes secret/a.txt with path-forbidden enforced leaves this order in evidence.jsonl: policy.decided (mode enforce, reason path.forbidden), then step.denied with the same packSha256, then step.failed.

  • A missing fact stops the step. When a rule needs a fact the step did not give, the answer is policy.input-incomplete, and an enforced rule stops the step with it.

  • An invalid baseline stops the enforced boundaries. If the built-in baseline cannot be used (policy.unavailable or policy.invalid, for example one with more than 500 rules), the steps at the boundaries of the enforced rules are denied, as sign-ins and writing agents already are. Push is not stopped by this.

  • Break-glass is for outages only. A break-glass lets through only the outage denials described in Break-glass. It never lets through a denial by an enforced rule.

  • Overlay files still refuse enforce. A pack or rule from policy.packs, policy.repositories or policy.mandatory in enforce mode is refused. Only the built-in baseline's rules are enforced, and only through policy.enforce.

Delivery contract#

A run that has a pull request in its own repository keeps a record of what was handed over with it: a chain of delivery contracts in the run folder, delivery/. A contract is written after a step, and only when something it states has changed.

  • When. After each top-level step, once pull_request is a pull request of the run's repository. A new contract is written only when the commit, the branch, a dependency lock file, a CI workflow file under .github/workflows/, the pull request or a requirement changed. More evidence alone does not write one, and neither does a key that changed.
  • What is in it. The run, the pull request, the commit and branch, the lock files and workflows with their hashes, the required checks, artifacts and provenance, and the evidence count and hash at that moment. A signed contract also has a signature file.
  • Files. contract-1.json, contract-2.json and so on are never changed. Each one after the first names the one before it (supersedes). contract.json and contract.json.sig hold a copy of the latest one. Files are readable by the account only.
  • Signed or unsigned. With a signing key set (see below) a contract is signed; without one it is unsigned. A key that is set but cannot be used (not in delivery-keys, unreadable, not Ed25519) writes no contract at all, so an unsigned one never stands in for a signed one.
  • Settings apply from the next step. Required checks, artifacts and provenance are read again for each step. A change makes a new contract at the next step that changes something.
  • Failures do not stop the run. If a contract cannot be written, the log gets one line such as delivery: the contract cannot be written, and the run goes on. The run can then finish with a pull request and no new contract. CI (see below) reports a missing or stale contract as a stop.
  • Logs. A written contract logs delivery: contract <n> written (signed) or (unsigned).

The settings for the contract are in the Delivery card of Administration → Settings, or in config.yaml:

delivery:
  signing_key_path: /Users/me/.spaghetti-code-foundry/delivery-keys/signing-key
  required_checks: [test, lint]          # CI checks a contract requires
  artifacts: [sbom.json]                 # artifacts a contract requires
  provenance: false                      # whether a contract requires provenance
  repositories:                          # per repository; each key is optional
    acme/app:
      required_checks: [test, e2e]
      artifacts: [sbom.json, coverage.xml]
      provenance: true
  • Signing key. An absolute path to an unencrypted Ed25519 key. It must be in the folder delivery-keys of the data folder (~/.spaghetti-code-foundry by default). Without a key, contracts are unsigned.
  • Required checks, artifacts and provenance. Each applies from the next step. A list holds at most 500 names; each name is 1 to 200 characters, has no control character and is given once. A repository is written as owner/name in lower case, and at most 50 repositories can have their own settings.
  • Per-repository settings are only in config.yaml; the Settings page does not show them.
  • Where the settings apply. The settings are read at each step, so a saved change applies from the next step that writes a contract. The key folder is protected by the sandbox rule below.

Set up the key. Make the folder with owner-only access, then create the key in it:

mkdir -m 700 <data>/delivery-keys && ssh-keygen -t ed25519 -N "" -f <data>/delivery-keys/signing-key

Here <data> is the data folder. Then set signing_key_path to the new signing-key file.

Who can read the key. A sandboxed step (a shell step or an agent step of a user's run, on macOS with the OS sandbox) cannot read anything in delivery-keys, also not a key added or rotated while the step runs. The rule is added after every rule that allows reads, so a sandbox.user_read path that covers the data folder does not open it. An admin's run, a run without the OS sandbox and a step in Docker can read the key if the account running the Foundry can. Keep the folder's access to that account only.

Improve this page on GitHub