Skip to content

Guards and Integrity: tracking issue #1711

Description

@lpcox

Overview

Tracking issue for the Guards and Integrity work in MCP Gateway. This covers the DIFC (Decentralized Information Flow Control) engine, WASM guard framework, GitHub Guard implementation, and end-to-end integration with the gh-aw compiler.


Specifications

gh-aw (compiler & platform)

Document Description
MCP Gateway Configuration Reference Canonical gateway config spec — server types, guard-policies schema, containerization requirements
MCP Gateway Config JSON Schema Machine-readable schema for config validation
MCP Scripts Specification MCP scripts spec (compiler input format)
gh-aw as MCP Server gh-aw MCP server reference

gh-aw-mcpg (gateway)

Core DIFC rules:

Document Description
DIFC_RULES.md Secrecy/integrity labels, read/write flow rules, enforcement modes, testing guidelines
DIFC_INTEGRATION_PROPOSAL.md Complete DIFC architecture and design decisions
GUARD_RESPONSE_LABELING.md Response labeling mechanism and label lifecycle

GitHub Guard specs:

Document Description
GitHub Guard README Guard architecture, WASM entrypoints, AllowOnly operating modes, labeling tables
INTEGRITY_TAG_SPEC.md Complete integrity hierarchy: merged > approved > unapproved > none
SECRECY_TAG_SPEC.md Secrecy label rules, private/public repo labeling
GATEWAY_ALLOWONLY_INTEGRATION_SPEC.md Guard policy JSON structure, scope validation, CLI arguments
LABELING.md How DIFC labels are applied to GitHub operations
LABEL_AGENT_IMPLEMENTATION_PLAN.md Label agent lifecycle and session handling
OVERVIEW.md Guard features overview
IMPLEMENTATION.md Technical implementation details
TESTING.md Test information and coverage

Configuration examples:

Document Description
config.example.toml TOML config with guard-policies examples (lines 72–88)
agentic-workflow-policy.schema.json JSON schema for agentic workflow policy frontmatter

Integrity Level Criteria

Hierarchy

merged > approved > unapproved > none (highest to lowest trust)

Labels are hierarchically expanded — each level includes all levels below it:

Assigned Level Labels Generated
merged none:<scope> + unapproved:<scope> + approved:<scope> + merged:<scope>
approved none:<scope> + unapproved:<scope> + approved:<scope>
unapproved none:<scope> + unapproved:<scope>
none none:<scope>

All objects receive at least none:<scope> via ensure_integrity_baseline().

Authorship Rules

The author_association field from the GitHub API maps to an integrity floor:

author_association Integrity Floor Source
OWNER approved helpers.rs: author_association_floor_from_str
MEMBER approved same
COLLABORATOR approved same
CONTRIBUTOR unapproved same
FIRST_TIME_CONTRIBUTOR unapproved same
FIRST_TIMER none same
NONE / missing none same

Additional authorship modifiers:

Condition Effect Source
Bot author (login ends with [bot]/-bot, or exact match: dependabot, renovate, github-actions, copilot) Treated as approved helpers.rs: is_bot
Private repo All authors elevated to at least approved tool_rules.rs, helpers.rs: issue_integrity, pr_integrity, commit_integrity

Reachability Rules (Object-Specific)

Reachability affects commits, PRs, and file contents. The rules vary by object type:

Commits (helpers.rs: commit_integrity, tool_rules.rs):

Condition Integrity
Default branch (main, master, HEAD, or empty) merged
Feature branch, private repo approved
Feature branch, public repo none

Pull Requests (helpers.rs: pr_integrity):

Condition Integrity
Merged (regardless of author or repo) merged
Unmerged, private repo approved
Unmerged, public repo, direct (same-repo) approved
Unmerged, public repo, from fork unapproved

File Contents (tool_rules.rs, response_items.rs, response_paths.rs):

Condition Integrity
Default branch ref merged
Other branch ref approved

Per-Object Integrity

Object Type Condition Integrity Source
Repository metadata Any approved tool_rules.rs: writer_integrity
Commits Default branch merged helpers.rs: commit_integrity
Commits Feature branch (private) approved same
Commits Feature branch (public) none same
Pull Requests Merged merged helpers.rs: pr_integrity
Pull Requests Unmerged, private repo approved same
Pull Requests Unmerged, public, direct approved same
Pull Requests Unmerged, public, from fork unapproved same
Issues / Comments author_association floor (see above), private repo elevates to approved varies helpers.rs: issue_integrity
File contents Default branch merged tool_rules.rs, response_items.rs
File contents Feature branch approved same
Releases Always (endorsed by maintainers) merged response_items.rs: merged_integrity
Tags Always approved tool_rules.rs: writer_integrity
Branches Always approved tool_rules.rs: writer_integrity
Security alerts Code scanning, Dependabot, Secret scanning approved tool_rules.rs: writer_integrity
Actions / Workflows Maintained by repo team approved tool_rules.rs: writer_integrity
User profiles / Search GitHub official data approved:github helpers.rs: project_github_labelwriter_integrity("github")
Gists User content (public or private) unapproved response_items.rs: reader_integrity("user")
Notifications User context none response_items.rs: none_integrity

Note: label_resource (pre-execution) and label_response (post-execution) may assign different integrity levels for the same tool. Response-level labeling refines resource-level labels with per-item context (e.g., merge status, author association). The table above reflects effective response-level integrity.

Secrecy Labels

Condition Secrecy Label Source
Public repo [] (empty — anyone can read) tool_rules.rs
Private repo private:<owner>/<repo> helpers.rs: policy_private_scope_label
Secret scanning alerts secret tool_rules.rs: secret_label
Sensitive files (.env, .key, .pem, .p12, .pfx, id_rsa, id_dsa, id_ecdsa, id_ed25519) secret constants.rs: SENSITIVE_FILE_PATTERNS
Files with sensitive keywords (secret, credential, password, token in filename) secret constants.rs: SENSITIVE_FILE_KEYWORDS
Workflow files (.github/workflows/*) secret (may contain tokens) tool_rules.rs: check_file_secrecy
Action artifact downloads secret tool_rules.rs
Notifications private:user response_items.rs
Private gists private:user response_items.rs
Public gists [] (empty) response_items.rs

DIFC Flow Rules

Rule Check
Read Agent.secrecy ⊇ Data.secrecy AND Data.integrity ⊇ Agent.integrity
Write Resource.secrecy ⊇ Agent.secrecy AND Agent.integrity ⊇ Resource.integrity

Work Completed

Core DIFC Engine (internal/difc/)

  • Three enforcement modes: strict (deny violations), filter (remove disallowed items), propagate (auto-adjust agent labels)
  • AgentLabels with thread-safe secrecy/integrity label management
  • Evaluator with read/write flow rules based on secrecy and integrity subset checks
  • Fine-grained PathLabels for JSONPath-based response labeling on collections
  • ~6,000 LOC implementation + ~3,800 LOC tests

Guard Framework (internal/guard/)

  • Abstract Guard interface with three WASM entrypoints: LabelAgent, LabelResource, LabelResponse
  • WasmGuard implementation using wazero runtime with thread-safe mutex serialization
  • NoopGuard fallback for unguarded sessions
  • Per-server guard registry and factory

GitHub Guard (guards/github-guard/)

  • Complete Rust-based WASM guard (~170KB compiled) with full GitHub MCP tool coverage
  • Secrecy labeling: public repos (empty), private repos (private:owner/repo)
  • Integrity hierarchy: none < unapproved < approved < merged
  • Backend API integration for contributor verification
  • Sensitive content detection (secrets, security issues)
  • Baked into the gateway Docker image

Guard Policies (internal/config/guard_policy.go)

  • AllowOnly policy model with flexible scope matching
  • Repos field: "all", "public", exact match, wildcards (owner/*, owner/prefix*)
  • MinIntegrity field: none, unapproved, approved, merged
  • Support in both TOML and JSON configuration formats

CLI and Configuration

  • 12 CLI flags for guards configuration (--enable-guards, --guards-mode, --guard-policy-json, etc.)
  • Environment variable support (MCP_GATEWAY_ENABLE_GUARDS, MCP_GATEWAY_GUARDS_MODE, etc.)
  • Config extensions for session-level secrecy/integrity labels
  • Per-server guard-policies in both TOML and JSON stdin formats

User-Facing Nomenclature

  • Renamed difcguards in all user-facing flags, env vars, config keys, and docs
  • Renamed readerunapproved, writerapproved for integrity labels
  • Renamed integritymin-integrity in policy configuration
  • Canonical policy key: allow-only (with backward compat for allowonly)

Testing

  • ~8,500 LOC of unit tests across 12 test files (DIFC core, guards, config, CLI flags)
  • Integration tests for DIFC config, environment variables, gateway startup
  • Copilot CLI smoke tests in four operating modes (yolo, public-only, owner-only, repo-only)
  • Manual end-to-end validation of all GitHub MCP read-only tools across all four modes

CI/CD

  • WASM guard built in release workflow with Rust cross-compilation
  • Guard baked into Docker image during build
  • Cross-repo release publishing to lpcox/github-guard

Key PRs


Next Steps

  • End-to-end integration tests with the gh-aw compiler — Validate that guard policies configured via gh-aw workflow specs compile correctly into gateway configurations and enforce the expected DIFC behavior at runtime
  • Compiler-generated guard-policies validation (TOML and JSON output)
  • Round-trip testing: workflow spec → compiler → gateway config → runtime enforcement
  • Test all four operating modes (yolo, public-only, owner-only, repo-only) through the compiler pipeline

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions