GitHub Copilot CLI 的访问权限配置
介绍 Copilot CLI 如何通过可信目录、工具许可、路径与 URL 权限控制其可访问范围,并说明默认行为与放宽全部限制的选项,以及关闭客户端遥测的启动参数。
## [导言](<https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/configure-copilot-cli#introduction>) 副驾驶CLI有几种配置选项,可以控制它能代表您访问和做什么. 文章显示您如何设置可信任的目录, 配置工具访问权限, 授予文件路径和 URL 权限, 并禁用客户端远程测量 。 ### [先决条件](<https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/configure-copilot-cli#prerequisites>) - 安装副驾驶 CLI。见 [安装 GitHub 副驾驶 CLI](<https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/install-copilot-cli>). ## [设置可信任的目录](<https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/configure-copilot-cli#setting-trusted-directories>) 可信任目录控制, Copilot CLI 可以读取、修改和执行文件。 信任目录有安全意义, 参见 [安全考虑](<https://docs.github.com/en/copilot/concepts/copilot-surfaces/copilot-cli#security-considerations>). ### [选择信任目录](<https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/configure-copilot-cli#choosing-to-trust-a-directory>) 当您启动一个 GitHub 副驾驶 CLI 会话时, 请您确认您信任您从中启动的 CLI 的目录中和下面的文件 。 您可以选择信任当前目录 : - 仅当前运行的会话 - B. 本届会议和今后各届会议 如果您选择信任未来会话的目录, 信任的目录提示将不会再次被显示。 您只应该选择第二个选项, 如果您确信此位置将永远成为 Copilot 操作的安全位置 。 ### [编辑信任的目录](<https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/configure-copilot-cli#editing-trusted-directories>) 您可以编辑永久信任的目录列表。 信任的目录存储在自动管理的目录中 `config.json` 文档。 1. 打开 CLI 的 `config.json` 文件。默认情况下,它被存储在 `.copilot` 您主目录下的文件夹 : - **macOS/Linux**: `~/.copilot/config.json` - **窗口**: `$HOME\.copilot\config.json` 您可以通过设置 `COPILOT_HOME` 环境变量。这将改变 `~/.copilot/` 财务报告和财务报告 `$HOME\.copilot\` 在上述路径中。 1. 编辑该条目的内容 `trustedFolders` 数组。 ## [设置允许的工具](<https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/configure-copilot-cli#setting-allowed-tools>) 您可以控制哪些工具 Copilot CLI 可以使用, 要么在 Copilot 尝试使用工具时响应批准提示, 要么通过命令行选项指定权限 。 注意允许工具访问对安全有影响,见: [安全考虑](<https://docs.github.com/en/copilot/concepts/copilot-surfaces/copilot-cli#security-considerations>). 本节中,您可学习: - [首次允许工具](<https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/configure-copilot-cli#allowing-a-tool-for-the-first-time>) - [允许不经手动批准而使用工具](<https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/configure-copilot-cli#allowing-tools-to-be-used-without-manual-approval>) - [指定要允许或拒绝哪个工具](<https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/configure-copilot-cli#specifying-which-tool-you-want-to-allow-or-deny>) - [允许一些工具同时否认其他工具](<https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/configure-copilot-cli#allowing-some-tools-while-denying-others>) - [限制可用的工具](<https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/configure-copilot-cli#limiting-available-tools>) ### [首次允许工具](<https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/configure-copilot-cli#allowing-a-tool-for-the-first-time>) 在手动批准模式下, Copilot 要求您批准那些已经不允许的工具请求—— 例如, `touch`, `chmod`, `node`,或 `sed`。是否被激励,取决于有效的权限以及工具是如何使用的,比如它的参数或以前的批准. 1. 通过运行启动交互式会话 `copilot`,然后输入 `/permissions manual`. 2. 提示副驾驶执行需要工具的任务。 例如 : ```copilot Create a new file called README.md with a project description ``` 3. 如果该工具尚未被允许,请从可用的批准选项中选择: - `Yes` 选择此选项允许 Copilot 运行此特定命令, 仅此一次。 下次需要使用此工具时, 它会再次询问您 。 - `Yes, and don't ask again ...` 选择此选项可以允许指定命令、 MCP 工具, 或在当前寄存器或目录中文件操作, 无需再次询问, 包括在未来的会话中。 根据请求, 您可能会看到为运行会话的其余部分批准该工具的选项 。 例如,如果副驾驶要求您允许它运行命令 `rm ./this-file.txt`,而你同意 `rm` 对于寄存器,然后Copilot 可以运行任意 `rm` 命令(例如, `rm -rf ./*`在那个仓库里工作的时候 不需要你批准 - `No, and tell Copilot what to do differently (Esc)` 选择此选项可取消拟议命令, 并指示 Copilot 尝试不同的方法 。 ### [允许不经手动批准使用工具](<https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/configure-copilot-cli#allowing-tools-to-be-used-without-manual-approval>) 您可以使用命令行选项来指定Copilot无需征求您的批准即可使用的工具. 或者,在不给予毛毯许可的情况下减少批准提示,请输入 `/permissions assisted` 使用辅助权限,一个大型语言模型会评估符合资格的许可请求,并自动批准它判断的安全性。现有权限和企业规则仍然适用,仍然需要你批准的请求会提交您。更多信息,请参见: [允许安全命令在未经手动批准的情况下运行](<https://docs.github.com/en/copilot/concepts/customizations/allowing-safe-commands>). #### [允许所有工具](<https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/configure-copilot-cli#allowing-all-tools>) 使用该 `--allow-all-tools` 允许副驾驶使用任何工具而无需征求您的同意。 - 例如: ```shell copilot -p "Revert the last commit" --allow-all-tools ``` #### [拒绝工具](<https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/configure-copilot-cli#denying-a-tool>) 使用( U) `--deny-tool` 防止副驾驶使用特定工具。 - 例如: ```shell copilot --deny-tool='shell(git push)' ``` 此选项优先于 `--allow-all-tools` 财务报告和财务报告 `--allow-tool` 选项。 #### [允许工具](<https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/configure-copilot-cli#allowing-a-tool>) 使用( U) `--allow-tool` 允许副驾驶使用特定工具而不征求您的同意。 - 例如: ```shell copilot --allow-tool='shell' ``` ### [指定要允许或拒绝哪个工具](<https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/configure-copilot-cli#specifying-which-tool-you-want-to-allow-or-deny>) 用来使用 `--deny-tool` 财务报告和财务报告 `--allow-tool` 选项,您必须指定要允许或拒绝何种类型的工具: - [贝壳命令](<https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/configure-copilot-cli#allowing-or-denying-shell-commands>) - [“ 写入” 工具](<https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/configure-copilot-cli#allowing-or-denying-write-tools>) - [MCP 服务器工具](<https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/configure-copilot-cli#allowing-or-denying-mcp-server-tools>) #### [允许或拒绝 shell 命令](<https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/configure-copilot-cli#allowing-or-denying-shell-commands>) 使用( U) `shell(COMMAND)` 允许或拒绝特定 shell 命令。 - 例如,防止副驾驶使用任何 `rm` 命令,使用: ```shell copilot --deny-tool='shell(rm)' ``` 为: `git` 财务报告和财务报告 `gh` 命令,指定允许或拒绝的首级子命令。 - 例如,防止副驾驶使用 `git push`,使用: ```shell copilot --deny-tool='shell(git push)' ``` 工具规格是可选的。例如, `copilot --allow-tool='shell'` 允许副驾驶不经个人批准而使用任何 shell 命令. #### [允许或拒绝 `'write'` 工具](<https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/configure-copilot-cli#allowing-or-denying-write-tools>) 使用( U) `'write'` 允许或拒绝修改文件的工具——除了 shell 命令。 - 例如,为了允许Copilot不经您个人批准编辑文件,请使用: ```shell copilot --allow-tool='write' ``` #### [允许或拒绝 MCP 服务器工具](<https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/configure-copilot-cli#allowing-or-denying-mcp-server-tools>) 使用( U) `'MCP_SERVER_NAME(TOOL_NAME)'` 允许或拒绝指定 MCP 服务器提供特定工具。 - 例如,防止副驾驶使用所谓的工具 `tool_name` 从 MCP 服务器调用 `My-MCP-Server`,使用: ```shell copilot --deny-tool='My-MCP-Server(tool_name)' ``` `MCP_SERVER_NAME` 是您配置的 MCP 服务器的名称 。 来自服务器的工具在括号中指定,使用在MCP服务器注册的工具名称. 使用服务器名称而不指定工具则允许或否认该服务器的所有工具. 您可以通过输入找到 MCP 服务器的名称 `/mcp` 在“副驾驶CLI”的互动模式中,从显示的列表中选择服务器。 ### [允许一些工具,同时否认其他工具](<https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/configure-copilot-cli#allowing-some-tools-while-denying-others>) 要准确确定哪些工具是副驾驶可以使用而不征求您的批准,您可以使用多种批准选项。例如: - 防止副驾驶使用 `rm` 财务报告和财务报告 `git push` 命令,但自动允许所有其他工具,使用: ```shell copilot --allow-all-tools --deny-tool='shell(rm)' --deny-tool='shell(git push)' ``` - 防止副驾驶使用工具 `tool_name` 来自命名为 MCP 的服务器 `My-MCP-Server`,但允许该服务器的所有其他工具不经个人批准而使用,使用: ```shell copilot --allow-tool='My-MCP-Server' --deny-tool='My-MCP-Server(tool_name)' ``` ### [限制可用工具](<https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/configure-copilot-cli#limiting-available-tools>) 将“副驾驶”限制在一组特定工具上,使用 `--available-tools`. 未列入本列表的工具将无法提供给副驾驶. ## [设置路径权限](<https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/configure-copilot-cli#setting-path-permissions>) 路径权限控制目录和文件可访问 。 默认情况下,副驾驶CLI可以访问当前的工作目录,其子目录,以及系统临时目录. 路径权限适用于 shell 命令、文件操作( 创建、 编辑、 查看) 和搜索工具( 如 `grep` 对于 shell 命令,路径通过标注命令文本和识别类似路径的符号来快速提取 。 3⁄4 ̄ ̧漯B 对 shell 命令的路径检测有限制 : - 嵌入于复杂 shell 构造中的路径可能无法检测到. - 只有一组具体的环境变量得到扩展(`HOME`, `TMPDIR`, `PWD`类似)。自定义变量,如 `$MY_PROJECT_DIR` 未扩展,且可能无法正确验证。 - 已存在文件的Symlink已解决,但正在创建的文件则不解决. ### [允许访问所有路径](<https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/configure-copilot-cli#allowing-access-to-all-paths>) 要禁用路径校验并允许访问任何路径,请使用 `--allow-all-paths` 选项,用于启动 CLI 副驾驶。 ### [取消对临时目录的访问](<https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/configure-copilot-cli#disallowing-access-to-the-temp-directory>) 不允许访问临时目录, 使用 `--disallow-temp-dir`. ## [设置 URL 权限](<https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/configure-copilot-cli#setting-url-permissions>) URL 权限控制外部的 URL 由 Copilot 访问。 默认情况下, 所有 URL 都需要批准才能获准访问 。 URL 权限适用于 `web_fetch` 工具以及访问网络的 shell 命令目录(例如 `curl`, `wget`,以及 `fetch`。对于 shell 命令, URL 使用 regex 模式进行提取。 3⁄4 ̄ ̧漯B 用于 shell 命令的 URL 检测有限制 : - 文件内容中的 URL, 配置文件, 或命令读取的环境变量不被检测到. - 模糊的URL(如分割字符串或逃逸序列)可能无法被检测到. - HTTP和HTTPS作为不同的协议处理,需要单独的批准. URL权限可以持续用于会话或永久使用. ### [禁用 URL 验证](<https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/configure-copilot-cli#disabling-url-verification>) 要禁用 URL 校验,请使用 `--allow-all-urls` 选项。 ### [预先核准的具体领域](<https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/configure-copilot-cli#pre-approving-specific-domains>) 要预先批准特定域,请使用 `--allow-url=DOMAIN`. - 举例来说, `--allow-url=github.com`. ### [拒绝特定域](<https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/configure-copilot-cli#denying-specific-domains>) 拒绝特定域, 使用 `--deny-url=DOMAIN`. - 举例来说, `--deny-url=github.com`. ## [允许所有工具、路径和 URL](<https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/configure-copilot-cli#allowing-all-tools-paths-and-urls>) 允许所有工具、路径和 URL, 使用 `--allow-all`,或其别名, `--yolo`. 此选项结合 : - `--allow-all-tools` (skip工具批准). - `--allow-all-paths` (障碍路径校验). - `--allow-all-urls` (残疾URL核查). 在交互式会话中,您也可以启用所有与 `/permissions allow-all` 斜线命令或其别名 `/allow-all` 财务报告和财务报告 `/yolo`. 说明 持有副驾驶业务或副驾驶企业执照的,这些命令可能被企业管理人屏蔽. ## [限制对文件的访问](<https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/configure-copilot-cli#restrict-access-to-files>) 各种 `--allow-all...` 选项可以避免您不得不决定是否允许 Copilot 访问单个工具、文件和 URL。然而,使用这些工具、文件和 URL 将扩展 Copilot 执行您可能不希望它执行的行动的范围 — 例如,在您正在工作的数据库之外更改文件。 为了减轻这一风险,您可以指示 CLI 将它的命令(局部的沙盒)放入沙盒,也可以在云沙盒中运行整个副驾驶 CLI 会话。更多信息,请参见 [关于用于 GitHub 的本地沙箱](<https://docs.github.com/en/copilot/concepts/security-governance-and-network-settings/about-cloud-and-local-sandboxes>) 财务报告和财务报告 [关于用于 GitHub 的云沙盒](<https://docs.github.com/en/copilot/concepts/security-governance-and-network-settings/about-cloud-sandboxes>). ## [禁用客户端遥测](<https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/configure-copilot-cli#disabling-client-side-telemetry>) 要禁用当前引用的第一当事方客户端遥测, 请使用 CLI 启动 。 `--disable-client-telemetry` 选项 : ```shell copilot --disable-client-telemetry ``` 此选项会禁用由 CLI 发送的首方遥测, 包括不受限制和受限制的遥测。 它不会保存在您的配置中 。 此选项不会禁用 GitHub 的服务器侧会话数据采集或遥测。 也不影响 : - 由您或您的企业配置的 OpenTelemetry 导出 。 - 遥测发送到一个使用Copilot SDK的应用程序,当该应用程序在连接到CLI时,明确允许遥测转发. ## [进一步阅读](<https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/configure-copilot-cli#further-reading>) - [自定义 GitHub 副驾驶 CLI](<https://docs.github.com/en/copilot/how-tos/copilot-cli/customize-copilot>) - [GitHub 副驾驶 CLI 配置目录](<https://docs.github.com/en/copilot/reference/copilot-cli-reference/cli-config-dir-reference>)
查看原始来源