Introducing a new way to review your PRs.

Read the announcement

hashgraph-online / hol-guard

Open-source antivirus and firewall for AI agents: block risky tools, secret access, prompt injection, malicious packages, MCP servers, plugins, and skills at runtime.

View on GitHub

44 documents · Updated Nov 23, 2026

docs / policy-bundles-integrity-and-sync

Policy bundles, integrity, and sync

A policy bundle is a signed package that carries trusted Guard Cloud policy or safety intelligence to a local Guard installation. Guard checks its source, identity, integrity, and freshness before it changes local authority. The same boundary controls local activation, device acknowledgement, and refresh when cloud access is unavailable.

This page is the bundle and local-state view of Policy authority and cloud exceptions. For exception requests, see Cloud exception request workflow. For cloud delivery and recovery, see Cloud review delivery and recovery. For business policy files and repair, see Business policy documents and recovery. For cloud operation, see Cloud actions connectivity and operations. For action-pack policy evaluation, see Cloud action packs and evaluation.

Policy bundle lifecycle

The bundle lifecycle turns a remote response into an authenticated local state. A daemon can request the first cloud sync when the device is connected and its first-sync milestone is still pending, but it does not hold up the runtime response while that work runs.

When Guard processes a policy or safety bundle, it follows this sequence:

  1. Resolve the connected workspace and cloud authentication context.
  2. Read the remote response or a cached response.
  3. Check the bundle shape, source identity, time window, version, and integrity data.
  4. Verify the response with a trusted key or other bundle-specific trust rule.
  5. Reject an old, conflicting, or incomplete response before it becomes active.
  6. Save the accepted bundle and its derived local state as one authority update.
  7. Use the accepted state for policy lookup, runtime defaults, or package-safety decisions.

This diagram shows how startup and repair sync reach the same guarded local state without making cloud access a requirement for every local protection step.

flowchart LR
    A[Daemon startup or repair action] --> B[Resolve workspace and cloud access]
    B --> C[Fetch or read cached bundle]
    C --> D[Parse and verify bundle]
    D --> E{Accepted?}
    E -->|yes| F[Persist active bundle and derived state]
    F --> G[Use local policy or safety intelligence]
    E -->|no| H[Keep last valid state or report a named next step]
    B -->|not paired or sign-in expired| H
    D -->|native authority unavailable| H

References: src/…/first_cloud_sync.py• L17-79 src/…/server.py• L1425-1467 src/…/runner.py• L3496-3577 src/…/native_policy_bundle.py• L148-248 rust/…/guard_store_policy_bundle_activated.rs• L24-60 rust/…/guard_store_policy_bundle_rejection.rs• L30-50

Bundle parsing and integrity

Bundle parsing defines the evidence that a remote policy or safety response must provide before Guard can use it. The Python boundary sends bounded JSON to the resident policy authority, which owns schema checks, canonical hashes, signatures, and version ordering; a resident outage is reported as unavailable rather than as a policy verdict.

The integrity checks serve different purposes:

CheckPurposeResult
Contract and field checksConfirm that the response has an allowed shape and supported valuesMalformed or unsupported data stays inactive
Canonical hash checksConfirm that the signed identity matches the exact contentContent changes cannot hide behind an old identity
Time and version checksConfirm that the response is fresh and orderedExpired or replayed state does not replace current state
Workspace checksConfirm that the response belongs to the connected workspaceData from another workspace cannot become local authority
Signature or trusted-key checksConfirm that an approved issuer signed the responseA response cannot create its own authority
Transport binding checksConfirm that the resident answered the exact request that was sentA stale, malformed, or mismatched resident answer is unavailable

The bridge also bounds input size, nesting, and page counts. Large decision or text results are reassembled only when their page order, total count or byte count, and digest agree. Cached data follows the same trust rule as new data, so an invalid cache cannot become a trusted shortcut.

Installed command-pack bundles used by authoring follow a separate fixed-release trust path. The authoring boundary uses the verified installed bundle as its source context and permits development staging only when an explicit development caller provides it. This keeps an uninstalled runtime from treating caller-supplied authoring data as installed authority.

Supply-chain responses use a workspace-scoped cache as transport storage. The cache records the response and selected identifying fields, but a cached response without the signed bundle or required fields is unusable. Reads are tied to the workspace in the local cloud credential and can return bounded pages so the caller can detect a changed response while reassembling it.

References: src/…/native_policy_bundle.py• L34-49 src/…/native_policy_bundle.py• L76-141 src/…/native_policy_bundle.py• L181-248 src/…/native_policy_bundle.py• L264-323 src/…/policy_bundle_parser.py• L1-7 src/…/policy_bundle_parser.py• L226-254 src/…/bundle_baseline.py• L59-85 rust/…/supply_chain_bundle_cache_op.rs• L76-157 rust/…/supply_chain_bundle_cache_op.rs• L163-196

Trusted-key validation

Trusted keys define which cloud authority may issue a bundle. The bundle can carry signing-key information, but that information only identifies the claimed issuer; it does not create a new local trust root.

Guard separates key discovery from key trust. A key must match the expected workspace and policy-bundle purpose. It must also be active when required and inside its validity window. A machine-managed key source takes precedence over user-writable sync state. If machine policy is present but invalid, inaccessible, empty, or missing its keyring, Guard keeps that trust domain fail-closed instead of falling back to a user copy.

Policy and supply-chain signing domains remain separate. Synced validation combines the permitted stored, synchronized, and managed context before the resident assembles the trust root. It can also return updated anchored keys for later validation, but a newly delivered key becomes usable only through the trust rules that admitted it. The supply-chain key loader is kept separate from bundle payload and signature code, so policy-key discovery can read that keyring without loading unrelated bundle processing. (src/…/supply_chain_verification_keys.py• L1-5)

References: src/…/policy_bundle_trusted_keys.py• L27-63 src/…/policy_bundle_trusted_keys.py• L129-181 src/…/policy_bundle_trusted_keys.py• L185-231 src/…/policy_bundle_trusted_keys.py• L282-365 src/…/policy_bundle_v2.py• L97-123 src/…/supply_chain_verification_keys.py• L1-5

Policy bundle versions

The established bundle contract and the v2 contract share the same trust boundary but use different signed evidence. The version choice affects how Guard derives the accepted payload and how it checks future state transitions.

Bundle formAuthority checksAccepted result
Established bundleSchema, canonical payload and bundle hashes, signature, workspace, freshness, daemon support, and downgrade orderA normalized payload with the verified payload hash
v2 bundleBounded envelope, canonical signed bytes, trusted signature, policy-document payload evidence, and current-time rulesThe validated signed envelope

The v2 payload is a policy document, not an arbitrary JSON value. Guard rejects unsupported numbers and oversized or deeply nested values. When the resident needs proof of the document hash, the local policy-document canonicalizer supplies evidence before validation completes.

References: src/…/policy_bundle_parser.py• L99-179 src/…/policy_bundle_trusted_keys.py• L315-365 src/…/policy_bundle_v2.py• L27-75 src/…/policy_bundle_v2.py• L97-123

Source context

Source context explains why an active policy row exists without changing the row's authority. Guard can attach a human command or label, workspace information, a receipt or approval identity, and a source path to a decision so an operator can understand its origin.

The context comes from matching approval, runtime, or inventory records. It remains separate from the signed policy meaning. A better label can explain a decision, but it cannot broaden the rule, change its owner, or extend its lifetime.

References: src/…/store_policy_source_context.py• L11-82 src/…/store_policy_source_context.py• L378-475 src/…/store_policy_source_context.py• L880-923

Rule activation

Activation converts an accepted bundle into the narrow local decisions that runtime checks can consume. The resident matches rule scope and checks exact representability, so a saved family decision is created only when it does not drop a constraint from the signed rule.

Canonical v2 bundles can also carry command-pattern Allow rules. Guard reads these rules from the validated bundle for the current device and can settle only an eligible review when every received command matches the pattern and its scope and time limits. A pattern does not create authority outside the signed bundle.

The local device and environment filter runs before materialization. Each resulting decision keeps a link to its source rule and carries the reason, owner, and expiry needed for later review. Decision rows may arrive in bounded pages, but Guard uses them only after the resident reports a complete and consistent result.

Cached policy rows are not authority by themselves. The resident revalidates the cached bundle and derives its decision identities again for the current device. A bundle that cannot pass validation or cannot produce the same decision set authorizes no cached rows. If the resident cannot determine the result in the same way as the policy store, the lookup defers instead of handing uncertain rows to a less trusted path.

References: src/…/policy_bundle_decisions.py• L1-42 src/…/policy_bundle_delivery.py• L41-70 src/…/policy_bundle_activation.py• L61-115 src/…/cloud_exceptions.py• L102-108 src/…/cloud_exceptions.py• L201-228 rust/…/policy_bundle_store_identities.rs• L64-145 rust/…/policy_bundle_store_identities.rs• L174-260 rust/…/policy_bundle_store_identities.rs• L285-329 rust/…/edge_command_pattern_allow.rs• L47-77 rust/…/edge_command_pattern_allow.rs• L103-165

Local activation and synchronization

Local activation keeps the accepted bundle, its derived rows, its delivery acknowledgement, and its sync state aligned. A resident verdict can take time, so Guard computes it outside the authority lock and reuses it only when it was derived from the exact state being written. The final acknowledgement is then built from the state observed under the write lock.

The store keeps the accepted bundle as a last-good copy. Canonical v2 activation preserves the replaced canonical bundle as a previous-good copy, while older bundle forms remain in a separate last-good slot. If cloud data is rejected and a stored bundle is restored, Guard records the rollback reason with that activation. It also applies the bundle's valid receipt-redaction level in the same write, so the bundle and its receipt bookkeeping cannot drift apart.

Rejection bookkeeping follows the same atomic rule. A rejection can update the last-error state and always records the rejection event; an approval-gate block can add a second event. Invalid event or payload writes roll back the related state change, so readers do not see only half of the rejection result.

Cloud synchronization uses the connected workspace and a local authentication context. The sync path can use a cached bundle when it is still valid. It stores a newly verified response and its related key and entitlement data only after the response passes verification. The active bundle version and hash provide the sequence identity that prevents an older response or a same-version conflict from silently replacing current authority.

Managed-controls rollout gates which connected-cloud capabilities are exposed. Catalog sync is enabled by default unless explicitly opted out. Policy targets, managed controls, atomic apply, and the first-controls UI become available only when their required earlier capabilities are active, while custom extension continuity requires the full chain.

The daemon starts a first sync only when local state says that a connected device still needs it. It repairs missing connection state first and stops without queueing work when the device is not paired, authentication remains degraded, or local storage fails. The queued operation runs in the background and avoids duplicate work while another sync is active.

Resident reads now derive cached-bundle authority through the same validation and decision-building contract used by the policy store. They apply stored and machine-managed keyrings, workspace binding, freshness, rollout, and downgrade rules before they expose cached decisions. If the resident cannot reproduce that authority, it defers the lookup instead of silently handing uncertain rows back to a less trusted path. This keeps local policy rows tied to the signed bundle that produced them.

References: src/…/policy_bundle_activation.py• L118-225 src/…/policy_bundle_delivery.py• L80-140 src/…/first_cloud_sync.py• L32-77 src/…/server.py• L1425-1467 src/…/server.py• L1482-1493 src/…/runner.py• L3503-3516 src/…/runner.py• L3576-3619 src/…/feature_flags.py• L48-87 rust/…/policy_bundle_store_identities.rs• L147-329 rust/…/guard_store_policy_bundle_activated.rs• L24-60 rust/…/guard_store_policy_bundle_rejection.rs• L21-50

Supply-chain repair synchronization

Supply-chain repair treats intelligence refresh as one independent recovery step beside package-shim repair and runtime activation. This keeps package protection local and available even when cloud intelligence cannot refresh.

The repair path resolves cloud access before it starts the intelligence sync. An untrusted endpoint remains a hard error. A missing connection or expired sign-in becomes a named remaining step that tells the operator to connect or reconnect. Workspace-wide audits stay outside the repair response, so a repair request can finish without waiting for long audits.

The repair coordinator reports completed steps, failed steps, and remaining steps separately. Its final result is incomplete when intelligence refresh needs operator action, even when package protection and runtime activation already completed.

References: src/…/supply_chain_repair_sync.py• L16-65 src/…/supply_chain_repair.py• L17-95 src/…/server.py• L3707-3749 src/…/supply_chain_repair_errors.py• L6-14 rust/…/supply_chain_bundle_cache_op.rs• L60-105 rust/…/supply_chain_bundle_cache_op.rs• L108-196

Runtime policy authority

Runtime consumers use an authenticated active bundle or the verified local state derived from it. Legacy top-level policy and exception fields do not become authority when a signed bundle is absent, expired, malformed, or rejected.

When cloud sync is unavailable, Guard keeps valid local protection and reports the missing cloud step instead of treating stale or unsigned data as a replacement. This separates continuity of local enforcement from freshness of cloud intelligence.

References: src/…/synced_policy.py• L87-112 src/…/config.py• L887-931 src/…/runner.py• L3496-3619 src/…/supply_chain_repair.py• L77-95

Change checklist

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

  • Changes to bundle identity or signed fields must update the matching canonical hash, signature, and transition contract.
  • Changes to v2 policy-document handling must preserve the resident evidence request and the same canonical document hash.
  • Changes to trusted-key metadata must preserve workspace binding, purpose, validity, and managed-source precedence.
  • Changes to cache contents must keep cached responses subject to the same verification as newly fetched responses.
  • Changes to resident request or response envelopes must preserve request identity, request binding, bounded paging, and outage-versus-verdict error mapping.
  • Changes to sync admission must preserve the connected-state and first-sync milestone checks.
  • Changes to managed-controls capability gates must preserve the digest-bound catalog sync contract and the prerequisite order for later control features.
  • Changes to activation persistence must keep the active bundle, previous-good or last-good copy, rollback event, receipt-redaction state, acknowledgement, key material, entitlement summary, and sequence identity aligned.
  • Changes to rejection persistence must keep the last-error row and rejection events in one write, and must preserve the separate approval-gate event when that gate blocks sync.
  • Changes to resident cached-bundle lookup must keep key validation, rollout and downgrade checks, decision identity derivation, and the defer-on-uncertainty behavior aligned with the policy store.
  • Changes to source context must not alter the signed rule scope or decision authority.
  • Changes to supply-chain key loading must keep its key type and loader independent from bundle payload processing while preserving the separate supply-chain trust domain.
  • Changes to supply-chain cache reads or writes must preserve workspace binding, required identifying fields, page metadata, and the distinction between an empty cache and an unreadable response.
  • Changes to authoring bundle admission must preserve the installed-release binding and keep development staging explicit rather than making it an installed runtime fallback.

Important failure modes

TriggerConsequenceGuard
Cached or new bundle fails shape, hash, signature, workspace, or freshness checksThe bundle does not become active local authorityApply the full verification contract before persistence or use
Resident answer has the wrong request identity, digest, page order, or totalGuard treats the authority service as unavailable and does not use the answerBind each answer to its request and verify the complete paged result
Trusted key is unknown, invalid, expired, or from the wrong workspaceCloud policy or safety intelligence is rejectedMatch the response to an anchored key with the correct purpose and workspace
Machine-managed trust is configured but invalid or missing its keyringUser-writable key state cannot silently take overKeep the managed trust domain fail-closed
Device is not paired or sign-in remains degraded during first syncNo background sync is queuedRepair connection state first and require a connected first-sync state
A managed-controls prerequisite is disabled or catalog sync is opted outDependent connected-cloud capabilities are not exposedPreserve the capability chain and enable each feature only after its required earlier capability
Cached supply-chain response fails revalidationGuard fetches a fresh response or reports sync failureReverify cached data and do not use an unverified cache
Resident verdict is computed from state that changes before the writeAn acknowledgement or activation could describe the wrong authorityCompute outside the lock, then retry against the exact state observed under the lock
Cached bundle validation or decision derivation cannot reproduce the signed bundle's authorityCached policy rows authorize nothing or the lookup defers instead of using uncertain stateReapply the shared validation contract and derive identities from the current device context
A command-pattern Allow is missing from the live validated bundle or does not match every received commandAn eligible review remains a reviewRead patterns only from the validated bundle and require scope, expiry, and full command matching
Activation bookkeeping fails after a last-good copy or rollback event is preparedThe transaction leaves neither the new bundle state nor partial bookkeeping visibleKeep activation and receipt-redaction updates in the store write transaction
Rejection payload is not an object or an event write failsNo invalid rejection state is recorded, or the prior last-error state remainsValidate payloads before writing and roll back the last-error row with its events
Supply-chain cache has no current workspace, required fields, or complete responseReads return no usable bundle or reject the cache writeBind reads to the signed-in workspace and require the bundle, payload hash, and identifying fields
Repair cannot refresh cloud intelligence because connection is missing or expiredPackage protection can remain active, but repair stays incompleteReturn a named connect or reconnect step
Repair sees an untrusted cloud endpointThe repair does not downgrade the trust failure to a retry stepPropagate the endpoint-trust error as a hard failure
Unsigned legacy policy is present without an accepted bundleLegacy data does not replace authenticated runtime authorityRead remote defaults only from an active verified bundle
Installed authoring lacks a verified release bundle or uses invalid bundle dataNative authoring context is unavailable and the runtime stays fail-closedRequire the verified installed bundle and keep all referenced data bounded and authenticated

Key files

FileWhy to read it
src/…/native_policy_bundle.pyShows the bounded resident boundary, request binding, typed outages, and paged-result checks.
src/…/policy_bundle_parser.pyDefines the established bundle contract and its acceptance checks.
src/…/policy_bundle_v2.pyDefines the bounded v2 envelope, canonical policy-document evidence, transition, and acknowledgement rules.
src/…/policy_bundle_trusted_keys.pyExplains trusted-key loading, workspace binding, managed trust precedence, and synced validation.
src/…/supply_chain_verification_keys.pyDefines the separate supply-chain key type and loader used without loading bundle payload processing.
src/…/policy_bundle_decisions.pyShows how verified rules become exact local decisions.
src/…/policy_bundle_delivery.pyShows delivery binding, runtime projection checks, and acknowledgement selection.
src/…/policy_bundle_activation.pyShows how activation and acknowledgements use one observed authority state.
rust/…/guard_store_policy_bundle_activated.rsShows the atomic last-good, previous-good, rollback, and receipt-redaction bookkeeping for an accepted bundle.
rust/…/guard_store_policy_bundle_rejection.rsShows atomic rejection error and event recording, including approval-gate blocks.
rust/…/policy_bundle_store_identities.rsShows how resident reads revalidate cached bundles and re-create the decision identities they authorize without a silent fallback.
rust/…/policy_bundle_store_identities_tests.rsShows the guarantees for empty, invalid, oversized, canonical, and device-scoped cached bundles.
rust/…/edge_command_pattern_allow.rsShows how validated v2 command-pattern Allows use device context and remain bounded by command, scope, and expiry checks.
src/…/runner.pyShows cloud authentication, cached and remote bundle verification, and persistence of verified safety state.
src/…/first_cloud_sync.pyShows when daemon startup admits the first background cloud sync.
src/…/feature_flags.pyShows the default catalog-sync gate and the prerequisite chain for managed-control capabilities.
src/…/store_policy_source_context.pyShows how decisions gain human-readable source context without changing authority.
src/…/supply_chain_repair_sync.pyShows cloud access checks and named deferred steps for supply-chain intelligence refresh.
src/…/supply_chain_repair.pyShows how repair reports completed, failed, and remaining recovery work.
src/…/server.pyShows first-sync admission and the supply-chain repair entry point.
rust/…/supply_chain_bundle_cache_op.rsShows workspace-scoped supply-chain cache reads, writes, required fields, and bounded response paging.
src/…/synced_policy.pyShows how accepted local bundle state reaches runtime defaults.
src/…/bundle_baseline.pyShows how authoring uses a verified installed bundle or explicit development staging as its source context.
src/…/installed_bundle.pyShows the fixed-release bundle identity and bounded reads used by installed authoring.