Skip to content

Centralize environment variable resolution - #16830

Merged
lpcox merged 3 commits into
mainfrom
copilot/refactor-semantic-function-clustering
Nov 20, 2026
Merged

lpcox merged 3 commits into
mainfrom
copilot/refactor-semantic-function-clustering

Conversation

@lpcox

@lpcox lpcox commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Environment reads across internal/ bypassed envutil, and guards-mode and GitHub Actions OIDC settings were resolved in multiple places. This change routes eligible reads through shared accessors and consolidates those two resolution paths.

  • Shared accessors: Add envutil.LookupEnv to preserve the distinction between an unset variable and one set to an empty value; migrate eligible environment reads to envutil.
  • Unified settings: Resolve guards mode once in DIFC and reuse that result for CLI overrides. Read OIDC URL and token through oidc.RequestCredentialsFromEnv, shared by config validation and launcher setup.
value, present := envutil.LookupEnv(key)
if present {
    // An explicitly empty value remains distinguishable from an unset variable.
}

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
@lpcox lpcox changed the title [WIP] Refactor environment variable handling in Go files Centralize environment variable resolution Nov 19, 2026
@lpcox
lpcox marked this pull request as ready for review November 19, 2026 22:45
Copilot AI adaptive review requested due to automatic review settings November 19, 2026 22:45
@github-actions

This comment has been minimized.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The test unsets MCP_GATEWAY_GUARDS_MODE without restoring its original value, potentially altering the environment seen by later tests.

1 open issue
What changed in this PR

Centralizes environment-variable access across MCP Gateway’s internal packages and shares guards-mode and GitHub Actions OIDC resolution.

Changes:

  • Add envutil.LookupEnv to distinguish unset variables from explicitly empty values, and migrate eligible reads.
  • Reuse DIFC mode resolution for CLI overrides while preserving explicit flag precedence.
  • Share OIDC credential lookup between validation and launcher setup, with focused helper tests.
File Description
internal/​tracing/​config_resolver.go Use shared accessors for tracing settings.
internal/​sys/​docker.go Read Docker host through envutil.
internal/​sys/​container.go Use shared access for container detection.
internal/​oidc/​provider.go Add shared OIDC request-credential resolution.
internal/​oidc/​provider_test.go Test credential lookup from the environment.
internal/​launcher/​mount_policy.go Read workspace through envutil.
internal/​launcher/​launcher.go Initialize OIDC using shared credential resolution.
internal/​guard/​wasm_discovery.go Centralize reads while preserving explicit-empty opt-out.
internal/​githubhttp/​visibility.go Use shared workflow-repository lookup.
internal/​envutil/​github.go Route GitHub settings through shared accessors.
internal/​envutil/​expand_env_args.go Use LookupEnv for Docker environment arguments.
internal/​envutil/​envutil.go Add presence-preserving lookup and reuse it internally.
internal/​envutil/​envutil_test.go Cover unset, empty, and populated values.
internal/​difc/​evaluator.go Centralize enforcement-mode resolution and presence detection.
internal/​difc/​evaluator_test.go Test mode normalization, fallback, and presence.
internal/​config/​validation_server.go Reuse OIDC lookup during validation.
internal/​config/​validation_env.go Centralize environment-validation reads.
internal/​config/​expand.go Use presence-preserving lookup and update explanatory comments.
internal/​cmd/​wasm_cache.go Preserve cache-setting presence through shared lookup.
internal/​cmd/​root.go Reuse mode resolution and shared environment accessors.
internal/​cmd/​proxy.go Centralize delegation and enclave environment reads.

Review effort: Max (adaptive)

Comment thread internal/difc/evaluator_test.go Resolved
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

🔒 mcpg Read-Only Stress — default

Surface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Isolation runtime: default

Part Surface Op Result Expected Status
A MCP reads data (4/4) ALLOWED ✅
B MCP writes (reaction/star/issue/comment/branch/file/PR) all 6 targets absent from catalog (23 read-only tools only) BLOCKED ⚠️
C CLI reads data ALLOWED ✅
D CLI REST writes gh CLI unauthenticated (no GH_TOKEN) BLOCKED ⚠️
E CLI GraphQL mutations gh CLI unauthenticated BLOCKED ⚠️

Overall: INCONCLUSIVE

(⚠️ = INCONCLUSIVE — no write leaked in any part. Part B: the 6 write tools (add_issue_comment, star_repository, issue_write, create_branch, create_or_update_file, create_pull_request) were absent from the exposed github CLI catalog entirely, so refusal only confirms backend GITHUB_READ_ONLY=1 config, not an independent gateway-level DIFC check. Part D/E: gh auth status showed no authenticated host and GH_TOKEN was not set, so the token-scope boundary could not be exercised this run.)

No write of any kind (reaction, star, issue, comment, branch, file, PR, or GraphQL mutation) succeeded or leaked through on either surface.

🔒 mcpg read-only stress (default AWF runtime) by Read-Only Stress: default runtime

@lpcox
lpcox merged commit a88e1a2 into main Nov 20, 2026
30 checks passed
@lpcox
lpcox deleted the copilot/refactor-semantic-function-clustering branch November 20, 2026 00:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[refactor] Semantic function clustering: env reads bypass envutil, and guards-mode and OIDC env handling is duplicated

3 participants