# シークレットマネージャー共有コマンド

### 概要

**レコードまたはフォルダ** (シークレット) のうち、Keeperシークレットマネージャーアプリがアクセスできるものを制御します。

* ユーザーは、このコマンドでアプリとシークレットをリンクして共有します。
* アプリに**読み取り専用**または**編集可能**でアクセスさせるかも選択できます。

### 対応コマンド

* [シークレットマネージャー共有コマンド](#secrets-manager-share)
* [シークレットマネージャー共有解除コマンド](#secrets-manager-unshare)

### シークレット共有コマンド

このコマンドは、ボルトのフォルダまたはレコードをKeeperシークレットマネージャーアプリケーションに関連付け、当該シークレットへのアプリのアクセスを付与します。

<details>

<summary>DotNet CLI</summary>

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

**アクション:** `share`

**フラグ:**

* `--folder` : 共有フォルダのUIDまたは名前。「share」「unshare」のみ
* `-e, --can-edit` : シークレットを編集できるか。「share」「unshare」のみ
* `--help` : このヘルプ画面を表示します。
* `--version` : バージョン情報を表示します。
* `value pos. 0` : KSMコマンド: "view", "create", "delete", "share", "unshare", "add-client",\
  "delete-client", "list", "app-share", "app-unshare"
* `value pos. 1` : シークレットマネージャーアプリケーションのUIDまたはタイトル

**例:**

```bash
My Vault > ksm share ksm_app_uid --folder folder_uid
  Application UID: ksm_app_uid
               Title: Test_Example Application

Shares
  #  Share Type    Share UID               Share Title                    Editable  Created           
---  ------------  ----------------------  -----------------------------  --------  ------------------
  1  SharedFolder  ksm_app_uid             Example Resources                 X         5/2/2025 9:53 AM

Devices
  #  Name                  Device ID  Created             Last Accessed     
---  --------------------  ---------  ------------------  ------------------
  1  Example Application    4xeebo     5/2/2025 9:53 AM    7/8/2025 10:56 AM  
```

</details>

<details>

<summary>DotNet SDK</summary>

**メソッド:** `ShareToSecretManagerApplication`

```csharp
 Task<SecretsManagerApplication> ShareToSecretManagerApplication(string applicationId,
            string sharedFolderOrRecordUid, bool canEdit);
```

**引数:**

`applicationId` - フォルダまたはレコードを共有する先のKSMアプリケーションのIDです。

`sharedFolderOrRecordUid` - レコードまたは共有フォルダのIDです。

`canEdit` - 編集権限を付与するかどうかを示すブール値です。

</details>

<details>

<summary>PowerCommander</summary>

**コマンド:** `Grant-KeeperSecretsManagerFolderAccess`

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

**フラグ:**

* `-App` : アプリケーションのUID
* `-Secret` : シークレット/レコード/フォルダのUID

**例:**

```powershell
PS > Grant-KeeperSecretManagerFolderAccess -App ksm_app_uid  -Secret record_uid   

Uid                    Title                    IsExternalShare DeviceCount ShareCount
---                    -----                    --------------- ----------- ----------
ksm_app_uid            Example Application         False           7           6
```

</details>

<details>

<summary>Python CLI</summary>

**コマンド**: `secret-manager-share --command=<add/remove>`

**パラメーター**:

* `--command` 追加または削除
* `-a` `--app` アプリケーション名またはUID
* `-s` `--secret` レコードUID（スペース区切り。例: "uid1 uid2 uid3"）

**オプション**:

* -e --editable この共有を編集可能にするかどうかです。

**例:**

```sh
My Vault> secrets-manager-share --command='add' -e -a='ksm_uid' -s='record_uid'

Successfully added secrets to app uid=ksm_uid, editable=True:
record_uid  Record
Share updates processed successfully
My Vault>
```

</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}")

added = ksm_management.KSMShareManagement.add_secrets_to_ksm_app(
    vault=vault,
    enterprise=enterprise_data,
    app_uid=app_uid,
    master_key=master_key,
    secret_uids=secret_uids,
    is_editable=is_editable,
)
print(f"Added {len(added)} secret(s) to KSM app '{app_uid_or_name}' (editable={is_editable}):")
for secret_uid, secret_type in added:
    print(f"  {secret_uid}  ({secret_type})")
```

</details>

### シークレット共有解除コマンド

このコマンドは、以前に共有したフォルダまたはレコードをKeeperシークレットマネージャーアプリケーションから外し、そのシークレットへのアクセスを取り消します。

<details>

<summary>DotNet CLI</summary>

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

**アクション:** `unshare`

**フラグ:**

* `--folder` : 共有フォルダのUIDまたは名前。「share」「unshare」のみ
* `-e, --can-edit` : シークレットを編集できるか。「share」「unshare」のみ
* `value pos. 1` : シークレットマネージャーアプリケーションのUIDまたはタイトル

**例:**

```bash
My Vault > ksm unshare ksm_app_uid --folder folder_uid
  Application UID: ksm_app_uid
               Title: Test_Example Application

Shares
  #  Share Type    Share UID               Share Title                    Editable  Created           
---  ------------  ----------------------  -----------------------------  --------  ------------------

Devices
  #  Name                  Device ID  Created             Last Accessed     
---  --------------------  ---------  ------------------  ------------------
  1  Example Application    4xeebo     5/2/2025 9:53 AM    7/8/2025 10:56 AM    
```

</details>

<details>

<summary>DotNet SDK</summary>

**メソッド:** `UnshareFromSecretManagerApplication`

```csharp
Task<SecretsManagerApplication> UnshareFromSecretManagerApplication(string applicationId,
            string sharedFolderOrRecordUid);
```

**引数:**

`applicationId` - フォルダまたはレコードの共有を解除する先のKSMアプリケーションのIDです。

`sharedFolderOrRecordUid` - 権限を取り消すレコードまたは共有フォルダのIDです。

</details>

<details>

<summary>PowerCommander</summary>

**コマンド**: `Revoke-KeeperSecretManagerFolderAccess`

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

**フラグ**:

* `-App` : アプリケーションのUID
* `-Secret` : シークレット/レコード/フォルダのUID

**例:**

```powershell
PS > Revoke-KeeperSecretManagerFolderAccess -App ksm_app_uid  -Secret record_uid 

Uid                    Title                    IsExternalShare DeviceCount ShareCount
---                    -----                    --------------- ----------- ----------
ksm_app_uid            Example Application         False           7           5
```

</details>

<details>

<summary>Python CLI</summary>

**コマンド**: `secrets-manager-share --command=<add/remove>`

**パラメーター**:

* `--command` 追加または削除
* `-a` `--app` アプリケーション名またはUID
* `-s` `--secret` レコードUID（スペース区切り。例: "uid1 uid2 uid3"）

**例:**

```sh
My Vault> secrets-manager-share --command='remove' -a='ksm_uid' -s='record_uid'
Shared secrets were successfully removed from the application
```

</details>

<details>

<summary>Python SDK</summary>

**関数:**

```python
ksm_management.KSMShareManagement.remove_secrets_from_ksm_app(
    vault=vault,
    app_uid=app_uid,
    secret_uids=secret_uids,
)
```

</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-share-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.
