Repository navigation
Centralize environment variable resolution - #16830
Conversation
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🟡 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.LookupEnvto 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)
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
🔒 mcpg Read-Only Stress — defaultSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Overall: INCONCLUSIVE ( No write of any kind (reaction, star, issue, comment, branch, file, PR, or GraphQL mutation) succeeded or leaked through on either surface.
|

Environment reads across
internal/bypassedenvutil, 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.envutil.LookupEnvto preserve the distinction between an unset variable and one set to an empty value; migrate eligible environment reads toenvutil.oidc.RequestCredentialsFromEnv, shared by config validation and launcher setup.