# Azure DevOps拡張機能

<figure><img src="https://859776093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPL6k1aGsLiFiiJ3Y7zCl%2Fuploads%2F6RQ89SOF7kIEZNMeee7C%2Fimage.png?alt=media&#x26;token=7e5663ee-583f-4bb8-8525-ae61b398fd9f" alt=""><figcaption></figcaption></figure>

## 機能

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

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

## 前提条件

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

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

## インストール

### Keeper Secrets Manager拡張機能のインストール

[こちらの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)にてソースコードをご覧いただけます。

<figure><img src="https://859776093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPL6k1aGsLiFiiJ3Y7zCl%2Fuploads%2FooKwWAPT5xprIDoHrWUo%2Fimage.png?alt=media&#x26;token=6006b804-a859-4152-8ce0-ad155c4caeac" alt=""><figcaption></figcaption></figure>

組織を選択して「ダウンロード（Download）」をクリックし、Azure組織の拡張機能を有効にします。

<figure><img src="https://859776093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPL6k1aGsLiFiiJ3Y7zCl%2Fuploads%2FeYJQjdiDUrA9ur2U7scc%2Fimage.png?alt=media&#x26;token=73bd690a-84d4-432b-bef8-8c1f6e14224b" alt=""><figcaption></figcaption></figure>

## Azureパイプラインからシークレットにアクセス

Keeperボルトのシークレットにアクセスするには、AzureパイプラインのYAML設定ファイルにタスクを追加します。 次に、目的のフィールドを取得するため記録を照会します。

### Keeper Secrets Managerのタスクを作成

Keeper Secrets Managerのタスクは以下のようになります。

```
- 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」を検索し、タスクフォームを開きます。

<figure><img src="https://859776093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPL6k1aGsLiFiiJ3Y7zCl%2Fuploads%2F3t6bDACOpSI6W1jQCXqp%2Fimage.png?alt=media&#x26;token=d3a50c66-d0de-46cd-b76d-ca289c19e500" alt=""><figcaption></figcaption></figure>

タスクフォームに入力し、Keeper Secrets Managerタスクを作成するために必要なものは以下のとおりです。

* [Keeper Secrets Managerの設定](https://docs.keeper.io/jp/keeperpam/secrets-manager/about/secrets-manager-configuration)
  * Azure DevOps拡張機能では、JSONとBase64の設定を使用できます。
* 1つまたは複数の[シークレットのクエリ](#keeper-secret-queries)（以下のクエリ構文を参照）

<figure><img src="https://859776093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPL6k1aGsLiFiiJ3Y7zCl%2Fuploads%2FTdvcVylLbUWBCoZ1jHO5%2Fimage.png?alt=media&#x26;token=e7888249-1317-4c0e-8fa4-ff7041536498" alt=""><figcaption></figcaption></figure>

Keeper Secrets Managerの設定をパイプラインにコピーするだけでも構いませんが、Azureパイプラインからアクセス可能なAzure Key VaultにSecrets Managerの設定を保管することをお勧めします。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 Secretクエリ <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: 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/jp/keeperpam/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.
