> 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).

# シークレットの 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フックをワンクリックでインストールできます。

[詳しくは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  # または特定のコミットに固定する
    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"
```

このファイルをステージ済みの変更に追加してください。このファイルをコミットしようとすると、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スキャンを無効にする

1回のコミットでpre-commitフックを一時的に回避する

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

1回のコミットで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フックのパスをリセットします: `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.
