> For the complete documentation index, see [llms.txt](https://docs.keeper.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.keeper.io/keeperpam/jp/secrets-manager/integrations/gitlab-plugin.md).

# GitLab

![](/files/PtGNIln9Dizq1HK8Fs1P)

## 機能

* GitLab Pipeline内でKeeperボルトからシークレットを取得
* ビルド引数または環境変数としてシークレット認証情報を設定
* Keeperボルトからセキュリティで保護されたファイルをコピー

{% hint style="info" %}
Keeperシークレットマネージャーの機能一覧については、[概要](/keeperpam/jp/secrets-manager/overview.md)をご参照ください。
{% endhint %}

## 前提条件

本ページでは、シークレットマネージャーとGitLabの連携について取り扱います。本連携を利用するには、以下が必要です。

* Keeperシークレットマネージャーへのアクセス（[クイックスタートガイド](/keeperpam/jp/secrets-manager/quick-start-guide.md)をご参照ください）
  * Keeperのサブスクリプションでシークレットマネージャーアドオンが有効になっていること
  * シークレットマネージャーポリシーが有効なロールに所属していること
* シークレットが共有されているKeeper[シークレットマネージャーアプリケーション](/keeperpam/jp/secrets-manager/about/terminology.md#application)
  * アプリケーションの作成手順については、[クイックスタートガイド](https://docs.keeper.io/keeperpam/jp/secrets-manager/integrations/pages/-MeRAVfQmDBzKQBC0f_c#2.-create-an-application)をご参照ください
* 初期化済みのKeeper[シークレットマネージャー構成](/keeperpam/jp/secrets-manager/about/secrets-manager-configuration.md)
  * GitLab連携では、JSON形式とBase64形式の構成を使用できます
* パイプライン作成権限を持つGitLabアカウント
  * GitLab PipelineジョブにPython 3がインストールされていること

## 概説

この連携では、Keeperからシークレットを安全に取得し、環境変数やファイルなど、GitLab Pipelineの目的の保存先に配置します。

## 設定

### 構成をシークレット変数として保存

GitLab連携を利用するには、Keeper[シークレットマネージャー構成](/keeperpam/jp/secrets-manager/about/secrets-manager-configuration.md)が必要です。

**1)** Keeperシークレットマネージャー構成を作成します。詳細は[ドキュメント](/keeperpam/jp/secrets-manager/about/secrets-manager-configuration.md)をご参照ください。GitLab連携は**Base64**と**JSON**形式の構成に対応しています。

**2)** GitLabに構成を保存するには、**\[GitLab Settings]** -> **CI/CD** -> **Variables**に移動します。

![](/files/UlqzCMbEECN1dAhabY4c)

**3)** 新しい変数を作成します。キーには任意の変数名を設定できます（`KSM_CONFIG` を変数名にすると、シークレットマネージャーSDKが構成を自動認識できます）。値には**Base64**または**JSON**形式のシークレットマネージャー構成を設定します。

{% hint style="info" %}
`KSM_CONFIG` を変数名にすると、シークレットマネージャーSDKが構成変数を自動認識できます
{% endhint %}

![](/files/UlqzCMbEECN1dAhabY4c)

変数を作成すると、以下のようにGitLab変数一覧に表示されます。

![](/files/UlqzCMbEECN1dAhabY4c)

{% hint style="success" %}
KeeperシークレットマネージャーとGitLabの連携設定が完了しました
{% endhint %}

## 使用方法

### シークレットマネージャー用にパイプラインを準備

GitLabでKeeperシークレットマネージャーを使用するには、まずPyPIレジストリからインストールします。`before_script` セクションに以下の行を追加します。

```yaml
before_script:
  - python3 -m pip install keeper-secrets-manager-cli
```

シークレットマネージャー構成の変数名を `KSM_CONFIG` にしていない場合は、`before_script` セクションで以下のように設定します。

```
  - export KSM_CONFIG=$<SECRETS MANAGER CONFIG VARIABLE>
```

### シークレットを取得

GitLabジョブ内で、以下の形式を使用してKeeperボルトからシークレットを取得します。

```bash
$(ksm secret notation <KEEPER NOTATION>)
```

上記のコマンドは[KSM CLIツール](/keeperpam/jp/secrets-manager/secrets-manager-command-line-interface.md)を使用し、[Keeper表記法](/keeperpam/jp/secrets-manager/about/keeper-notation.md)でシークレットを取得します。

シークレットを取得したら、環境変数またはファイルとして設定できます。

### 環境変数としてシークレットを設定

`- export <VARIABLE NAME>=$(ksm secret notation <KEEPER NOTATION>)` を使用して、シークレットを環境変数に設定します。

**例:**

以下のジョブは、パスワードシークレットを `MY_PWD` という環境変数に、カスタム isbncode フィールドを `MY_ISBNCODE` という環境変数に設定します。

```yaml
job1:
  stage: build
  script:
    - export MY_PWD=$(ksm secret notation keeper://XXX/field/password)
    - export MY_ISBNCODE=$(ksm secret notation keeper://XXX/custom_field/isbncode)
```

上記の例の `XXX` をレコードUIDに置き換えます。

{% hint style="info" %}
Keeperシークレットマネージャーは、すべてのジョブステージで使用できます。この例では `build` ステージを使用します。
{% endhint %}

### シークレットからファイルを作成

`- ksm secret download -u <UID> --name <SECRET FILENAME> --file-output "<OUTPUT FILENAME>"` を使用して、Keeperボルトからファイルを取得し、GitLab Pipelineジョブに保存します。

**例:**

以下のジョブは、Keeperレコードに添付された mykey.pub ファイルを取得し、ローカルの `/tmp` フォルダに mykey.pub として保存します。

```yaml
job1:
  stage: build
  script:
   - ksm secret download -u XXX --name "mykey.pub" --file-output "/tmp/mykey.pub"
```

上記の例の `XXX` をレコードUIDに置き換えます。

{% hint style="info" %}
Keeperシークレットマネージャーは、すべてのジョブステージで使用できます。この例では `build` ステージを使用します。
{% endhint %}

## 完全な例

以下の例は、この連携で利用可能なすべての機能を示しています。

```yaml
image: python:latest

before_script:
  - python3 -m pip install keeper-secrets-manager-cli

job1:
  stage: build
  script:
    - export MY_PWD=$(ksm secret notation keeper://XXX/field/password)
    - export MY_ISBNCODE=$(ksm secret notation keeper://XXX/custom_field/isbncode)
    - ksm secret download -u XXX--name "mykey.pub" --file-output "/tmp/mykey.pub"
    - file /tmp/mykey.pub
```

上記の例の `XXX` をレコードUIDに置き換えます。


---

# 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:

```
GET https://docs.keeper.io/keeperpam/jp/secrets-manager/integrations/gitlab-plugin.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
