# GitLab

<figure><img src="https://859776093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPL6k1aGsLiFiiJ3Y7zCl%2Fuploads%2FYJsUQ3EYhsiSwKrYHWeP%2Fimage.png?alt=media&#x26;token=407134c3-5ee0-4877-95ec-75abf2bd0581" alt=""><figcaption></figcaption></figure>

## 機能

* GitLabパイプライン内にKeeperボルトからシークレットを取り込みます
* ビルドの引数または環境変数としてシークレットのクレデンシャルを設定します
* Keeperボルトからセキュリティで保護されたファイルをコピーします

{% hint style="info" %}
Keeper Secrets Manager機能の完全なリストについては、[概要](/keeperpam/jp/secrets-manager/overview.md)をご参照ください。
{% endhint %}

## 前提条件

このページでは、Secrets ManagerとGitLabとの連携について説明します。 この連携を利用するための必要条件は以下のとおりです。

* Keeper Secrets Managerへのアクセス (詳細については、[クイックスタートガイド](/keeperpam/jp/secrets-manager/quick-start-guide.md)をご参照ください)
  * KeeperアカウントのSecrets Managerアドオンの有効化
  * Secrets Manager強制ポリシーが有効化されたロールを割り当てられたメンバーシップ
* シークレットを共有するKeeper [Secrets Managerアプリケーション](/keeperpam/jp/secrets-manager/about/terminology.md)
  * アプリケーションの作成手順については、[クイックスタートガイド](/keeperpam/jp/secrets-manager/quick-start-guide.md)をご参照ください
* Keeper [Secrets Manager設定](/keeperpam/jp/secrets-manager/about/secrets-manager-configuration.md)の初期化
  * GitLab連携では、JSON形式とBase64形式の設定を使用できます
* パイプラインの作成権限を持つGitLabアカウント
  * GitLabパイプラインジョブにインストールされたPython3

## 概説

このアクションによって、Keeperからシークレットを安全に取得し、環境変数やファイルなど、GitLabパイプラインの適切な場所に格納します。

## 設定

### 設定をシークレット変数として保存

GitLab連携を利用するには、Keeper [Secrets Managerの設定](/keeperpam/jp/secrets-manager/about/secrets-manager-configuration.md)が必要です。

**1)** Keeper Secrets Managerの設定を作成します。 詳細は、[ドキュメント](/keeperpam/jp/secrets-manager/about/secrets-manager-configuration.md)をご参照ください。GitLab連携は**Base64**と**JSON**形式の設定をサポートしています。

**2)** GitLabに設定を保存するには、GitLab設定 (GitLab Settings) -> CI/CD -> 変数 (Variables) に移動します。

<figure><img src="https://859776093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPL6k1aGsLiFiiJ3Y7zCl%2Fuploads%2FUuBO2Yp17FzXpT1LqLpM%2Fimage.png?alt=media&#x26;token=29eaf3bd-90bd-426b-8e7d-a7466f44beb6" alt=""><figcaption></figcaption></figure>

**3)** 新しい変数を作成します。キーには、変数の任意の名前を設定できます (KSM\_CONFIGを使用して、SDKに設定を自動的に認識させます)。**Base64**または**JSON**形式のSecrets Managerの設定として値を指定します。

{% hint style="info" %}
`KSM_CONFIG`を変数名として使用して、Secrets Manager SDKが設定の変数を自動的に認識するようにします
{% endhint %}

<figure><img src="https://859776093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPL6k1aGsLiFiiJ3Y7zCl%2Fuploads%2Fv5jIsb7MlzcLg0mfac6F%2Fimage.png?alt=media&#x26;token=b7c94fdb-e421-4e12-8f6b-f346836ecc71" alt=""><figcaption></figcaption></figure>

変数を作成すると、以下に示すようにGitLab変数に表示されるはずです。

<figure><img src="https://859776093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPL6k1aGsLiFiiJ3Y7zCl%2Fuploads%2FDntv7Zc4IzsHwH80LSuO%2Fimage.png?alt=media&#x26;token=df969315-2c83-4d3d-8eb5-cec1cac908da" alt=""><figcaption></figcaption></figure>

{% hint style="success" %}
Keeper Secrets ManagerとGitLabの連携設定が完了しました
{% endhint %}

## 使用方法

### Secrets Managerのパイプラインを準備

GitLabでKeeper Secrets Managerを使用するには、まずPyPiレジストリからインストールする必要があります。これは、`before_script`欄に以下の行を追加することで実現できます。

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

Secrets Managerの設定で変数名を`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 Secrets Managerは、すべてのジョブステージで使用できます。この例では、`build`ステージを使用します。
{% endhint %}

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

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

**例:**

以下のジョブは、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 Secrets Managerは、すべてのジョブステージで使用できます。この例では、`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: 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.
