> For the complete documentation index, see [llms.txt](https://coky-t.gitbook.io/owasp-devsecops-guideline-ja/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://coky-t.gitbook.io/owasp-devsecops-guideline-ja/v0.1/01-pre-commit/01a-secrets-management.md).

# 01a. シークレットとクレデンシャルに注意

*機密情報がリポジトリにプッシュされないようにするにはどのようにすればよいでしょうか？*

これは [OWASP Top Ten issues](https://owasp.org/www-project-top-ten/2017/A3_2017-Sensitive_Data_Exposure) の一つであり、 いくつかのバグバウンティの記事がこの種の問題に関連しています。たとえばハードコードされたクレデンシャルが誤ってプッシュされたなどです。

コミットやリポジトリをスキャンして、パスワード、秘密鍵、社外秘などの機密情報を検出する必要があります。 図のようなプロセスに従います。<br>

理想的なアプローチは機密データがリポジトリにヒットする前に露出を検出して防止することです。 なぜならそれらは履歴に表示されるからです。コードホスティングプラットフォームの場合、シークレットはウェブ上に残り、 リポジトリから削除した後でも検索できます。

補完的なアプローチとしてはリポジトリをスキャンして機密情報を探し、それを削除することです。 クレデンシャルが漏洩した場合、それはすでに危険な状態であり、無効にすべきであることに注意してください。

## 複数の場所でシークレットを検出する

* **既存のシークレットを検出する** リポジトリ内の既存のシークレットを検索します。
* **プレコミットフックを使用する** シークレットがコードベースに入ることを防ぐため。
* **パイプラインでシークレットを検出する**

## なぜシークレットを検出するのか？

* シークレットがハードコードされていないこと。
* シークレットが暗号化解除されていないこと。
* シークレットがソースコードに保存されていないこと。
* コード履歴に不注意によるシークレットが含まれていないこと。

## シークレットをいつどこで検出するか？

![Pre Commit](/files/WmLag17gYzQRvOzQ9JoD)

そうですね、最適な場所は **pre-commit** の場所です。これによりシークレットが実際にコードベースに入る前にインターセプトされ、開発者やコミットした人がメッセージを受け取ることができます。もう一つの場所はビルドサーバーまたは **build** プロセスです。ビルドサーバーは既にコミットされているソースコードを取得して、ソースコードを解析します。新しいシークレットが含まれていたり、既知のシークレットが含まれていた場合にそのシークレットが実際に妥当性確認や監査されます。

***

ここではリポジトリを自動的にスキャンして機密情報を探すのに役立つツールを紹介します。 スキャンはパイプラインに直接実装でき、再現性と効率性に優れています。

## ツール:

* **オープンソース**:
  * [gittyleaks](https://github.com/kootenpv/gittyleaks) - git リポジトリの機密情報を検索します
  * [git-secrets](https://github.com/awslabs/git-secrets) - シークレットとクレデンシャルを git リポジトリにコミットできないようにします
  * [Repo-supervisor](https://github.com/auth0/repo-supervisor) - コードのセキュリティ設定ミスをスキャンし、パスワードとシークレットを検索します
  * [truffleHog](https://github.com/dxa4481/truffleHog) - git リポジトリから高エントロピー文字列とシークレットを検索し、コミット履歴を深く掘り下げます
  * [Git Hound](https://github.com/ezekg/git-hound) - 機密データのコミットを防止する git プラグインです
  * [Github Secret Scanning](https://docs.github.com/en/code-security/secret-scanning) - GitHub に組み込まれたシークレット検出用の機能です。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://coky-t.gitbook.io/owasp-devsecops-guideline-ja/v0.1/01-pre-commit/01a-secrets-management.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
