|
| 1 | +# Gemini-CLI Specific GitHub Actions (GHA) Trust Guidance |
| 2 | + |
| 3 | +This guide outlines essential security configurations and best practices for integrating the Gemini CLI with your GitHub Actions (GHA) workflows. Version `0.39.1` introduces security controls for Gemini CLI in headless mode. When running Gemini CLI in CI, like GitHub Actions, you must determine if your CI workflow operates on trusted or untrusted data. If your workflow operates exclusively on trusted data, e.g., code or prompts from repo owners, you can safely set `GEMINI_TRUST_WORKSPACE=true`. If your workflow operates on untrusted data, follow the guidance below, and set the environment variable after hardening your workflow. |
| 4 | + |
| 5 | +**1\. Determine if your workflow processes untrusted data** |
| 6 | + |
| 7 | +The required security configuration for your workflow depends on the origin of the data it processes: |
| 8 | + |
| 9 | +| Data Trust Level | Required Configuration & Action | |
| 10 | +| ------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | |
| 11 | +| **Fully Trusted Data** e.g. any inputs from high-trust collaborators. | Set `GEMINI_TRUST_WORKSPACE=true` in your workflow. | |
| 12 | +| **Untrusted Data** e.g. GitHub issues or pull requests submitted by non-collaborators | Follow the guidelines below to harden your workflow, and then set the environment variable. | |
| 13 | + |
| 14 | +**2\. Permissions and Principle of Least Privilege** |
| 15 | + |
| 16 | +Follow these principles to protect your repository, especially when dealing with untrusted input: |
| 17 | + |
| 18 | +- **Exercise Least Privilege:** Explicitly exercise the principle of least privilege. Grant only the minimum privileges necessary for the workflow to complete its task. |
| 19 | +- **GitHub Token Permissions:** Set a **minimal set of GH token permissions** for your GitHub token (e.g., `issues: read`). Be aware that even token permissions that may be considered "downscoped" can still pose a security risk (e.g. `actions: write`). See GitHub’s [Modifying Github Tokens for Least Privilege](https://docs.github.com/en/actions/tutorials/authenticate-with-github_token#modifying-the-permissions-for-the-github_token) |
| 20 | +- **Limit credential permissions** as much as possible to limit the risk if they are stolen. (See GitHub’s [Limiting credential permissions](https://docs.github.com/en/actions/concepts/security/secrets#limiting-credential-permissions)) |
| 21 | +- **Workflow Triggering:** Prefer workflows where the **PR review is kicked off intentionally by a maintainer** (manually triggered workflows) and not on forks, to avoid automatically processing untrusted content. |
| 22 | + |
| 23 | +See [Best Practices](./best-practices.md) and GitHub’s [GHA Best Practices for Security](https://docs.github.com/en/actions/reference/security/secure-use) |
| 24 | + |
| 25 | +**3\. Tool and Command Allow Listing** |
| 26 | + |
| 27 | +If you are processing **untrusted data**, you must strictly limit which tools the Gemini CLI is allowed to execute. |
| 28 | + |
| 29 | +- **Prefer a minimal set of tools** such as `list_directory`, `read_file`, and `grep_search`. |
| 30 | +- **Allowlist commands only if necessary** and take caution allowing commands with dangerous functionality. |
| 31 | + |
| 32 | +### Allow List Configuration Examples |
| 33 | + |
| 34 | +These examples demonstrate how to configure the tool allow list using the `settings_json` input in your GHA workflow. |
| 35 | + |
| 36 | +**Example A: Strict Allow List (Recommended for Untrusted Data)** |
| 37 | + |
| 38 | +This configuration allows only the core native tools necessary for reading and searching files. |
| 39 | + |
| 40 | +``` |
| 41 | +with: |
| 42 | + settings_json: | |
| 43 | + { |
| 44 | + "coreTools": [ |
| 45 | + "read_file", |
| 46 | + "grep_search" |
| 47 | + ], |
| 48 | + "sandbox": false |
| 49 | + } |
| 50 | +``` |
| 51 | + |
| 52 | +| Tool Category | Tool/Command | Rationale | |
| 53 | +| :--------------: | :-----------: | :------------------------------------------: | |
| 54 | +| **Native Tools** | `read_file` | Recommended tool for reading content. | |
| 55 | +| **Native Tools** | `grep_search` | Recommended tool for file pattern searching. | |
| 56 | + |
| 57 | +**Example B: Including Minimal Shell Commands (If Necessary)** |
| 58 | + |
| 59 | +If your workflow requires a very simple shell command that cannot be replaced by a native tool, you can add it using `run_shell_command()`. |
| 60 | + |
| 61 | +``` |
| 62 | +with: |
| 63 | + settings_json: | |
| 64 | + { |
| 65 | + "coreTools": [ |
| 66 | + "read_file", |
| 67 | + "grep_search", |
| 68 | + "run_shell_command(echo)" |
| 69 | + ], |
| 70 | + "sandbox": false |
| 71 | + } |
| 72 | +``` |
| 73 | + |
| 74 | +**Important Note on Legacy Examples:** If you are using older workflow examples (such as the PR review workflow), they may currently use the unsafe `run_shell_command` for commands that are now available as safer native tools. You should update these examples to replace all instances of `run_shell_command` with the CLI's safer built-in tools wherever possible. |
0 commit comments