|
| 1 | +# Best Practices |
| 2 | + |
| 3 | +This guide provides best practices for using the Gemini CLI GitHub Action, with a focus on repository security and operational excellence. |
| 4 | + |
| 5 | +- [Best Practices](#best-practices) |
| 6 | + - [Repository Security](#repository-security) |
| 7 | + - [Branch and Tag Protection](#branch-and-tag-protection) |
| 8 | + - [Restrict PR Approvers](#restrict-pr-approvers) |
| 9 | + - [Workflow Configuration](#workflow-configuration) |
| 10 | + - [Use Workload Identity Federation](#use-workload-identity-federation) |
| 11 | + - [Use Secrets for Sensitive Data](#use-secrets-for-sensitive-data) |
| 12 | + - [Pin Action Versions](#pin-action-versions) |
| 13 | + - [Creating Custom Workflows](#creating-custom-workflows) |
| 14 | + - [Monitoring and Auditing](#monitoring-and-auditing) |
| 15 | + |
| 16 | +## Repository Security |
| 17 | + |
| 18 | +A secure repository is the foundation for any reliable and safe automation. We strongly recommend implementing the following security measures. |
| 19 | + |
| 20 | +### Branch and Tag Protection |
| 21 | + |
| 22 | +Protecting your branches and tags is critical to preventing unauthorized changes. You can use [repository rulesets] to configure protection for your branches and tags. |
| 23 | + |
| 24 | +We recommend the following at a minimum for your `main` branch: |
| 25 | + |
| 26 | +* **Require a pull request before merging** |
| 27 | +* **Require a minimum number of approvals** |
| 28 | +* **Dismiss stale approvals** |
| 29 | +* **Require status checks to pass before merging** |
| 30 | + |
| 31 | +For more information, see the GitHub documentation on [managing branch protections]. |
| 32 | + |
| 33 | +### Restrict PR Approvers |
| 34 | + |
| 35 | +To prevent fraudulent or accidental approvals, you can restrict who can approve pull requests. |
| 36 | + |
| 37 | +* **CODEOWNERS**: Use a [`CODEOWNERS` file] to define individuals or teams that are responsible for code in your repository. |
| 38 | +* **Code review limits**: [Limit code review approvals] to specific users or teams. |
| 39 | + |
| 40 | +## Workflow Configuration |
| 41 | + |
| 42 | +### Use Workload Identity Federation |
| 43 | + |
| 44 | +For the most secure authentication to Google Cloud, we recommend using [Workload Identity Federation]. This keyless authentication method eliminates the need to manage long-lived service account keys. |
| 45 | + |
| 46 | +For detailed instructions on how to set up Workload Identity Federation, please refer to our [**Authentication documentation**](./authentication.md). |
| 47 | + |
| 48 | +### Use Secrets for Sensitive Data |
| 49 | + |
| 50 | +Never hardcode secrets (e.g., API keys, tokens) in your workflows. Use [GitHub Secrets] to store sensitive information. |
| 51 | + |
| 52 | +### Pin Action Versions |
| 53 | + |
| 54 | +To ensure the stability and security of your workflows, pin the Gemini CLI action to a specific version. |
| 55 | + |
| 56 | +```yaml |
| 57 | +uses: google-github-actions/run-gemini-cli@v0 |
| 58 | +``` |
| 59 | +
|
| 60 | +## Creating Custom Workflows |
| 61 | +
|
| 62 | +When creating your own workflows, we recommend starting with the [examples provided in this repository](../examples/workflows/). These examples demonstrate how to use the `run-gemini-cli` action for various use cases, such as pull request reviews, issue triage, and more. |
| 63 | + |
| 64 | +Ensure the new workflows you create follow the principle of least privilege. Only grant the permissions necessary to perform the required tasks. |
| 65 | + |
| 66 | +## Monitoring and Auditing |
| 67 | + |
| 68 | +To gain deeper insights into the performance and behavior of Gemini CLI, you can enable OpenTelemetry to send traces, metrics, and logs to your Google Cloud project. This is highly recommended for production environments to monitor for unexpected behavior and performance issues. |
| 69 | + |
| 70 | +For detailed instructions on how to set up and configure observability, please refer to our [**Observability documentation**](./observability.md). |
| 71 | + |
| 72 | +[repository rulesets]: https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-rulesets/about-rulesets |
| 73 | +[managing branch protections]: https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-protected-branches/about-protected-branches |
| 74 | +[`codeowners` file]: https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners |
| 75 | +[limit code review approvals]: https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/managing-repository-settings/managing-pull-request-reviews-in-your-repository#enabling-code-review-limits |
| 76 | +[github secrets]: https://docs.github.com/en/actions/security-guides/encrypted-secrets |
| 77 | +[Workload Identity Federation]: https://cloud.google.com/iam/docs/workload-identity-federation |
0 commit comments