GitHub初心者向け: GitHubセキュリティの始め方
GitHub公式ブログは、初心者向けにGitHub Advanced Security(GHAS)のセキュリティ機能(シークレットスキャン、Dependabot、コードスキャン、Copilot Autofix)を有効化・使用する具体的な手順を解説し、コードの脆弱性を発見・修正する方法を紹介している。
キーポイント
セキュリティの重要性と脆弱性の継承
プロジェクトで使用するサードパーティライブラリの脆弱性は、そのままプロジェクトのリスクとなるため、新規・小規模プロジェクトでもセキュリティ対策が重要である。
GitHub Advanced Security(GHAS)の概要
GHASはコードの品質を向上・維持するための製品スイートであり、パブリックリポジトリではDependabot、コードスキャン、シークレットスキャン、Copilot Autofixが利用可能である。
セキュリティ機能の有効化手順
リポジトリ設定からGHASを有効にし、Dependabotアラート/アップデート、CodeQL分析、シークレット保護を順次オンにする具体的な手順が示されている。
シークレットスキャンの実用的な利用方法
誤ってコミットしたAPIキーやトークンは、セキュリティタブのシークレットスキャンで検知され、アラートをクリックすることで詳細な内容と場所を確認できる。
Dependabotの機能と活用方法
Dependabotは依存関係の脆弱性を検出し、GitHubセキュリティアドバイザリを自動的にプルリクエストに変換するツールです。アラートを確認し、セキュリティ更新をレビューした後にプルリクエストをマージすることで、プロジェクトの依存関係を安全に保つことができます。
CodeQLの特徴とCopilot Autofixの活用
CodeQLはデータフローを理解する強力なコードスキャンエンジンで、幅広いシナリオをカバーします。アラートの詳細を理解した後、Copilot Autofixの「Generate fix」ボタンを使用して問題を解決できます。
Copilotによるセキュリティ修正の確認
Copilotが提案するパッチをレビューし、ニーズに対応しているか確認する必要があります。
影響分析・編集コメントを表示
影響分析
この記事は、GitHubが提供する統合的なセキュリティツールの存在とその具体的な利用方法を、特に初心者層に広く認知させる役割を果たす。開発者、特にオープンソースプロジェクトのメンテナーにとって、セキュリティ対策の敷居を下げ、標準的なプラクティスとしての浸透を促進する可能性がある。
編集コメント
GitHub公式による初心者向けチュートリアルという位置付けであり、新機能の発表ではなく既存機能の解説記事。しかし、セキュリティ対策の重要性と具体的な導入フローを分かりやすくまとめており、実践的な価値は高い。
GitHub for Beginners シーズン3へようこそ!今年これまでに、GitHub IssuesとProjects、そしてGitHub Actionsについて取り上げてきました。今回はセキュリティについて少しお話しし、GitHubがコードの安全性を維持するために提供するツールについて説明します。この記事を読み終える頃には、シークレットスキャン、Dependabot、コードスキャン、Copilot Autofixなどの組み込みツールを使ってリポジトリの脆弱性を修正する方法を理解できるようになるでしょう。
なぜセキュリティが重要なのか
脆弱性とは、攻撃者が悪用できるコードや使用ライブラリの弱点のことです。脆弱なコードを自分で書いていなくても、ライブラリをプロジェクトにインポートした瞬間に、そのライブラリのリスクを引き継ぐことを理解することが重要です。これが、小規模なプロジェクトやまったく新しいプロジェクトでさえ脆弱性を持つ可能性がある理由です。ほとんどすべてのソフトウェアはサードパーティのパッケージに依存しているからです。
GitHubは、GitHub Advanced Security (GHAS) という製品スイートにより、これらの問題を見つけて修正することをかつてないほど簡単にしています。GHASはコードの品質を向上させ、維持するのに役立ちます。公開リポジトリでは、Dependabot、コードスキャン、シークレットスキャン、Copilot Autofixを利用できます。さまざまな機能についてさらに詳しく知りたい場合は、GHASに関するドキュメントをご覧ください。または、これらの機能の一部を有効にして使用する手順をこれから説明しますので、読み進めてください。
セキュリティ機能を有効にする
最初のステップは、GHASが有効になっていることを確認することです。
- リポジトリに移動します。
- ページ上部の [Settings] タブをクリックします。
- 左側のバーで、「Security」セクションの下にある [Code security and analysis] を選択します。
- 「Dependabot」の下で、「Dependabot alerts」と「Dependabot security updates」を有効にします。
- 「Code scanning」セクションまでスクロールダウンします。
- 「CodeQL analysis」で、[Set up] を選択し、コンテキストメニューから [Default] を選択します。
- 新しいウィンドウが表示されます。設定を変更せずに [Enable CodeQL] を選択します。
- 「Secret scanning」までスクロールダウンして有効にします。
これらのツールは、デフォルトで公開リポジトリで利用できます。プライベートリポジトリの場合は、GHASライセンスが必要です。
ウィンドウ上部の [Security] タブを選択して、このリポジトリのセキュリティホームページに移動します。ここには、有効にしたさまざまなGHASツールのオプションが表示されます。ここで、漏洩したシークレット、脆弱な依存関係、リスクのあるコードパスに関するアラートを確認できます。
では、これらのツールのいくつかを詳しく見ていきましょう。さまざまなアラートの表示例を確認するには、このブログ記事のビデオ版がオンラインで公開されていることを覚えておいてください。
シークレットスキャンを使用する
GitHubは、シークレットスキャンを使用して機密情報を保護するのに役立ちます。誤ってAPIキーやトークンをコミットした場合、シークレットスキャンが左側の [Security] タブ内の「Secret scanning」で警告を表示します。アラートが表示されたら、特定のアラートのタイトルをクリックして、どのシークレットがどこで検出されたかを確認します。
この漏洩したシークレットに対処する方法の1つは、無効化(取り消し)することです。シークレットの無効化とは、古いキーを無効にして使用できなくすることを意味します。通常、シークレットの発行元プラットフォーム(AzureやStripeなど)で新しいキーを生成することで行います。
GitHubは自動的にシークレットを無効化することはできません。この部分はご自身で行う必要があります。ただし、シークレットスキャンは早期に警告するため、漏洩したシークレットが悪用される前に防ぐことができます。
シークレットを無効化したら、次の手順でシークレットスキャンのアラートを閉じることができます。
- ウィンドウ右上の [Close as] を選択します。
- コンテキストメニューから [Revoked] を選択します。
- コンテキストメニュー下部の緑色の [Close alert] ボタンをクリックします。
Dependabotとは?
Dependabotは、依存関係を最新の状態に保つのに役立つツールです。プロジェクトに取り込んだすべてのライブラリの脆弱性を引き継ぐという話を覚えていますか?Dependabotは、プロジェクトが依存するライブラリに脆弱性を発見した場合に警告することで、この問題に対処するのに役立ちます。
Dependabotアラートを確認するには、リポジトリの [Security] タブに戻ります。Dependabotアラートをクリックすると、プルリクエストに移動するので、ライブラリを更新できます。プルリクエスト内で下にスクロールし、[See advisory in GitHub Advisory Database] を選択すると、アラートの原因となった具体的なアドバイザリを確認できます。
プルリクエストで、上部の緑色の [Review security update] ボタンを選択して、バージョンアップの内容を確認します。変更を取り込む前には、常に提案された変更を確認する必要があります。すべて問題なさそうであれば、プルリクエストをマージしてください。
Dependabotは、GitHubセキュリティアドバイザリをプルリクエストに自動的に変換するため、共通脆弱性識別子 (CVE) を手動で追跡する必要がありません。
レベルアップする準備はできていますか?
GitHub Advanced Securityについてさらに学び、GitHub Skillsにアクセスしていくつかの課題に挑戦することで、スキルをレベルアップしてください。これらはセキュリティについて学ぶ楽しくインタラクティブな方法です!
- シークレットスキャンの紹介
- リポジトリのサプライチェーンを保護する
- CodeQLの紹介
また、vulnerable-nodeリポジトリをチェックして、これらのツールを使った実践経験をさらに積むこともできます。
CodeQLアラートへの対応
CodeQLは、コードをスキャンしてコードスキャンアラート([Security] タブで確認できます)を生成するエンジンです。CodeQLはリンターではありません。データフローを理解し、入力がどこから始まりどこに行き着くかを示すため、はるかに強力です。
その結果、コードスキャンアラートは、多岐にわたる可能性のあるシナリオをカバーできます。コードスキャンアラートを選択すると、問題が説明され、可能であれば修正の推奨事項や、問題と解決策を示す例などの追加情報が提供されます。
アラートの内容を理解したら、Copilot Autofixを使用して次の手順で解決できます。
- アラート上部の [Generate fix] ボタンを選択します。
- Copilotが修正案を提案します。変更内容を確認し、要件を満たしていることを確認します。
- 下部の緑色の [Commit to new branch] ボタンをクリックします。
- 新しいポップアップウィンドウで、[Open a pull request] オプションを選択し、[Commit change] をクリックします。
生成されたプルリクエストは、他のプルリクエストと同様に扱います。確認して変更をマージしてください。Copilotはセキュリティ修正を加速しますが、常に最終的な判断はあなたが行っていることを忘れないでください。
次は何をしましょうか?
おめでとうございます!GitHub Advanced Securityを使ってコードの脆弱性を自信を持って検出および修正する方法を学びました。公開リポジトリはこれらのGHASツールに無料でアクセスできるため、最初からプロジェクトを安全に保つことができます。GitHub Skillsまたはvulnerable-nodeリポジトリを利用していつでもスキルを試してください。
さらに情報をお探しの場合は、豊富なドキュメントが利用可能です。始めるためのリンクをいくつか紹介します。
- シークレットスキャンについて
- Dependabotアラートについて
- コードスキャンアラートについて
Happy coding!
この投稿「GitHub for Beginners: GitHubセキュリティの基本」は、The GitHub Blogに最初に掲載されました。
原文を表示
Welcome back to GitHub for Beginners, season three! So far this year, we’ve covered GitHub Issues and Projects, as well as GitHub Actions. This time around, we’re going to be talking a little bit about security, and what tools GitHub provides to help you keep your code secure. By the end of this post, you’ll understand how to fix vulnerabilities in your repository using built-in tools like secret scanning, Dependabot, code scanning, and Copilot Autofix.
Why security matters
Vulnerabilities are weaknesses in your code or the libraries you use that attackers can exploit. It’s important to realize that you inherit any risk from a library the moment you import it into your project, even though you didn’t write the vulnerable code yourself. This is why even small or brand-new projects can have vulnerabilities—almost all software relies on third-party packages.
GitHub makes finding and fixing these issues easier than ever with GitHub Advanced Security (GHAS), a suite of products that helps you improve and maintain the quality of your code. On public repositories, you have access to Dependabot, code scanning, secret scanning, and Copilot Autofix. If you want to learn even more about the different features, check out our documentation about GHAS. Or keep reading as we walk through enabling and using some of these features.
Enabling security features
The first step is making sure that GHAS is turned on.
Navigate to your repository.
Click the Settings tab at the top of the page.
In the left-hand bar, under the “Security” section, select Advanced Security.
Under “Dependabot,” enable “Dependabot alerts” and “Dependabot security updates.”
Scroll down to the “Code scanning” section.
For “CodeQL analysis,” select Set up and then select Default from the context menu.
A new window will appear. Select Enable CodeQL without changing any settings.
Scroll down to “Secret Protection” and enable it.
These tools are available to public repositories by default. If you have a private repository, you’ll need a GHAS license.
Select the Security tab at the top of the window to navigate to the security home page for this repository. Here you’ll see options for the various GHAS tools you’ve enabled. This is where you can see alerts for exposed secrets, vulnerable dependencies, and risky code paths.
Now let’s take a look at some of these tools in greater detail. To see how the various alerts look, remember that we have a video version of this blog available online.
Using secret scanning
GitHub can help you protect sensitive information with secret scanning. If you accidentally commit an API key or token, secret scanning will flag it in the security tab in the left-hand column underneath Secret scanning. When you see an alert, click the title of the specific alert to see what secret was detected and where it was found.
One of the ways to address this exposed secret is to revoke it. Revoking a secret means disabling the old key so that it can’t be used anymore. You usually do this by generating a new key on the platform where the secret came from, such as Azure or Stripe.
GitHub can’t automatically revoke the secret for you. You’ll need to do that part yourself. However, secret scanning gives you an early warning so that a leaked secret doesn’t become an exploited secret.
Once you’ve revoked the secret, you can close the secret scanning alert by doing the following:
Select Close as in the top-right of the window.
Select Revoked from the context menu.
Click the green Close alert button at the bottom of the context menu.
What is Dependabot?
Dependabot is a code scanning tool that helps you keep your dependencies up to date. Remember when we talked about how you inherit the vulnerabilities of every library you pull into your project? Dependabot helps to address this by alerting you if it finds vulnerabilities in the libraries your project depends on.
To find Dependabot alerts, navigate back to the Security tab in your repository. When you click on a Dependabot alert, it’ll navigate you to the pull request, so you can update your library. In the pull request, if you scroll down, you can see the specific advisory that triggered the alert by selecting See advisory in GitHub Advisory Database.
From the pull request, select the green Review security update button at the top to review the version bump. You should always review suggested changes before incorporating them. As long as everything looks good, go ahead and merge the pull request.
Dependabot automates turning GitHub security advisories into pull requests so you don’t have to manually track common vulnerabilities and exposures.
Ready to level up?
Learn more about GitHub Advanced Security and level up your expertise by heading over to GitHub Skills and trying some of these challenges. They’re a fun and interactive way to learn about security!
Introduction to secret scanning
Secure your repository’s supply chain
Introduction to CodeQL
You can also check out the vulnerable-node repository to get more experience using these tools.
Responding to CodeQL alerts
CodeQL is the engine that scans your code and produces the code scanning alerts (which you can find under the Security tab). CodeQL is not a linter. It’s much more powerful because it understands data flow, showing where input starts and where it ends up.
As a result, code scanning alerts can cover a wide range of possible scenarios. When you select a code scanning alert, it will explain the issue and, if it can, provide additional information, such as a recommendation for fixes and examples to illustrate the problem and possible solution.
Once you have an understanding of the alert, you can use Copilot Autofix to resolve it by following these steps:
Select the Generate fix button at the top of the alert.
Copilot will suggest a patch. Review the change and verify it addresses your needs.
Click the green Commit to new branch button at the bottom.
In the new pop-up window, select the Open a pull request option, and click Commit change.
Treat the generated pull request as you would any other pull request: review it and merge changes. Remember that while Copilot accelerates security fixes, you stay in control the entire time.
What’s next?
Congratulations! You’ve now learned how to use GitHub Advanced Security to confidently detect and fix vulnerabilities in your code. Public repositories have access to these GHAS tools for free, so you can keep your projects safe from the start. Test your skills using GitHub Skills or the vulnerable-node repository any time.
And if you’re looking for more information, we have lots of documentation available. Here are just a few links to get your started:
About secret scanning
About Dependabot alerts
About code scanning alerts
Happy coding!
The post GitHub for Beginners: Getting started with GitHub security appeared first on The GitHub Blog.
関連記事
今日のまとめ
AI日報で今日の重要ニュースをまとめ読み