Skip to content

fix: pass MCP GitHub token via env, not argv - #4189

Open
anjalirj27 wants to merge 1 commit into
knative:mainfrom
anjalirj27:fix/mcp-gh-token-env
Open

anjalirj27 wants to merge 1 commit into
knative:mainfrom
anjalirj27:fix/mcp-gh-token-env

Conversation

@anjalirj27

Copy link
Copy Markdown

Changes

  • 🐛 The MCP config_git_set tool now passes the GitHub access token to the func subprocess as the FUNC_GH_ACCESS_TOKEN environment variable instead of --gh-access-token <token>, so it no longer shows in the process list.

/kind bug

Fixes #4188

Why: a process's command line is readable by any local user (ps, /proc/<pid>/cmdline). The CLI already reads every flag from a FUNC_-prefixed environment variable, so no CLI change is needed. A process's environment is only readable by the same user and root.

What changed:

  • pkg/mcp/mcp.go: new ExecuteEnv on the executor, which adds environment variables to the inherited environment.
  • pkg/mcp/tools_config_git.go: the token is no longer added to the arguments; a new Env() sets FUNC_GH_ACCESS_TOKEN only when a token is given.
  • pkg/mcp/mock/executor.go: mock gains ExecuteEnv, falling back to ExecuteFn so existing tests are unchanged.

Testing:

  • New regression test TestTool_ConfigGitSet_TokenViaEnv: fails on the current code, passes with the fix.
  • TestTool_ConfigGitSet_NoTokenNoEnv: no variable is set when no token is given.
  • TestDefaultExecutor_ExecuteEnv: the variable reaches a real subprocess alongside the inherited environment.
  • go test -race ./pkg/mcp/... and make check pass.

Release Note

The MCP config_git_set tool no longer exposes the GitHub access token in the process list.

Docs


The MCP config_git_set tool passed the GitHub access token to the func subprocess as --gh-access-token <token>. A process's command line is readable by any local user (ps, /proc/<pid>/cmdline), so the token was exposed for as long as the subprocess ran.

The CLI already reads every flag from a FUNC_-prefixed environment variable, so the tool now sets FUNC_GH_ACCESS_TOKEN in the subprocess's environment instead, which only the same user and root can read. When no token is given nothing is set, so a value already exported in the server's environment still applies.

To support this the executor gains ExecuteEnv, which adds environment variables to the subprocess. Tests cover that the token never appears in the arguments, that no variable is set without a token, and that the variables reach a real subprocess.

Issue knative#4188
@knative-prow knative-prow Bot added the kind/bug Bugs label Nov 23, 2026
@knative-prow

knative-prow Bot commented Nov 23, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: anjalirj27
Once this PR has been reviewed and has the lgtm label, please assign dsimansk for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@linux-foundation-easycla

linux-foundation-easycla Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: anjalirj27 / name: Anjali (a09f95e)

@knative-prow

knative-prow Bot commented Nov 23, 2026

Copy link
Copy Markdown

Welcome @anjalirj27! It looks like this is your first PR to knative/func 🎉

@knative-prow knative-prow Bot added size/L 🤖 PR changes 100-499 lines, ignoring generated files. needs-ok-to-test 🤖 Needs an org member to approve testing labels Nov 23, 2026
@knative-prow

knative-prow Bot commented Nov 23, 2026

Copy link
Copy Markdown

Hi @anjalirj27. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Bugs needs-ok-to-test 🤖 Needs an org member to approve testing size/L 🤖 PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP config_git_set exposes the GitHub token on the func subprocess command line

1 participant