> 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 は、秘密情報が本番環境に到達する前に 3 つのポイントで防ぎます: IDE、pre-commit、PR ゲーティングです。私たちの pre-commit githook は、ステージ済みのコードから秘密情報、パスワード、API キーをスキャンします。これにより機密データがリポジトリに到達するのを防ぎ、漏えいや意図しない公開のリスクを軽減します。

## インストール

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

[詳細は 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 hook をインストールするには、次を実行します:

```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 hook スクリプトがグローバル hooks ディレクトリにインストールされます。
{% endtab %}

{% tab title="Windows" %}
すべての git リポジトリに Aikido Secrets の pre-commit hook をインストールするには、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 hook スクリプトがグローバル hooks ディレクトリにインストールされます。
{% endtab %}

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

```
repos:
  - repo: https://github.com/AikidoSec/pre-commit
    rev: main  # または特定のコミットに固定する
    hooks:
      - id: aikido-local-scanner
```

その後、hooks をインストールします:

```
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 hook のテスト

設定した後に pre-commit hook をテストするには、 `sample.js` ファイルをリポジトリに作成します:

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

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

```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 hooks を一時的にバイパスする

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

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

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

## アンインストール

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

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

```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 hook をインストールしており、アンインストールしたい場合は、次を実行します:

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

{% endtab %}
{% endtabs %}

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

これにより、すべてのグローバル Git hooks と 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 を使用していてそれらを保持したい場合は、hooks ディレクトリを削除しないでください。

代わりに:

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

Git は、Aikido Secrets を実行せずに既存の hooks を引き続き使用します。

## 関連記事

* [コードコメントによるシークレットの無視](/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.
