> 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のpre-commitフック

Aikido は、秘密情報が本番環境に届く前に、IDE、pre-commit、PR ゲーティングの 3 か所でそれを防ぎます。私たちの 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 Framework" %}
すでに [pre-commit](https://pre-commit.com/) フレームワークを使っているなら、 `.pre-commit-config.yaml`:

```
に次を追加してください:
  - repo: https://github.com/AikidoSec/pre-commit
    rev: main  # または特定のコミットに固定
    hooks:
      - id: aikido-local-scanner
```

その後、フックをインストールします:

```
pre-commit install
```

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

**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"
```

このファイルをステージ済みの変更に追加します。このファイルを commit しようとすると、pre-commit フックが実行され、次のメッセージで 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 スキャンを無効にする

1 回の commit に対して一時的に pre-commit フックをバイパスする

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

1 回の commit に対して Aikido Secrets の pre-commit フックを一時的にバイパスする

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

## アンインストール

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

{% tabs %}
{% tab title="Mac/Lunix" %}
インストールスクリプトを使って 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" %}
インストールスクリプトを使って 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.
