gh-secure README

The project's README from github.com/GitHubSecurityLab/gh-secure. As one markdown file: README.md.

gh-secure

Protect your project in 2 minutes

A GitHub CLI extension to enable security features on public repositories, following best practices from the GitHub Security Lab.

Everything we'll cover is free for open source

No security or coding skills needed

Only an open source project on GitHub where you have admin access.

How do I use it?

Running the tool will enable security features for your repository in 2 minutes or less.

You can use it from your terminal, with an interactive mode or a "just do it" mode.

gh-secure CLI demo

You can also use it from the GitHub Copilot CLI or the GitHub Copilot App, or any other AI assistant who has access to the tool. Ask for an overview of your repository's security, ask for details on specific features, and ask the tool to enable the missing features for you.

gh-secure Copilot App demo

Installation

gh extension install GitHubSecurityLab/gh-secure

Prerequisites

Usage

gh secure                                  # Interactive mode, all features
gh secure --yes                            # Enable all features, no prompts
gh secure branch-protection dependabot     # Enable only these two features
gh secure bp ss cs -y                      # Enable 3 features, no prompts
gh secure --repo owner/repo code-scanning  # Enable CodeQL on specific repo
gh secure --yes --dry-run                  # Preview what would be enabled
gh secure status                           # Check current feature status
gh secure status --repo owner/repo         # Check status of specific repo

Flags

Flag Description
-r, --repo <owner/repo> Target repository (default: current repo)
-y, --yes Enable selected features without prompting for confirmation
-n, --dry-run Simulate changes without applying them
-v, --version Print version
-h, --help Show help message

Feature Names

Pass one or more feature names to enable only specific features. If none are specified, all features are included.

Feature Shorthand
branch-protection bp
vulnerability-reporting vr
secret-scanning ss
dependabot dep
code-scanning cs

Security Features

This tool enables five security features based on GitHub Security Lab recommendations:

1. Branch Protection

Branch protection blocks unwanted changes to your project. Prevent accidental or malicious commits that may introduce vulnerabilities or disrupt the stability of your project. Branch rules give you flexible control over who can force push, delete, etc. If your repository already has active rulesets, gh secure will warn you before enabling legacy branch protection to avoid overlapping or conflicting rules. Documentation

2. Private Vulnerability Reporting

Security Policy and Private Vulnerability Reporting (PVR) create a safe path for reporting vulnerabilities before they go public. Make it easy for people external to the project, such as users and security researchers, to report security bugs privately. Documentation

3. Secret Scanning

Sensitive data like API keys, tokens, and passwords can accidentally be committed to your repository. Secret scanning with push protection guards over 300 token types and patterns from more than 180 service providers. Documentation

4. Dependabot

Dependabot keeps your dependencies safe effortlessly. Automatically checks your dependencies for known vulnerabilities and create pull requests to update them to safe versions. This saves you the hassle of manual checks and blocks threats. Documentation

5. Code Scanning (CodeQL)

GitHub code scanning automatically detects common security vulnerabilities in your project and in your pull requests. Resolve them manually or with the help of Copilot Autofix AI-powered suggestions, before they are exploited against you and your users. Documentation

Troubleshooting

"403 Forbidden" Errors

Ensure you have admin or maintain permissions on the repository. For org repos, you may need admin:org scope — run gh auth refresh -s admin:org.

Code Scanning Fails

Ensure the repository contains supported languages and that code scanning is available for your plan.

Branch Protection Fails

Some organizations have policies that restrict branch protection. Contact your org admin. If your repository uses rulesets, you may not need legacy branch protection at all — gh secure will detect active rulesets and prompt you before enabling it.

Resources

FAQ

What permissions do I need and why?

You need admin or maintain permissions on the target repository. This is because enabling security features (branch protection rules, code scanning, secret scanning, Dependabot, and vulnerability reporting) requires write access to repository settings. For organization repositories, you may also need the admin:org OAuth scope — run gh auth refresh -s admin:org to add it.

How do I authenticate?

gh-secure uses the GitHub CLI authentication. Run gh auth status to check your current session. If you are not authenticated, run gh auth login and follow the prompts. The tool inherits whatever token and scopes your gh session has.

What are the implications of these changes for my project?

Enabling these features adds protective guardrails but does not change your source code:

All of these settings can be reverted at any time from your repository settings, with no impact on the project.

Will my project be secure?

These features significantly raise the security baseline of your project, but no tool can guarantee complete security. They help you detect and prevent common issues — leaked secrets, known vulnerable dependencies, code-level vulnerabilities, and unauthorized changes — but security is an ongoing process. Regularly review alerts, keep dependencies up to date, and follow the GitHub Security Documentation for additional best practices.

License

This project is licensed under the terms of the MIT open source license. Please refer to the LICENSE file for the full terms.

Maintainers

See CODEOWNERS or reach out to the GitHub Security Lab team.

Support

See SUPPORT.md for details on how to get help with this project.

gh-secure (GitHubSecurityLab/gh-secure)

Searching Database…

这是什么?gh-secure 是一个 GitHub CLI 扩展,能在约 2 分钟内为仓库开启五项推荐的安全功能——分支保护、私密漏洞报告、密钥扫描、Dependabot 和代码扫描。
它是独立应用,还是别的东西的插件?它是一个 gh 扩展,因此以 GitHub CLI(gh)子命令的形式运行,而不是作为独立程序。
怎么安装和运行它?安装 GitHub CLI,用 gh auth login 完成认证,然后在你想加固的仓库中通过终端安装并运行该扩展(交互模式或非交互的 '-y' 模式)。
运行它之前需要什么?你需要安装并认证好 GitHub CLI(gh),并且对目标仓库拥有管理员或维护者权限;对于组织仓库,可能还需要 admin:org OAuth scope。
启用这些功能时可能出什么岔子?缺少 admin/maintain 权限时会遇到 403 Forbidden 错误(组织可能需要 admin:org scope);仓库语言不受支持时代码扫描可能失败;还有些组织的策略会阻止开启分支保护。
它在任何操作系统上都能运行吗?它是基于 shell 的 gh 扩展,因此 GitHub CLI 能运行的地方它都能用——Windows、macOS 和 Linux。
它会动我的源代码或向外发送数据吗?不会——它只通过 GitHub API、用你现有的 gh 会话令牌更改仓库设置(分支规则、扫描开关、Dependabot),不会修改你的源代码。
可以只启用特定功能而不是全部五项吗?可以。你可以传入特定功能名称或缩写(如 bp、vr、ss、dep、cs)来只启用这几项;若一个都不指定,则五项全部启用。
可以不用终端、搭配 AI 助手使用吗?可以——README 说它可以从 GitHub Copilot CLI、GitHub Copilot App 或任何能访问该工具的 AI 助手中使用。
应用更改之前可以先预览吗?可以。-n/--dry-run 标志会模拟更改而不实际应用,之后所有更改也都能在仓库设置里撤销。
启用分支保护会不会弄坏我现有的规则集?该工具会先检查是否存在生效中的规则集,并在启用旧版分支保护前发出警告,以避免规则重叠或冲突。
Size
2.6 MB
Stars
653
Updated
CommitOct 02
Age
3mo
Commits · 90 Days