# 1Password から CircleCI にシークレットをロードする

[CircleCI用の1Password Secrets Orb](https://circleci.com/developer/orbs/orb/onepassword/secrets)を使用[、シークレット参照](https://developer.1password.com/docs/cli/secret-reference-syntax)を使用して、1Password から CircleCI CI/CD パイプラインにシークレットを安全に読み込むことができます。シークレット参照は 1Password と自動的に同期され、コード内のプレーンテキストのシークレットが公開されるリスクがなくなります。

[CircleCI orbs](https://circleci.com/docs/orb-intro/)はYAML 構成ファイルを含むパッケージです。Orb を使うと、1 行のコードでこれらの構成を参照できます。

INFO

[1Password Secrets orb for CircleCI](https://github.com/1password/secrets-orb)によって公式にサポートおよび管理されていますが、コミュニティからの貢献も歓迎します。

Orb は、[1Password Connect Server](https://developer.1password.com/docs/connect/)または[1Password Service Account](https://developer.1password.com/docs/service-accounts/)で使用できます。CircleCI および Docker で 1Password Service Account を使う方法の簡単な紹介については、以下のビデオをご覧ください。

<https://www.youtube.com/watch?embeds_referring_euri=https%3A%2F%2Fdeveloper.1password.com%2Fdocs%2Fci-cd%2Fcircle-ci%2F&source_ve_path=Mjg2NjQsMTY0NTAz&v=xnv5qBjfisU&feature=youtu.be>

### **Requirements** <a href="#id-1a1qpsihy3bl" id="id-1a1qpsihy3bl"></a>

1Password for CircleCI orb の使用を開始するための必要条件は、サービス アカウントを使うか Connect サーバーを使うかによって異なります。

**Service account**

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

* 1Passwordに[サインアップしてください。](https://start.1password.com/sign-up/plan)
* [サービス アカウントをCreateします。](https://developer.1password.com/docs/service-accounts/)
* [CircleCI](https://circleci.com/)アカウントをCreateする

**Connect**

* 1Passwordに[サインアップしてください。](https://start.1password.com/sign-up/plan)
* [Connect サーバーをCreateして展開します。](https://developer.1password.com/docs/connect/get-started/#step-2-deploy-1password-connect-server)
* [CircleCI](https://circleci.com/)アカウントをCreateする。

注意

接続資格情報はサービス アカウント資格情報よりも優先されます。

OP\_CONNECT\_HOSTまたはOP\_CONNECT\_TOKEN環境変数を と一緒に設定した場合OP\_SERVICE\_ACCOUNT\_TOKEN、Connect 認証情報は提供されたサービス アカウント トークンよりも優先されます。アクションがサービス アカウント トークンを使うようにするには、Connect 環境変数を設定解除する必要があります。

### **Get started** <a href="#swtk7bmjfpj6" id="swtk7bmjfpj6"></a>

**Service account**

* **サービスアカウント**
* ①CircleCI でサービス アカウント トークン環境変数を設定します。\
  [CircleCIの設定ページ](https://circleci.com/docs/introduction-to-the-circleci-web-app/#project-settings)で、OP\_SERVICE\_ACCOUNT\_TOKENシークレットをロードするために使うサービス アカウントのトークンに環境変数を設定します。
* ②CircleCI 構成ファイルを編集し、次の更新を行います。
  * 1Password for CircleCI orb を使うには[CircleCIconfig.ymlファイル](https://circleci.com/docs/config-intro/)を更新する。
  * バージョン番号を指定するか、volatile最新のバージョン番号を使用します。
* config.ymlファイルにonepassword/secrets orb を追加します。

config.yml

![](https://4200399111-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8GVOyHz3wUSpdV3qlPwR%2Fuploads%2FiLMcf5WFxypH5XEQaajz%2F0.png?alt=media)

プロジェクトで*最新*バージョンの 1Password Secrets orb を使うには、volatileバージョン番号として設定します。

config.yml

![](https://4200399111-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8GVOyHz3wUSpdV3qlPwR%2Fuploads%2FCejC4VqmAa2nT2E9ilID%2F1.png?alt=media)

③1password/install-cli[コマンド](https://developer.1password.com/docs/ci-cd/circle-ci/?workflow-type=service-account#commands)を使用して、CircleCI ジョブの最初のステップとして1Password CLI バージョン**2.18.0 以降**をインストールします。1Password CircleCI orb が機能するには、パイプラインに CLI をインストールする必要があります。1Password CLI の以前のバージョンでは、サービス アカウントはサポートされていません。

[1Password CLI リリース ノート](https://app-updates.agilebits.com/product_history/CLI2)で最新のバージョン番号を確認してください。

config.yml

![](https://4200399111-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8GVOyHz3wUSpdV3qlPwR%2Fuploads%2F0ZtnhAa0ArIjROgHJulz%2F2.png?alt=media)

④パイプラインの後続のステップで 1Password CLI コマンドを使用します。

次のサンプル ファイルを参照してください。1Password [CLI バージョン 2.18.0 以降](https://app-updates.agilebits.com/product_history/CLI2)にconfig.yml更新してください。2.x.x

**Example 1**

![](https://4200399111-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8GVOyHz3wUSpdV3qlPwR%2Fuploads%2FS2MDiUJkJ6ZaOSmR5WkS%2F3.png?alt=media)

**Example 2**

config.yml

description: Install 1Password CLI within a job and make it useable for all the commands following the installation.

usage:

version: 2.1

orbs:

1password: onepassword/secrets\@1.0.0

jobs:

deploy:

machine:

image: ubuntu-2204:current

steps:

\- 1password/install-cli:

version: 2.x.x

\- checkout

\- run: |

docker login -u $(op read op\://company/docker/username) -p $(op read op\://company/docker/password)

docker build -t company/app:${CIRCLE\_SHA1:0:7} .

docker push company/app:${CIRCLE\_SHA1:0:7}

workflows:

deploy:

jobs:

\- deploy

**Connect**

①CircleCI で Connect サーバー環境変数を設定します。

[CircleCIの設定ページ](https://circleci.com/docs/introduction-to-the-circleci-web-app/#project-settings)で、Connect サーバーがシークレットをロードするために使うOP\_CONNECT\_HOSTおよび環境変数を設定します。OP\_CONNECT\_TOKEN

* OP\_CONNECT\_TOKENConnect サーバー トークンに設定します。
* OP\_CONNECT\_HOSTConnect サーバーのホスト名または IP アドレスを設定します。

②CircleCI 構成ファイルを編集します。

1Password for CircleCI orb を使うために[CircleCIconfig.ymlファイル](https://circleci.com/docs/config-intro/)を更新します。必ずバージョン番号を指定するか、volatile最新のバージョン番号を使用してください。

config.ymlファイルにonepassword/secrets orb を追加します。

![](https://4200399111-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8GVOyHz3wUSpdV3qlPwR%2Fuploads%2F1qwQytXC54vsrxCt4QgA%2F4.png?alt=media)

プロジェクトで*最新*バージョンの 1Password Secrets orb を使うには、volatileバージョン番号として設定します。

![](https://4200399111-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8GVOyHz3wUSpdV3qlPwR%2Fuploads%2F8kkLbh1YBgCTfE9fd7FT%2F5.png?alt=media)

①1Password CLI をインストールします。

1Password CircleCI orb が機能するには、パイプラインに[1Password CLI を](https://developer.1password.com/docs/cli/)インストールする必要があります。

* 1password/install-cli [コマンド](https://developer.1password.com/docs/ci-cd/circle-ci/?workflow-type=connect\&install-example=example-1#commands)を使用して、CircleCI ジョブの最初のステップとして CLI をインストールします。
* パイプラインの後続のステップで 1Password CLI コマンドを使用します。

次のサンプルconfig.ymlファイルを参照してください。

**Example 1**

**例1**

![](https://4200399111-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8GVOyHz3wUSpdV3qlPwR%2Fuploads%2FlWisp0sclN9REs0WR2U5%2F6.png?alt=media)

**Example 2**

config.yml

description: Install 1Password CLI within a job and make it useable for all the commands following the installation.

usage:

version: 2.1

orbs:

1password: onepassword/secrets\@1.0.0

jobs:

deploy:

machine:

image: ubuntu-2204:current

steps:

\- 1password/install-cli

\- checkout

\- run: |

docker login -u $(op read op\://company/docker/username) -p $(op read op\://company/docker/password)

docker build -t company/app:${CIRCLE\_SHA1:0:7} .

docker push company/app:${CIRCLE\_SHA1:0:7}

workflows:

deploy:

jobs:

\- deploy

### **Reference** <a href="#id-3h7e3e6m752i" id="id-3h7e3e6m752i"></a>

次のセクションでは、1Password for CircleCI orb[コマンド](https://developer.1password.com/docs/ci-cd/circle-ci/?workflow-type=connect\&install-example=example-1#commands)と[シークレット参照構文](https://developer.1password.com/docs/ci-cd/circle-ci/?workflow-type=connect\&install-example=example-1#secret-reference-syntax)について説明します。

#### &#x20;<a href="#id-20n7o6woco9y" id="id-20n7o6woco9y"></a>

#### **Commands** <a href="#fqrtvm5kb6l6" id="fqrtvm5kb6l6"></a>

Orb を設定するときに使うコマンドは 3 つあります: 1password/install-cli、1password/exec、および 1password/export。

注意

一部のコマンドのみがシークレットをマスクします。

1password/execorb コマンドとシェル ラッパーは両方とも、[op run](https://developer.1password.com/docs/cli/reference/commands/run/)CircleCI ログ出力からシークレットを自動的にマスクします。シークレットが誤ってログに記録された場合、1Password はそれを に置き換えます\<concealed by 1Password>。1password/exportコマンドはシークレットをマスクしません。

![](https://4200399111-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8GVOyHz3wUSpdV3qlPwR%2Fuploads%2FTRrLDV29luMxourGOu0R%2F7.png?alt=media)

#### **Secret reference syntax** <a href="#liqq6z7thtc2" id="liqq6z7thtc2"></a>

シークレット参照構文を使用して環境にシークレットへの参照を含めることで、CircleCI ジョブとステップでシークレットを利用できるようになります。シークレット参照構文は、保管庫名、アイテム名、セクション名、フィールド名を指定して特定の 1Password シークレットを指す 1Password URI です。

![](https://4200399111-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8GVOyHz3wUSpdV3qlPwR%2Fuploads%2F5CTZPQ9F9Rozrg5mrXPt%2F8.png?alt=media)

[シークレット参照構文](https://developer.1password.com/docs/cli/secret-reference-syntax/)のドキュメントにアクセスして例にアクセスし、シークレットの参照について詳しく学習してください。

### **Usage examples** <a href="#w2l5f9obcznw" id="w2l5f9obcznw"></a>

1Password CircleCI orb の具体的な使用例については、次のセクションをご覧ください。

* [シークレットをロードするexec](https://developer.1password.com/docs/ci-cd/circle-ci/?workflow-type=connect\&install-example=example-1#load-exec)
* [シークレットをロードするexport](https://developer.1password.com/docs/ci-cd/circle-ci/?workflow-type=connect\&install-example=example-1#load-export)

#### **Load secrets with the exec command** <a href="#ddiaox9wo6vx" id="ddiaox9wo6vx"></a>

1password/exec コマンドを使用してシークレットをロードするには:

①1password/install-cliを使用して 1Password CLI をインストールします。サービス アカウントを使用している場合は、 [1Password CLI のバージョン](https://app-updates.agilebits.com/product_history/CLI2)2.18.0を以降に設定してください。

②1password/execコマンドを使用して、必要に応じてシークレットをロードし、シークレットを必要とするコマンドを実行します。

ジョブのステップとして1password/execコマンドを追加すると、ジョブの後続のステップでシークレットにアクセスできるようになります。

次の例は、 1password/execコマンドを使用してジョブ レベルで変数を解決する方法を示しています。このexecコマンドは、誤ってログに記録される可能性のある秘密情報や機密値を自動的にマスクします。

![](https://4200399111-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8GVOyHz3wUSpdV3qlPwR%2Fuploads%2FKQ5KbY8o7ugrKobkHPTC%2F9.png?alt=media)

#### **Load secrets with the export command** <a href="#t9g0sipxifju" id="t9g0sipxifju"></a>

1password/export コマンドを使用してシークレットをロードするには:

①1password/install-cliを使用して 1Password CLI をインストールします。サービス アカウントを使用している場合は、 [1Password CLI のバージョン](https://app-updates.agilebits.com/product_history/CLI2)2.18.0を以降に設定してください。

②1password/exportコマンドを使用して、環境にエクスポートされた[シークレット参照](https://developer.1password.com/docs/ci-cd/circle-ci/?workflow-type=connect\&install-example=example-1#secret-reference-syntax)を読み込みます。

③ジョブの後続のステップでシークレットにアクセスします。

次の例は、 1password/exportコマンドを使用してジョブ レベルで変数を解決する方法を示しています。

config.yml

![](https://4200399111-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8GVOyHz3wUSpdV3qlPwR%2Fuploads%2FWxMmVscZQsgbgb6Po4rX%2F10.png?alt=media)


---

# 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://manual.dxable.com/1password/load-secrets-from-1password-into-circleci.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.
