> For the complete documentation index, see [llms.txt](https://help.aikido.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.aikido.dev/docs/docs-ja/ai-totsru/aikido-secrets-pre-commit-hook.md).

# Secrets の事前コミットフック

Aikido は、本番環境に到達する前の 3 つのポイントでシークレットを防ぎます: IDE、pre-commit 時、PR のゲート時です。私たちの pre-commit githook は、ステージ済みコード内のシークレット、パスワード、API キーをスキャンします。機密データがリポジトリに到達するのを防ぐことで、漏えいや意図しない公開のリスクを低減します。

## インストール

{% tabs %}
{% tab title="IDE から" %}
その [Aikido IDE プラグイン](broken://pages/86df750995a73f7f6f060fc99988f19f951074d8) がインストールされている場合、Aikido Expansion Packs を使って pre-commit フックをワンクリックでインストールできます。

[Expansion Packs のドキュメントで詳しく見る。](/docs/docs-ja/ai-totsru/ide-plugins-overview/features/aikido-expansion-packs.md)
{% endtab %}

{% tab title="Mac/Linux" %}
すべての Git リポジトリに Aikido Secrets の pre-commit フックをインストールするには、次を実行します:

```shellscript
curl -fsSL https://raw.githubusercontent.com/AikidoSec/pre-commit/6cc79e039ee78b206520f143d618a44665c904b3/installation-samples/install-global/install-aikido-hook.sh | bash
```

これにより、シークレット検出に使用される Aikido pre-commit スキャナーがダウンロードされ、pre-commit フックスクリプトがグローバル hooks ディレクトリにインストールされます。
{% endtab %}

{% tab title="Windows" %}
すべての Git リポジトリに Aikido Secrets の pre-commit フックをインストールするには、PowerShell で次を実行します:

```powershell
iex (iwr "https://raw.githubusercontent.com/AikidoSec/pre-commit/6cc79e039ee78b206520f143d618a44665c904b3/installation-samples/install-global/install-aikido-hook.ps1" -UseBasicParsing)
```

これにより、シークレット検出に使用される Aikido pre-commit スキャナーがダウンロードされ、pre-commit フックスクリプトがグローバル hooks ディレクトリにインストールされます。
{% endtab %}

{% tab title="Pre-Commit フレームワーク" %}
すでに [pre-commit](https://pre-commit.com/) フレームワークを使用しているなら、これを `.pre-commit-config.yaml`:

```
repos:
  - repo: https://github.com/AikidoSec/pre-commit
    rev: main  # or pin to a specific commit
    hooks:
      - id: aikido-local-scanner
```

次にフックをインストールします:

```
pre-commit install
```

**注意:** 次の `aikido-local-scanner` binary は別途インストールする必要があります。まずグローバルインストールスクリプトを実行してください:

**macOS/Linux:**

```
curl -fsSL https://raw.githubusercontent.com/AikidoSec/pre-commit/2235fe0536f9135aa561ce108702fac708b38977/installation-samples/install-global/install-aikido-hook.sh | bash -s -- --download-only
```

**Windows (PowerShell):**

```
irm https://raw.githubusercontent.com/AikidoSec/pre-commit/2235fe0536f9135aa561ce108702fac708b38977/installation-samples/install-global/install-aikido-hook.ps1 | % { iex \"& { $_ } -DownloadOnly\" }
```

これによりスキャナーが次の場所にインストールされます `~/.local/bin/aikido-local-scanner`.
{% endtab %}
{% endtabs %}

次の [スクリプトのソースコードとその動作に関する詳細情報](https://github.com/AikidoSec/pre-commit) は GitHub で確認できます。

## pre-commit フックのテスト

セットアップ後に pre-commit フックをテストするには、リポジトリに `sample.js` というファイルを作成します:

```javascript
const password = "eRwjQKVUSRX7uYV017B0cRHVKv45Gv8G"
```

このファイルをステージ済みの変更に追加してください。このファイルをコミットしようとすると、pre-commit フックが実行され、次のメッセージでコミットがブロックされます:

```log
ステージ済みファイルでシークレットが検出されました!
シークレット #1:
  ファイル: sample.js
  行: 1
  シークレット: password = "****************************Gv8G"
  説明: 汎用 API キーを検出しました。さまざまなサービスや機密操作へのアクセスを公開してしまう可能性があります。
```

## 特定のシークレットをスキップする

〜をスキップするには [特定のシークレットがフラグ付けされるのを防ぐ](/docs/docs-ja/kdosukyan/scanning-practices/ignoring-secrets-via-code-comments.md)、検出されたシークレットの行にコメントを追加します:

```javascript
const password = "eRwjQKVUSRX7uYV017B0cRHVKv45Gv8G" // gitleaks:allow
```

## Aikido Secrets の pre-commit スキャンを無効にする

単一のコミットで pre-commit フックを一時的にバイパスする

```sh
git commit --no-verify
```

単一のコミットで Aikido Secrets の pre-commit フックを一時的にバイパスする

```bash
AIKIDO_SKIP_PRE_COMMIT=1 git commit
```

## アンインストール

アンインストールスクリプトを使用するか、以下の手順に従ってフックを手動でアンインストールしてください。

{% tabs %}
{% tab title="Mac/Lunix" %}
install スクリプトを使って Aikido pre-commit フックをインストールし、アンインストールしたい場合は、次を実行します:

```bash
curl -fsSL https://raw.githubusercontent.com/AikidoSec/pre-commit/e6f541e65378dd30f3f320628000f837cfba0ec4/installation-samples/install-global/uninstall-aikido-hook.sh | bash
```

{% endtab %}

{% tab title="Windows" %}
install スクリプトを使って Aikido pre-commit フックをインストールし、アンインストールしたい場合は、次を実行します:

```powershell
iex (iwr "https://raw.githubusercontent.com/AikidoSec/pre-commit/e6f541e65378dd30f3f320628000f837cfba0ec4/installation-samples/install-global/uninstall-aikido-hook.ps1" -UseBasicParsing)
```

{% endtab %}
{% endtabs %}

### グローバル pre-commit フックの手動アンインストール

これにより、すべてのグローバル Git フックと Aikido バイナリが完全に削除されます。

1. グローバル hooks ディレクトリを削除します:
   * Unix/Linux/macOS: `rm -rf ~/.git-hooks`
   * Windows: `Remove-Item -Recurse -Force $env:USERPROFILE\.git-hooks`
2. Git hooks のパスをリセットします: `git config --global --unset core.hooksPath`
3. 必要に応じてバイナリを削除します:
   * Unix/Linux/macOS: `rm ~/.local/bin/aikido-local-scanner`
   * Windows: `Remove-Item $env:USERPROFILE\.local\bin\aikido-local-scanner.exe`

### Aikido Git Hook のみを手動でアンインストールする

すでに独自のグローバル Git フックを使用していて、それらを保持したい場合は、hooks ディレクトリを削除しないでください。

代わりに:

1. グローバル hooks ディレクトリ内の pre-commit ファイル（例: \~/.git-hooks/pre-commit）を開きます。
2. aikido-local-scanner を呼び出す行、または Aikido によって追加されたと明確に分かる行だけを削除します。
3. ファイルを保存します。

Git は既存のフックを引き続き使用し、Aikido Secrets は実行しません。

## 関連記事

* [コードコメントでシークレットを無視する](/docs/docs-ja/kdosukyan/scanning-practices/ignoring-secrets-via-code-comments.md)
* [.aikido ファイルを使ってファイルを無視する](/docs/docs-ja/kdosukyan/scanning-practices/ignore-via-code-with-aikido-files.md)


---

# 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://help.aikido.dev/docs/docs-ja/ai-totsru/aikido-secrets-pre-commit-hook.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.
