Introducing a new way to review your PRs.

Read the announcement

affaan-m / agentshield

AI agent security scanner. Detect vulnerabilities in agent configurations, MCP servers, and tool permissions. Available as CLI, GitHub Action, ECC plugin, and GitHub App integration. 🛡️

View on GitHub

20 documents · Updated Sep 11, 2026

docs / policy-evaluation-and-promotion

Policy evaluation and promotion

Policy evaluation and promotion turn a scan result into an organization decision. A policy states the security posture that a repository must meet. The evaluation checks that posture against findings, score, and configuration. Export and promotion then move an approved policy from a named posture choice into the active path used for enforcement. See Policy governance for the wider governance model and Baselines and fingerprints for change-based drift checks.

Policy data model

An organization policy is a versioned JSON contract that joins a named policy pack with owners, exceptions, score limits, finding limits, and configuration rules. The contract is validated before evaluation so that a malformed or unsupported policy cannot silently become an enforcement decision. References: src/…/types.ts• L15-74, src/…/evaluate.ts• L31-47

Policy controls

The policy controls define the approved state that the scan must meet. They cover both the result of analysis and the configuration surfaces that can change agent behavior.

ControlGovernance question
min_scoreIs the overall security score high enough?
max_severityDoes any finding exceed the allowed severity?
required_deny_listDo settings deny the required tool patterns?
banned_mcp_serversAre prohibited MCP servers absent?
banned_toolsAre prohibited tools absent from the allow list?
required_hooksAre the required lifecycle hooks configured?

The policy also carries a display name, description, pack identifier, and owner list. These fields give a reviewer the context for the decision without changing the checks themselves. References: src/…/types.ts• L39-70

Policy exceptions

A policy exception is a time-bounded approval for a known gap. It names an owner, reason, rule, and expiry time. An optional scope narrows the exception to violations whose details contain that scope. An optional ticket links the approval to an external work record.

Active exceptions can remove a matching violation from the final decision. Expired exceptions do not remove violations. They add an expired_exception violation instead. Evaluation also returns an audit summary with active, expiring-soon, and expired states. References: src/…/types.ts• L28-37, src/…/types.ts• L100-131, src/…/evaluate.ts• L152-176, src/…/evaluate.ts• L308-364

Policy pack presets

Policy packs are named starting points for common risk levels and operating settings. They let a team select a shared posture before it edits the policy for local needs. Each generated policy keeps the pack identifier so later results and promotion records can identify the intended posture.

Preset levels

The available packs cover public repositories, shared team work, managed enterprise groups, regulated environments, high-risk hooks or MCP use, and CI enforcement. Higher-assurance packs generally raise the score threshold and add restrictions or required runtime hooks.

PackMain use
ossPublic repositories with permissive contribution paths
teamShared private repositories and active development
enterpriseManaged production engineering groups
regulatedCompliance and sensitive-data environments
high-risk-hooks-mcpRepositories with privileged hooks or MCP integrations
ci-enforcementBranch-protection enforcement in GitHub Actions

The CLI can create an example policy from a pack with agentshield policy init. Owners and a display name can be supplied at creation time. The generated file is then the team-owned policy source rather than an immutable preset. References: src/…/presets.ts• L3-12, src/…/presets.ts• L37-85, src/index.ts• L1095-1136

Policy evaluation

Evaluation compares one scan’s findings, security score, and discovered configuration with one validated organization policy. It produces a structured result that reports compliance, unsuppressed violations, applied exceptions, exception life cycle data, and the score used for the decision.

Evaluation inputs

The CLI runs policy evaluation after the static scan and score calculation. It passes the findings selected by the scan severity threshold together with the full discovered configuration files. This means the scan threshold affects which finding severities reach the policy decision, while configuration checks still inspect the discovered settings and MCP data.

The evaluation checks the score and finding severity first. It then checks permissions, MCP server names, allowed tools, and hook commands. A violation records the rule, severity, expected state, actual state, and a description that can be shown to a reviewer or CI system. References: src/index.ts• L315-332, src/index.ts• L349-377, src/…/evaluate.ts• L52-149, src/…/types.ts• L76-98

Compliance decision

The final decision is compliant only when no violation remains after exception handling. A passing result can still be marked COMPLIANT (WITH EXCEPTIONS) when active exceptions were used. A failing result keeps every unsuppressed violation visible so that the team can fix the gap or change the policy through review.

The CLI reports a policy failure with exit code 4. SARIF includes the policy status and violation count alongside scan results. This keeps the policy decision available to both human reviewers and systems that consume scan output. References: src/…/evaluate.ts• L152-176, src/…/evaluate.ts• L454-525, src/index.ts• L372-386, src/index.ts• L516-517, src/…/sarif.ts• L63-84

The following flow shows how analysis becomes a compliance result.

flowchart LR
    A[Configuration target] --> B[Scan findings and score]
    B --> C[Severity-selected findings]
    B --> D[Discovered settings and MCP configuration]
    C --> E[Policy checks]
    D --> E
    E --> F[Apply active exceptions]
    F --> G{Violations remain?}
    G -->|No| H[Compliant]
    G -->|Yes| I[Non-compliant]
    F --> J[Exception audit]

Policy export

Policy export creates a reviewable bundle of generated pack files. The bundle separates policy selection from activation and gives each policy a manifest entry with a file name, pack identity, description, and SHA-256 digest.

Export bundle

The export command writes all known packs unless the caller selects one or more packs. It writes a stable JSON policy file for each selected pack and a manifest.json with schema version agentshield.policy-export.v1. Owners and a name prefix can be applied during generation so the exported bundle carries the intended review context.

The manifest is the integrity record for the bundle. A consumer should keep the manifest and the policy files together because promotion uses the manifest digest to confirm that the selected policy was not changed after export. References: src/…/export.ts• L7-27, src/…/export.ts• L29-66, src/index.ts• L1139-1189

Policy promotion

Promotion moves one exported pack into the active policy path only after the bundle passes integrity and identity checks. It supports a dry run so a team can inspect the review state before changing the policy used by enforcement.

Promotion verification

Promotion follows a fixed verification sequence:

  1. It loads the export manifest and checks its schema version.
  2. It selects the requested pack. A manifest with multiple packs requires an explicit pack choice.
  3. It resolves and reads the policy file named by the manifest.
  4. It checks the file’s SHA-256 digest against the manifest.
  5. It validates the policy and confirms that its declared pack matches the manifest entry.
  6. It writes the active policy unless the run is a dry run.

The result includes the selected pack, policy name, owners, verified digest, write state, and review items. A dry run verifies the source but leaves the active path unchanged. References: src/…/promote.ts• L20-39, src/…/promote.ts• L62-119, src/…/promote.ts• L182-253

Promotion review

Promotion is not the same as approval. Its review items show whether the bundle digest is verified, whether a policy owner exists, whether the protected rollout path is complete, and whether a runtime smoke scan still needs action. A successful write verifies the rollout-path item, but the runtime smoke item remains open until a scan uses the promoted policy.

The CLI exposes this state through agentshield policy promote. The command can emit JSON for automation or run with --dry-run for review without writing the active policy. References: src/…/promote.ts• L122-179, src/index.ts• L1191-1243

GitHub Action promotion

The GitHub Action can verify or promote an exported bundle before policy evaluation. Its default promotion mode is a dry run. When promotion writes an active policy and no separate policy path is supplied, that active path becomes the policy input for the same job.

The Action publishes promotion status, selected pack, review-item counts, required-action count, and digest as outputs. It can fail the job when review items remain if fail-on-policy-promotion is enabled. When the job evaluates the promoted path, it can mark the runtime smoke review item verified with that scan result. References: action.yml• L66-85, action.yml• L142-151, src/action.ts• L135-149, src/action.ts• L254-371, src/action-promotion.ts• L6-57, src/action-promotion.ts• L98-115

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep pack identifiers aligned across the policy schema, preset list, export manifest, promotion selector, and CI inputs.
  • Keep the exported policy bytes aligned with the manifest digest. Any post-export edit must create a new reviewed bundle.
  • Keep the policy pack declared inside a policy file aligned with the manifest entry selected for promotion.
  • Keep exception rule names, scopes, expiry times, and audit statuses aligned so an approval does not silently become a failure.
  • Keep the scan severity threshold and policy evaluation inputs aligned. A threshold change can change the compliance result.
  • Keep promotion review outputs aligned with the Action failure setting so a needs-review result cannot be treated as a verified rollout.

Important failure modes

TriggerConsequenceGuard
Policy file is missing or fails schema validationEvaluation returns an error and the CLI or Action cannot use the policyValidate the policy before enabling its gate
Manifest schema is unsupportedPromotion stops before selecting a policyExport and promote bundles with the same manifest schema
Exported policy content changes after exportDigest verification fails and no active policy is writtenReview and distribute the manifest with its exact policy files
Manifest contains several packs without a selected packPromotion stops because the target is ambiguousPass an explicit pack identifier
Policy file pack differs from its manifest entryPromotion rejects the bundleTreat the manifest identity and policy identity as one contract
Exception expires while its violation remainsThe gap is no longer suppressed and an expired_exception violation is addedRenew or remove the exception before expiry
Promotion stays in dry-run modeThe active policy does not change and rollout review remains incompleteUse a protected non-dry-run path after owner review
Promotion review still has action itemsThe Action reports needs-review; an enabled promotion gate fails the jobComplete owner, rollout, and runtime smoke checks

Key files

FileWhy to read it
src/…/types.tsDefines the policy, exception, violation, and evaluation contracts.
src/…/presets.tsDefines the available posture choices and their broad assurance differences.
src/…/evaluate.tsShows how scan outcomes and configuration become a compliance decision.
src/…/export.tsDefines the checksum-backed bundle that separates export from activation.
src/…/promote.tsDefines manifest verification, dry-run behavior, and promotion review items.
src/index.tsShows the CLI flow for policy initialization, evaluation, export, and promotion.
src/action.tsShows how promotion and policy evaluation become CI outputs and gate results.
src/action-promotion.tsSummarizes promotion review state for a GitHub Action job.
action.ymlDefines the CI inputs and outputs for policy evaluation and promotion.