> 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/azure-devops-plugin.md).

# Azure DevOps拡張機能

![](/files/VHQL9QL4pHbFFYZzXIkd)

## 機能

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

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

## 前提条件

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

* 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)
  * Azure DevOps連携では、JSON形式とBase64形式の構成を使用できます

## インストール

### Keeperシークレットマネージャー拡張機能のインストール

[Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=KeeperSecurity.keeper-secrets-manager)からダウンロードするか、「Keeper Secrets Manager」で検索してください。

ソースコードは[GitHubリポジトリ](https://github.com/Keeper-Security/secrets-manager/tree/master/integration/keeper_secrets_manager_azure_pipeline_extension)で公開されています。

![](/files/rYfkgSnUrRZZR0k2nrg9)

組織を選択して **\[Download]** をクリックし、Azure組織で拡張機能を有効にします。

![](/files/KfQktQ7yuJ5xGX0I7YL8)

## Azure Pipelinesからシークレットにアクセス

Keeperボルトのシークレットにアクセスするには、Azure PipelinesのYAML設定ファイルにタスクを追加し、レコードから必要なフィールドを取得します。

シークレットのクエリには [Keeper表記法](/keeperpam/jp/secrets-manager/about/keeper-notation.md) を使用し、構文は `KeeperNotation > destination` です。代入先はプレフィックス `var:`、`out:`、`file:` で指定します。以下の例をご参照ください。

{% hint style="warning" %}
v1.0.4以降の拡張機能では、UIDの代わりにレコードタイトルによる検索構文を使用できます。タイトルを使用する場合は、Keeper表記法のルールに従ってエスケープし、YAML形式の特殊文字エスケープ仕様にも従う必要があります。
{% endhint %}

### Keeperシークレットマネージャータスクの作成

Keeperシークレットマネージャーのタスクは以下のとおりです。

```
- task: ksmazpipelinetask@1
  inputs:
    keepersecretconfig: $(secret_config)
    secrets: |
      6ya_fdc6XTsZ7i4x9Jcodg/field/password > var:var_password
      6ya_fdc6XTsZ7i4x9Jcodg/field/password > out:out_password
      6ya_fdc6XTsZ7i4x9Jcodg/field/password > out_password2
      6ya_fdc6XTsZ7i4x9Jcodg/file/cert.pem > file:/tmp/mycert.pem

```

この例では、`6ya_fdc6XTsZ7i4x9Jcodg` がレコードUIDです。タスクはタスクフォームで作成するか、手動で追加できます。

#### タスクフォームを使用したタスクの追加

タスクメニューで「Keeper Secrets Manager」を検索し、タスクフォームを開きます。

![](/files/IO6UYvZlJtakaD6hFwqj)

タスクフォームに入力してKeeperシークレットマネージャータスクを作成するには、以下が必要です。

* [Keeperシークレットマネージャー構成](/keeperpam/jp/secrets-manager/about/secrets-manager-configuration.md)
  * Azure DevOps拡張機能では、JSON形式とBase64形式の構成を使用できます
* 1つ以上の[シークレットクエリ](#keeper-secret-queries)（以下のクエリ構文をご参照ください）

![](/files/z1j3t8sAQunqGBBeXLaF)

Keeperシークレットマネージャー構成をパイプラインに直接コピーすることもできますが、Azure Pipelineからアクセス可能なAzure Key Vaultに構成を保管することをお勧めします。Azure Key Vaultの詳細は、[Microsoftのドキュメント](https://docs.microsoft.com/en-us/azure/key-vault/general/overview)をご参照ください。

フォームを送信すると、設定にタスクが自動的に追加されます。

#### タスクを手動で追加

パイプライン設定にタスクを手動で追加するには、以下の構文に従います。

{% tabs %}
{% tab title="Syntax" %}

```
- task: <Task Name>
  inputs:
    keepersecretconfig: <Secrets Manager Configuration>
    secrets: |
      <Secrets Queries>
```

{% endtab %}

{% tab title="Example" %}

```
- task: ksmazpipelinetask@1
  inputs:
    keepersecretconfig: $(secret_config)
    secrets: |
      6ya_fdc6XTsZ7i7x9Jcodg/field/password > pazzword
      6ya_fdc6XTsZ7i7x9Jcodg/field/login > LOGIN
      6ya_fdc6XTsZ7i7x9Jcodg/file/build-vsix.sh > file:/tmp/build-vsix.sh
```

{% endtab %}
{% endtabs %}

### Keeperシークレットクエリ <a href="#keeper-secret-queries" id="keeper-secret-queries"></a>

Keeperボルトのシークレットに対するクエリでは、以下の構文を使います。

#### 標準フィールド値を取得

構文

```
[UID]/field/[FIELD NAME] > [VARIABLE NAME]
```

例

```
6ya_fdc6XTsZ7i7x9Jcodg/field/password > my_password
```

#### カスタムフィールド値を取得

構文

```
[UID]/custom_field/[FIELD NAME] > [VARIABLE NAME]
```

例

```
6ya_fdc6XTsZ7i7x9Jcodg/custom_field/notes > MyNotes
```

#### 二要素コードを取得

構文

`[UID]/field/oneTimeCode > [VARIABLE NAME]`

例

```
6ya_fdc6XTsZ7i7x9Jcodg/field/oneTimeCode > MyOneTimeCode
```

#### ファイルを取得

構文

```
[UID]/file/[SECRET FILE NAME] > file:[OUTPUT FILE NAME]
```

例

```
6ya_fdc6XTsZ7i7x9Jcodg/file/cert.pem > file:secret-cert.pem
```

####

#### 変数の型

Keeperボルトのシークレットをパイプラインの変数として保存する場合、用途に応じて以下の方法を選択できます。

**OUT**

`out`（デフォルト）を使うと、パイプライン内のすべてのジョブから参照できる変数にシークレットを設定できます。変数の型を指定しない場合は、デフォルトで `out` が使われます。

```
6ya_fdc6XTsZ7i7x9Jcodg/field/password > pazzword
6ya_fdc6XTsZ7i7x9Jcodg/field/password > out:my_password
```

**VAR**

`var` を使うと、同じパイプラインジョブ内でのみ使用できるローカル変数にシークレットを設定できます。

```
6ya_fdc6XTsZ7i7x9Jcodg/field/password > var:my_password
```

**FILE**

`file` を使うと、ファイルにコンテンツが書き込まれます。Keeperボルトから証明書などを取得するときに使います。

```
6ya_fdc6XTsZ7i7x9Jcodg/file/build-vsix.sh > file:/tmp/build-vsix.sh
```

**環境変数**

`env` を使うと、ビルドマシンから参照できる環境変数としてシークレットを設定できます。

まずシークレットをパイプライン変数に設定し、bashタスクの環境変数としてマッピングします。

```
- task: ksmazpipelinetask@1
  name: getKeeperSecrets
  inputs:
    keepersecretconfig: $(sm-config)
    secrets: |
      6ya_fdc6XTsZ7i7x9Jcodg/field/password > var:var_password
      
- bash: |
        echo "Using the mapped env variable: $MY_MAPPED_ENV_VAR_PASSWORD"
    env:
        $MY_MAPPED_ENV_VAR_PASSWORD: $(var_password)
```

## 使用例

### Keeperからシークレットを取得

このパイプライン例では、Keeperボルトのシークレットを変数に設定して表示します。表示されるパスワードはマスクされます。

```yaml
trigger:
- master

pool:
  vmImage: ubuntu-latest

steps:

- task: ksmazpipelinetask@1
  name: setKsmSecretsStep
  inputs:
    keepersecretconfig: $(sm-config)
    secrets: |
      6ya_fdc6XTsZ7i7x4Jcodg/field/password > var:var_password
      6ya_fdc6XTsZ7i7x4Jcodg/field/password > out_password2
      6ya_fdc6XTsZ7i7x4Jcodg/field/password > out:out_password
      6ya_fdc6XTsZ7i7x4Jcodg/field/oneTimeCode > var:MyOneTimeCode
      6ya_fdc6XTsZ7i7x4Jcodg/file/build-vsix.sh > file:/tmp/build-vsix.sh

- bash: |
    echo "Using an input-macro works                : $(var_password)"
    echo "Using an output variable (default method) : $(setKsmSecretsStep.out_password2)"
    echo "Using an output variable                  : $(setKsmSecretsStep.out_password)"
    echo "Using an output variable for totp         : $(setKsmSecretsStep.out_password)"
    echo "Using the mapped env var                  : $(MyOneTimeCode)"
    echo "Check injected secret file                : $(file /tmp/build-vsix.sh)"
  env:
    MY_MAPPED_ENV_VAR_PASSWORD: $(var_password) # 環境変数にマッピングするための推奨方法
  name: display_secret_values
```

### 複数のジョブでシークレットを使用

この例では、Keeperからパスワードとファイルを取得し、別のジョブで利用します。

```yaml
trigger:
- master

pool:
  vmImage: ubuntu-latest

jobs:
- job: ksmSecrets
  displayName: "Inject KSM Secrets"

  steps:

  - task: ksmazpipelinetask@1
    name: setKsmSecretsStep
    inputs:
      keepersecretconfig: $(sm-config)
      secrets: |
        6ya_fdc6XTsZ7i7x9Jcodg/field/password > var:var_password
        6ya_fdc6XTsZ7i7x9Jcodg/field/password > out:out_password
        6ya_fdc6XTsZ7i7x9Jcodg/field/password > out_password2
        6ya_fdc6XTsZ7i7x9Jcodg/file/mykey.pub > file:/tmp/public_key.pem
        6ya_fdc6XTsZ7i7x9Jcodg/file/mykey.pem > file:/tmp/private_key.pem

  - bash: |
      echo "Using an input-macro works                : $(var_password)"
      echo "Using an output variable (default method) : $(setKsmSecretsStep.out_password2)"
      echo "Using an output variable                  : $(setKsmSecretsStep.out_password)"
      echo "Using the mapped env var                  : $MY_MAPPED_ENV_VAR_PASSWORD"
      echo "Check injected secret file                : $(file /tmp/public_key.pem)"
    env:
      MY_MAPPED_ENV_VAR_PASSWORD: $(var_password) # 環境変数にマッピングするための推奨方法
    name: display_secret_values

  - bash: |
      cat << EOF > decrypted.txt
      This is a decrypted message
      EOF
    name: create_text_file

  - bash: cat decrypted.txt
    name: view_decrpyted_content


  - bash: openssl rsautl -encrypt -inkey /tmp/public_key.pem -pubin -in decrypted.txt -out ecrypted.bin
    name: encrypte_file

  - bash: cat ecrypted.bin
    name: view_encrpyted_content

  - bash: openssl rsautl -decrypt -inkey /tmp/private_key.pem -in ecrypted.bin -out decrypted2.txt
    name: decrpyt_content

  - bash: cat decrypted2.txt
    name: view_decrpyted2_content


- job: encryptFileTest
  dependsOn: ksmSecrets
  variables:
    # ジョブAの出力変数をこのジョブにマッピング
    # 注意:
    # ジョブ間でファイルを共有できないため、各エージェントは一度に1つのジョブしか実行できません。
    # 1つのジョブは独立した実行単位であり、異なるジョブ間で通信するには
    # 変数や中間生成物などの「ミドルウェア」を使用する必要があります。
    pwdFromKsmSecrets: $[ dependencies.ksmSecrets.outputs['setKsmSecretsStep.out_password'] ]

  steps:
    - bash: |
        echo "password retrieved from job 'ksmSecrets', step 'pwdFromKsmSecrets', out variable 'setKsmSecretsStep.out_password':$(pwdFromKsmSecrets)"
```


---

# 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/azure-devops-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.
