Repository navigation
fix: pass MCP GitHub token via env, not argv - #4189
anjalirj27 wants to merge 1 commit into
Conversation
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
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: anjalirj27 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
|
|
Welcome @anjalirj27! It looks like this is your first PR to knative/func 🎉 |
|
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 Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions 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. |
Changes
config_git_settool now passes the GitHub access token to thefuncsubprocess as theFUNC_GH_ACCESS_TOKENenvironment 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 aFUNC_-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: newExecuteEnvon 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 newEnv()setsFUNC_GH_ACCESS_TOKENonly when a token is given.pkg/mcp/mock/executor.go: mock gainsExecuteEnv, falling back toExecuteFnso existing tests are unchanged.Testing:
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/...andmake checkpass.Release Note
Docs