# シークレットマネージャークライアントコマンド

### 概要

クライアントとは、ワンタイムアクセストークンで認証し、紐付けられたアプリケーション経由でシークレットにアクセスする特定のデバイスです。

### 対応コマンド

* [シークレットマネージャークライアント追加コマンド](#secrets-manager-client-add)
* [シークレットマネージャークライアント削除コマンド](#secrets-manager-client-remove)

### クライアント追加コマンド

このコマンドは、新しいクライアント識別子を作成し、そのデバイス上でKeeperシークレットマネージャーSDKを安全に初期化するための **ワンタイムアクセストークン** を生成します。

<details>

<summary>DotNet CLI</summary>

**コマンド:** `ksm`

**アクション:**

`add-client` : 新しいデバイスを追加する、またはシークレットマネージャーアプリケーションに新しい構成を追加します。ユーザーはこのクライアント構成を使い、このアプリがアクセスできるシークレットマネージャーアプリケーションおよびボルトの該当部分にアクセスできるようになります。

**フラグ:**

* `--client-name` : クライアント名。「add-client」「remove-client」のみ
* `--unlock-ip` : IPアドレスのロックを解除するか。「add-client」のみ
* `--create-expire` : デバイス作成の有効期限 (分)。「add-client」のみ
* `--access-expire` : デバイスアクセスの有効期限 (分)。「add-client」のみ
* `--b64` : ワンタイムトークンの代わりにKSM構成を返す。「add-client」のみ
* `value pos. 1` : シークレットマネージャーアプリケーションのUIDまたはタイトル

**例:**

```shell
My Vault> ksm add-client ksm_app_uid --client-name "Example Client"
Successfully generated Client Device

One-Time Access Token: US:device_token
IP Lock: Enabled
Token Expires On: 9/1/2025 10:23:15 AM
App Access Expires On: Never
```

</details>

<details>

<summary>DotNet SDK</summary>

**メソッド:**

```csharp
public async Task<Tuple<SecretsManagerDevice, string>> AddSecretManagerClient(
            string applicationId, bool? unlockIp = null, int? firstAccessExpireInMinutes = null,
            int? accessExpiresInMinutes = null, string name = null)
```

**引数:**

`applicationId` - このデバイスをリンクする先のアプリケーションのUIDです。

`unlockIp` - コマンドで生成したクライアントデータを、初回利用時の単一IPに固定するか、構成を移行すれば任意のコンピューターから利用できるかを設定するフラグです。true にするとIPロックを解除します。

`firstAccessExpireInMinutes` - 未使用のまま経過すると構成が無効になるまでの時間 (分) を表す整数です。

`accessExpiresInMinutes` - この構成が無効化・期限切れになるまでの時間 (分) を表す整数です。

`name` - シークレットマネージャーアプリケーションに保存されるクライアント名です。ウェブアプリ/UIのボルト内のシークレットマネージャーアプリに表示されます。

</details>

<details>

<summary>PowerCommander</summary>

**コマンド** : `Add-KeeperSecretManagerClient`

**エイリアス :** `ksm-addclient`

**フラグ** :

* `-App` : アプリケーションのUID
* `-Name` : デバイス名
* `-UnlockIP` : IPアドレスのロックを解除する
* `-B64` : ワンタイムトークンの代わりにKSM構成を返す。「add-client」のみ

**例:**

```powershell
PS > Add-KeeperSecretManagerClient -App ksm_app_uid -Name "Example Device"               
US:device_token
```

</details>

<details>

<summary>Python CLI</summary>

**コマンド:** `secrets-manager-client`

**パラメーター:**

* `--command` 追加または削除
* `-a` `--app` アプリケーション名またはUID
* `-n` `--name` クライアント名
* `-c` `--count` トークン数。既定は1
* `-s` `--secret` KSMアプリに追加されたレコードUID
* `-x` `--first-access-expires-in-min`

このコマンド実行時点から、最初のリクエストが期限切れになるまでの時間 (分)。

最大1440分（24時間）。既定は60分。

* `-p` `--access-expire-in-min`

このクライアントがKSMアプリケーションにアクセスできる時間 (分)。

この時間を過ぎるとアクセスは拒否されます。コマンド実行時点からの経過分で指定します。

**オプション:**

* `-f` `--force` 確認プロンプトを省略します。
* `-l` `--unlock-ip` クライアントにアクセスできるIPアドレスのロックを解除します。
* `--return-tokens` デバイストークンを返します。

**例:**

```sh
My Vault> secrets-manager-client --command add --app="ksm_app_uid" --name "test client"

Successfully generated Client Device
====================================

One-Time Access Token: US:access_token
Name: test client
IP Lock: Enabled
Token Expires On: 2025-11-05 16:20:14
App Access Expires on: Never
Warning: Configuration is now locked to your current IP. To keep in unlock you can add flag `--unlock-ip` or use the One-time token to generate configuration on the host that has the IP that needs to be locked.

```

</details>

<details>

<summary>Python SDK</summary>

**関数:**

```python
master_key = vault.vault_data.get_record_key(record_uid=app_uid)
if not master_key:
    raise ValueError(f"Could not retrieve app key for application {app_uid}")

server = keeper_auth_context.keeper_endpoint.server
current_time_ms = int(time.time() * MILLISECONDS_PER_SECOND)
first_access_expire_duration_ms = (
    current_time_ms + first_access_expires_in_minutes * MILLISECONDS_PER_MINUTE
)
access_expire_in_ms = (
    access_expire_in_minutes * MILLISECONDS_PER_MINUTE
    if access_expire_in_minutes else None
)

for i in range(count):
    result = ksm_management.KSMClientManagement.add_client_to_ksm_app(
        vault=vault,
        uid=app_uid,
        client_name=client_name or "",
        count=count,
        index=i,
        unlock_ip=unlock_ip,
        first_access_expire_duration_ms=first_access_expire_duration_ms,
        access_expire_in_ms=access_expire_in_ms,
        master_key=master_key,
        server=server,
    )
    print(result["output_string"])
    if result.get("token_info"):
        print(f"  One-Time Token: {result['token_info'].get('oneTimeToken', '')}")
```

</details>

### クライアント削除コマンド

このコマンドは、クライアント登録を削除することで、デバイスのシークレットへのアクセスを取り消します。

<details>

<summary>DotNet CLI</summary>

**コマンド:** `ksm`

**アクション:** `delete-client`

**フラグ:**

* `--client-name` : クライアント名。「add-client」「remove-client」のみ
* `--b64` : ワンタイムトークンの代わりにKSM構成を返す。「add-client」のみ
* `value pos. 1` : シークレットマネージャーアプリケーションのUIDまたはタイトル

**例:**

```bash
My Vault> ksm delete-client ksm_app_uid --client-name "Example Client"
Client "Example Client" has been deleted from application Test_Gateway Application
```

</details>

<details>

<summary>DotNet SDK</summary>

**メソッド:**

```csharp
public async Task DeleteSecretManagerClient(string applicationId, string deviceId)
```

**引数:**

`ApplicationId` : KSMアプリのID

`deviceId` : KSMデバイス構成のID

**例:**

```csharp
var applicationId = "<AppId>";
var deviceId = "<deviceId>";
await vault.DeleteSecretManagerClient(applicationId, deviceId);
```

</details>

<details>

<summary>PowerCommander</summary>

**コマンド:** `Remove-KeeperSecretManagerClient`

**エイリアス :** `ksm-rmclient`

**フラグ:**

* `-App` : アプリケーションのUID
* `-Name` : デバイス名
* `-WhatIf`
* `-Confirm`

**例:**

```powershell
PS > Remove-KeeperSecretManagerClient -App ksm_app_uid -Name "Example Device" -Confirm

Confirm
Are you sure you want to perform this action?
Performing the operation "Removing KSM Device 'Example Device'" on target "Test_Gateway Application".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): Y
```

</details>

<details>

<summary>Python CLI</summary>

**コマンド:** `secrets-manager-client`

**パラメーター:**

* `--command` 追加または削除
* `-i` `--client` 削除するクライアントのID。`secrets-manager-app get` でクライアント一覧を取得して確認します。

**オプション**:

* `-f` `--force` 確認プロンプトを省略します。

**例:**

```sh
My Vault> secrets-manager-client --command remove --app="ksm-app-uid" -i "client-uid"
Are you sure you want to delete 1 matching client(s) from this application? [y/n]: y

Client removal was successful

My Vault>
```

</details>

<details>

<summary>Python SDK</summary>

**関数:**

```python
ksm_management.KSMClientManagement.remove_clients_from_ksm_app(
    vault=vault,
    uid=app_uid,
    client_names_and_ids=client_ids, ##only client ids are supported
    callable=confirm_remove,
)
```

</details>


---

# 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/commander-sdk/keeper-commander-sdks/sdk-command-reference/secrets-manager-commands/secrets-manager-client-commands.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.
