Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
8ca2e1d
feat(difc): add propagate enforcement mode and --difc-mode flag
lpcox Feb 7, 2026
953548f
feat: add config extensions for session labels
lpcox Feb 7, 2026
1fb9c69
feat: Add DIFC config extensions with schema bypass
lpcox Feb 7, 2026
6aa8fd9
docs: Add DIFC environment variables, flags, and config extensions re…
lpcox Feb 7, 2026
f9edbf1
refactor: Centralize DIFC mode string constants in difc package
lpcox Feb 7, 2026
0615448
feat: Load guards from config instead of always using NoopGuard
lpcox Feb 8, 2026
bac03ef
feat: Restore WASM guard support and path-based labeling
lpcox Feb 8, 2026
52e77dc
test: Add GitHub WASM guard integration tests
lpcox Feb 8, 2026
43856c9
fix: Load WASM guards from config path instead of factory lookup
lpcox Feb 8, 2026
d6db366
fix: Skip coarse-grained DIFC check for reads in filter/propagate mode
lpcox Feb 8, 2026
34cacd2
fix: Correct DIFC propagate mode label semantics
lpcox Feb 8, 2026
ee64df9
added doc
lpcox Feb 8, 2026
3e51134
docs: Update GUARD_RESPONSE_LABELING with DIFC rules and fix NoopGuard
lpcox Feb 9, 2026
4da3476
Fix strict mode DIFC implementation and lint issues
lpcox Feb 9, 2026
e7b2b91
fix: Unwrap MCP responses before applying path-based labels
lpcox Feb 9, 2026
57ad274
debug: Add logging for tool args passed to guard LabelResource
lpcox Feb 10, 2026
d59e427
fixed guard bugs
lpcox Feb 20, 2026
cdc4e18
Propagate tool_args to DIFC LabelResponse
lpcox Feb 21, 2026
087d0a8
Allow read operations to proceed for response labeling
lpcox Feb 21, 2026
1674e0d
Set DIFC agent ID from session context
lpcox Feb 21, 2026
e83cb57
Harden label_agent payload and fail-closed handling
lpcox Feb 22, 2026
74e6653
Add AllowOnly policy and label_agent session integration
lpcox Feb 22, 2026
3563b54
Align AllowOnly integrity baseline to None
lpcox Feb 23, 2026
d66b27b
Align allowonly validation with updated schema regex
lpcox Feb 23, 2026
4439226
Send strict top-level allowonly payload to label_agent
lpcox Feb 24, 2026
a590c05
Normalize guard normalized_policy scope_kind to lowercase
lpcox Feb 24, 2026
a7f5a62
Add DIFC sink-aware agent tag snapshots to RPC JSONL logs
lpcox Feb 24, 2026
bc2e92b
Add configurable DIFC sink server IDs and fix lint/test issues
lpcox Feb 24, 2026
9eeb53c
Update JSONL logger changes
lpcox Feb 24, 2026
7ac52ff
Initial plan
Claude Feb 23, 2026
5db2f25
Initial plan
Claude Feb 23, 2026
83c7aec
Refactor: Extract wrapWithMiddleware helper to eliminate duplicate code
Claude Feb 23, 2026
3a6c829
Initial plan
Claude Feb 23, 2026
dfa58a4
Initial plan
Claude Feb 23, 2026
3acbce1
Initial plan
Claude Feb 24, 2026
79077bb
Initial plan
Claude Feb 24, 2026
4ace630
Refactor: consolidate function clustering - move Docker utils, replac…
Claude Feb 24, 2026
2f408b8
feat: Add DIFC config extensions with schema bypass
lpcox Feb 7, 2026
5e0d928
Set DIFC agent ID from session context
lpcox Feb 21, 2026
3d0acbd
Fix agent-finished failures in mcp and integration tests
lpcox Feb 25, 2026
1221e4b
Resolve rebase conflicts and restore passing test suite
lpcox Feb 25, 2026
acdcb2a
Resolve post-rebase MCP test and transport conflicts
lpcox Feb 25, 2026
d972693
chore: update root command handling
lpcox Feb 25, 2026
3ff7307
docs: add LabelAgent documentation to GUARD_RESPONSE_LABELING.md
lpcox Feb 27, 2026
95b932b
docs: add end-to-end GitHub guard scoping example
lpcox Feb 27, 2026
556b378
updated labeling doc
lpcox Feb 27, 2026
25a3903
add MCP_GATEWAY_WASM_GUARDS_DIR guard discovery and fix lint
lpcox Mar 1, 2026
fa7277c
log MCP_GATEWAY_WASM_GUARDS_DIR at unified startup
lpcox Mar 1, 2026
ff61042
log MCP_GATEWAY_WASM_GUARDS_DIR in container entrypoint
lpcox Mar 1, 2026
010f172
log per-server guard policies at startup
lpcox Mar 2, 2026
07f3788
fix DIFC guard policy resolution and label_agent init
lpcox Mar 3, 2026
e166e65
rebase: restore setupSessionCallback lost during rebase onto main
lpcox Mar 4, 2026
39850f4
rename integrity labels: reader→unapproved, writer→approved
lpcox Mar 5, 2026
725728f
gitignore: exclude gateway.log and pdf files
lpcox Mar 5, 2026
8ee5e8d
refactor: rename guard policy field 'integrity' → 'min-integrity'
lpcox Mar 8, 2026
afc0f6a
fix: eliminate data race in AgentLabels bulk tag mutations
Copilot Mar 8, 2026
fe18d88
fix: ephemeral ports in difc_config_test and use resolveGuardPolicy i…
Copilot Mar 8, 2026
b07b623
feat: hide sys tools from MCP SDK; accept allow-only (with dash) as c…
Copilot Mar 8, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@ scripts/rebase-github-difc.sh
# Serena cache directories
.serena/
.DS_Store

# Runtime artifacts
gateway.log
*.pdf
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ DEBUG_COLORS=0 DEBUG=* ./awmg --config config.toml
- `DEBUG_COLORS` - Control colored output (0 to disable, auto-disabled when piping)
- `MCP_GATEWAY_LOG_DIR` - Log file directory (sets default for `--log-dir` flag, default: `/tmp/gh-aw/mcp-logs`)
- `MCP_GATEWAY_PAYLOAD_DIR` - Large payload storage directory (sets default for `--payload-dir` flag, default: `/tmp/jq-payloads`)
- `MCP_GATEWAY_DIFC_SINK_SERVER_IDS` - Comma-separated server IDs whose RPC JSONL logs should include agent secrecy/integrity tag snapshots (sets default for `--difc-sink-server-ids`)

**Note:** The `PORT`, `HOST`, and `MODE` environment variables are used only by test scripts and are not read by the gateway application. The gateway uses command-line flags instead: `--listen` for bind address and `--routed`/`--unified` for mode selection.

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This gateway is used with [GitHub Agentic Workflows](https://github.com/github/g
- Adds missing `properties` field to object schemas
- Prevents downstream validation errors
- Transparent to both backends and clients
- **Routing Modes**:
- **Routing Modes**:
- **Routed**: Each backend server accessible at `/mcp/{serverID}`
- **Unified**: Single endpoint `/mcp` that routes to configured servers
- **Docker Support**: Launch backend MCP servers as Docker containers
Expand Down Expand Up @@ -398,6 +398,8 @@ When running locally (`run.sh`), these variables are optional (warnings shown if
| `MCP_GATEWAY_PAYLOAD_DIR` | Large payload storage directory (sets default for `--payload-dir` flag) | `/tmp/jq-payloads` |
| `MCP_GATEWAY_PAYLOAD_PATH_PREFIX` | Path prefix for remapping payloadPath returned to clients (sets default for `--payload-path-prefix` flag) | (empty - use actual filesystem path) |
| `MCP_GATEWAY_PAYLOAD_SIZE_THRESHOLD` | Size threshold in bytes for payload storage (sets default for `--payload-size-threshold` flag) | `524288` |
| `MCP_GATEWAY_WASM_GUARDS_DIR` | Root directory for per-server WASM guards (`<root>/<serverID>/*.wasm`, first match is loaded) | (disabled) |
| `MCP_GATEWAY_DIFC_SINK_SERVER_IDS` | Comma-separated sink server IDs for JSONL DIFC tag enrichment (sets default for `--difc-sink-server-ids`) | (disabled) |
| `DEBUG` | Enable debug logging with pattern matching (e.g., `*`, `server:*,launcher:*`) | (disabled) |
| `DEBUG_COLORS` | Control colored debug output (0 to disable, auto-disabled when piping) | Auto-detect |
| `RUNNING_IN_CONTAINER` | Signals the gateway is running inside a container (set automatically by container runtimes) | `true` |
Expand Down
556 changes: 556 additions & 0 deletions docs/GUARD_RESPONSE_LABELING.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/itchyny/gojq v0.12.18
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1
github.com/stretchr/testify v1.11.1
github.com/tetratelabs/wazero v1.11.0
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY=
github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/tetratelabs/wazero v1.11.0 h1:+gKemEuKCTevU4d7ZTzlsvgd1uaToIDtlQlmNbwqYhA=
github.com/tetratelabs/wazero v1.11.0/go.mod h1:eV28rsN8Q+xwjogd7f4/Pp4xFxO7uOGbLcD/LzB1wiU=
github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4=
github.com/yosida95/uritemplate/v3 v3.0.2/go.mod h1:ILOh0sOhIJR3+L/8afwt/kE++YT040gmv5BQTMR2HP4=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
Expand Down
209 changes: 207 additions & 2 deletions internal/cmd/flags_difc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,51 @@ package cmd
// DIFC (Decentralized Information Flow Control) related flags

import (
"fmt"
"os"
"strings"

"github.com/github/gh-aw-mcpg/internal/config"
"github.com/github/gh-aw-mcpg/internal/difc"
"github.com/github/gh-aw-mcpg/internal/envutil"
"github.com/spf13/cobra"
)

// DIFC flag defaults
const (
defaultEnableDIFC = false
defaultEnableDIFC = false
defaultConfigExtensions = false
)

// DIFC flag variables
var (
enableDIFC bool
enableDIFC bool
difcMode string
enableConfigExt bool // Enable config extensions (guards, session labels)
sessionSecrecy string // Comma-separated initial secrecy labels
sessionIntegrity string // Comma-separated initial integrity labels
difcSinkServerIDs string // Comma-separated server IDs that should include DIFC tag snapshots in RPC JSONL logs
guardPolicyJSON string
allowOnlyPublic bool
allowOnlyOwner string
allowOnlyRepo string
allowOnlyMinInt string
)

func init() {
RegisterFlag(func(cmd *cobra.Command) {
cmd.Flags().BoolVar(&enableDIFC, "enable-difc", getDefaultEnableDIFC(), "Enable DIFC enforcement for information flow control")
cmd.Flags().MarkHidden("enable-difc")
cmd.Flags().StringVar(&difcMode, "difc-mode", getDefaultDIFCMode(), "DIFC enforcement mode: strict (deny violations), filter (remove denied tools), or propagate (auto-adjust agent labels on reads)")
cmd.Flags().BoolVar(&enableConfigExt, "enable-config-extensions", getDefaultConfigExtensions(), "Enable config extensions (guards, session labels) - required for DIFC session label features")
cmd.Flags().StringVar(&sessionSecrecy, "session-secrecy", getDefaultSessionSecrecy(), "Comma-separated initial secrecy labels for agent sessions (requires --enable-config-extensions)")
cmd.Flags().StringVar(&sessionIntegrity, "session-integrity", getDefaultSessionIntegrity(), "Comma-separated initial integrity labels for agent sessions (requires --enable-config-extensions)")
cmd.Flags().StringVar(&difcSinkServerIDs, "difc-sink-server-ids", getDefaultDIFCSinkServerIDs(), "Comma-separated server IDs whose RPC JSONL logs should include agent secrecy/integrity tag snapshots")
cmd.Flags().StringVar(&guardPolicyJSON, "guard-policy-json", getDefaultGuardPolicyJSON(), "Guard policy JSON (e.g. {\"allow-only\":{\"repos\":\"public\",\"min-integrity\":\"none\"}})")
cmd.Flags().BoolVar(&allowOnlyPublic, "allowonly-scope-public", getDefaultAllowOnlyScopePublic(), "Use public AllowOnly scope")
cmd.Flags().StringVar(&allowOnlyOwner, "allowonly-scope-owner", getDefaultAllowOnlyScopeOwner(), "AllowOnly owner scope value")
cmd.Flags().StringVar(&allowOnlyRepo, "allowonly-scope-repo", getDefaultAllowOnlyScopeRepo(), "AllowOnly repo name (requires owner)")
cmd.Flags().StringVar(&allowOnlyMinInt, "allowonly-min-integrity", getDefaultAllowOnlyMinIntegrity(), "AllowOnly integrity: none|unapproved|approved|merged")
})
}

Expand All @@ -29,3 +56,181 @@ func init() {
func getDefaultEnableDIFC() bool {
return envutil.GetEnvBool("MCP_GATEWAY_ENABLE_DIFC", defaultEnableDIFC)
}

// getDefaultDIFCMode returns the default DIFC mode, checking MCP_GATEWAY_DIFC_MODE
// environment variable first, then falling back to the hardcoded default (strict)
func getDefaultDIFCMode() string {
if envMode := os.Getenv("MCP_GATEWAY_DIFC_MODE"); envMode != "" {
mode := strings.ToLower(envMode)
if isValidDIFCMode(mode) {
return mode
}
}
return difc.ModeStrict
}

// isValidDIFCMode checks if the given mode string is a valid DIFC mode
func isValidDIFCMode(mode string) bool {
for _, valid := range difc.ValidModes {
if mode == valid {
return true
}
}
return false
}

// getDefaultConfigExtensions returns the default config extensions setting,
// checking MCP_GATEWAY_CONFIG_EXTENSIONS environment variable first
func getDefaultConfigExtensions() bool {
return envutil.GetEnvBool("MCP_GATEWAY_CONFIG_EXTENSIONS", defaultConfigExtensions)
}

// getDefaultSessionSecrecy returns the default session secrecy labels from
// MCP_GATEWAY_SESSION_SECRECY environment variable
func getDefaultSessionSecrecy() string {
return os.Getenv("MCP_GATEWAY_SESSION_SECRECY")
}

// getDefaultSessionIntegrity returns the default session integrity labels from
// MCP_GATEWAY_SESSION_INTEGRITY environment variable
func getDefaultSessionIntegrity() string {
return os.Getenv("MCP_GATEWAY_SESSION_INTEGRITY")
}

func getDefaultDIFCSinkServerIDs() string {
return os.Getenv("MCP_GATEWAY_DIFC_SINK_SERVER_IDS")
}

func getDefaultGuardPolicyJSON() string {
return os.Getenv("MCP_GATEWAY_GUARD_POLICY_JSON")
}

func getDefaultAllowOnlyScopePublic() bool {
return envutil.GetEnvBool("MCP_GATEWAY_ALLOWONLY_SCOPE_PUBLIC", false)
}

func getDefaultAllowOnlyScopeOwner() string {
return os.Getenv("MCP_GATEWAY_ALLOWONLY_SCOPE_OWNER")
}

func getDefaultAllowOnlyScopeRepo() string {
return os.Getenv("MCP_GATEWAY_ALLOWONLY_SCOPE_REPO")
}

func getDefaultAllowOnlyMinIntegrity() string {
return os.Getenv("MCP_GATEWAY_ALLOWONLY_MIN_INTEGRITY")
}

func buildAllowOnlyPolicy(public bool, owner, repo, minIntegrity string) (*config.GuardPolicy, error) {
owner = strings.TrimSpace(owner)
repo = strings.TrimSpace(repo)
integrityInput := strings.TrimSpace(minIntegrity)
integrityKey := strings.ToLower(strings.ReplaceAll(integrityInput, "-", ""))

integrityByInput := map[string]string{
"none": config.IntegrityNone,
"unapproved": config.IntegrityUnapproved,
"approved": config.IntegrityApproved,
"merged": config.IntegrityMerged,
}
integrity, hasIntegrity := integrityByInput[integrityKey]

scopeCount := 0
if public {
scopeCount++
}
if owner != "" {
scopeCount++
}
if repo != "" && owner == "" {
return nil, fmt.Errorf("allowonly scope repo requires allowonly scope owner")
}

if scopeCount == 0 && minIntegrity == "" {
return nil, nil
}
if scopeCount != 1 {
return nil, fmt.Errorf("exactly one AllowOnly scope variant must be set (public or owner[/repo])")
}
if integrityInput == "" {
return nil, fmt.Errorf("allowonly integrity is required")
}
if !hasIntegrity {
return nil, fmt.Errorf("allowonly integrity must be one of: none, unapproved, approved, merged")
}

var repos interface{}
if public {
repos = "public"
} else {
scope := owner + "/*"
if repo != "" {
scope = owner + "/" + repo
}
repos = []string{scope}
}

policy := &config.GuardPolicy{
AllowOnly: &config.AllowOnlyPolicy{
Repos: repos,
MinIntegrity: integrity,
},
}

if err := config.ValidateGuardPolicy(policy); err != nil {
return nil, err
}

return policy, nil
}

// ValidateDIFCMode validates the DIFC mode flag value and returns an error if invalid
func ValidateDIFCMode(mode string) error {
if !isValidDIFCMode(strings.ToLower(mode)) {
return fmt.Errorf("invalid DIFC mode %q: must be one of: %s, %s, %s", mode, difc.ModeStrict, difc.ModeFilter, difc.ModePropagate)
}
return nil
}

// parseSessionLabels parses a comma-separated string of labels into a slice
func parseSessionLabels(labels string) []string {
if labels == "" {
return nil
}
parts := strings.Split(labels, ",")
result := make([]string, 0, len(parts))
for _, part := range parts {
trimmed := strings.TrimSpace(part)
if trimmed != "" {
result = append(result, trimmed)
}
}
return result
}

func parseDIFCSinkServerIDs(input string) ([]string, error) {
if strings.TrimSpace(input) == "" {
return nil, nil
}

parts := strings.Split(input, ",")
result := make([]string, 0, len(parts))
seen := make(map[string]struct{}, len(parts))

for _, part := range parts {
value := strings.TrimSpace(part)
if value == "" {
continue
}
if strings.ContainsAny(value, " \t\n\r") {
return nil, fmt.Errorf("invalid DIFC sink server ID %q: whitespace is not allowed", value)
}
if _, exists := seen[value]; exists {
continue
}
seen[value] = struct{}{}
result = append(result, value)
}

return result, nil
}
Loading
Loading