# 1Password CLIでサービスアカウントを使う

### **1Password CLIでサービスアカウントを使う** <a href="#ujk884owui03" id="ujk884owui03"></a>

1Password CLIで1Passwordサービスアカウントを使用して、保管庫とアイテムを管理できます。[サポートされているコマンド](https://developer.1password.com/docs/service-accounts/use-with-1password-cli/#supported-commands)を参照してください。

### **必要条件** <a href="#cdjgpxjy4sr6" id="cdjgpxjy4sr6"></a>

1Password CLIでサービスアカウントを使う前に、次の操Createを行う必要があります。

* [1Passwordにサインアップしてください。](https://1password.com/pricing)
* [1Password CLI](https://developer.1password.com/docs/cli/get-started/)をインストールします。\
  サービスアカウントには1Password CLIバージョン2.18.0以降が必要です。
* [サービスアカウントをCreateします。](https://developer.1password.com/docs/service-accounts/get-started/#create-a-service-account)

### **始めましょう** <a href="#lhtnhfnxwnhs" id="lhtnhfnxwnhs"></a>

1Password CLIでサービスアカウントを使うには以下のように操Createします。

1. OP\_SERVICE\_ACCOUNT\_TOKEN環境変数をサービスアカウントトークンに設定します。\
   Bash、sh、zshの場合\
   $ export OP\_SERVICE\_ACCOUNT\_TOKEN=\<your-service-account-token>

Fishの場合\
$ set -x OP\_SERVICE\_ACCOUNT\_TOKEN \<your-service-account-token>

PowerShellの場合\
$ $Env:OP\_SERVICE\_ACCOUNT\_TOKEN = "\<your-service-account-token>"

1. 次のコマンドを実行して、サービスアカウントが構成されていることを確認します。\
   $ op user get --me\
   結果の例：

* ID: \<service-account-id>
* Name: \<service-account-name>
* Email: \<service-account-email>
* State: ACTIVE
* Type: SERVICE\_ACCOUNT
* Created: 2 minutes ago
* Updated: 2 minutes ago
* Last Authentication: now

⚠️注意\
1Password CLIが[1Password Connect](https://developer.1password.com/docs/connect/)と連携するように設定されている場合、環境変数OP\_CONNECT\_HOSTとOP\_CONNECT\_TOKENが、OP\_SERVICE\_ACCOUNT\_TOKENよりも優先されます。

代わりにサービスアカウントを構成するには、Connect環境変数をクリアします。

#### **サポートされているコマンド** <a href="#plwpwzvh9o4m" id="plwpwzvh9o4m"></a>

サービスアカウントとして認証された、サポートされている1Password CLIコマンドを実行できるようになりました。

* [op read](https://developer.1password.com/docs/cli/reference/commands/read/)
* [op inject](https://developer.1password.com/docs/cli/reference/commands/inject/)
* [op service-account ratelimit](https://developer.1password.com/docs/cli/reference/management-commands/service-account#ratelimit)
* [op run](https://developer.1password.com/docs/cli/reference/commands/run/)
* [op vault create](https://developer.1password.com/docs/cli/reference/management-commands/vault/#vault-create)

次のコマンドを使う際に、サービスアカウントが複数の保管庫にアクセスできる場合は、--vaultフラグを使って対象の保管庫を指定する必要があります。

* [op item](https://developer.1password.com/docs/cli/reference/management-commands/item/)
* [op document](https://developer.1password.com/docs/cli/reference/management-commands/document/)

次のコマンドは、サービスアカウントによってCreateされた保管庫に対してのみサポートされます。

* [op vault delete](https://developer.1password.com/docs/cli/reference/management-commands/vault/#vault-delete)
* [op vault user grant](https://developer.1password.com/docs/cli/reference/management-commands/vault/#vault-user-grant)
* [op vault group grant](https://developer.1password.com/docs/cli/reference/management-commands/vault/#vault-group-grant)
* [op vault group revoke](https://developer.1password.com/docs/cli/reference/management-commands/vault/#vault-group-revoke)<br>

詳細

サポートされていないコマンドサービスアカウントを使う場合、次のコマンドはサポートされません。

* [op group](https://developer.1password.com/docs/cli/reference/management-commands/group/)
* [op user provision](https://developer.1password.com/docs/cli/reference/management-commands/user/#user-provision)
* [op user confirm](https://developer.1password.com/docs/cli/reference/management-commands/user/#user-confirm)
* [op user suspend](https://developer.1password.com/docs/cli/reference/management-commands/user/#user-suspend)
* [op user delete](https://developer.1password.com/docs/cli/reference/management-commands/user/#user-delete)
* [op events-api](https://developer.1password.com/docs/cli/reference/management-commands/events-api/)
* [op vault edit](https://developer.1password.com/docs/cli/reference/management-commands/vault/#vault-edit)
* [op vault user grant](https://developer.1password.com/docs/cli/reference/management-commands/vault/#vault-user-grant)
* [op vault user revoke](https://developer.1password.com/docs/cli/reference/management-commands/vault/#vault-user-revoke)

サービスアカウントは一部のユーザー／グループ／Vault管理コマンドをサポートしていますが、完全なプロビジョニングワークフローはサポートされていないため、使用しないことをお勧めします。

* [op user get](https://developer.1password.com/docs/cli/reference/management-commands/user/#user-get)
* [op user list](https://developer.1password.com/docs/cli/reference/management-commands/user/#user-list)
* [op group get](https://developer.1password.com/docs/cli/reference/management-commands/group/#group-get)
* [op group list](https://developer.1password.com/docs/cli/reference/management-commands/group/#group-list)
