> For the complete documentation index, see [llms.txt](https://manual.dxable.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://manual.dxable.com/1password/secret-reference-syntax.md).

# シークレット参照の構文

シークレット参照 URI は、情報がSaveされている保管庫、アイテム、セクション、フィールドの名前を使用して、1Password アカウント内でシークレットがSaveされている場所を指します。

```
$ op://<vault-name>/<item-name>/[section-name/]<field-name>
```

シークレット参照により、コード内のプレーンテキストのシークレットが公開されるリスクがなくなり、1Password アカウントに加えた変更が反映されるため、スクリプトを実行すると最新の値が得られます。

シークレット参照は次の場合に使用できます。

<table data-view="cards"><thead><tr><th></th><th></th><th></th></tr></thead><tbody><tr><td><h4 id="id-6k93fifd5yc2"><strong>1Password CLI</strong></h4></td><td>環境変数、構成ファイル、スクリプトにシークレットを読み込みます。</td><td><a href="https://developer.1password.com/docs/cli/secret-references/">もっと詳しく知る</a></td></tr><tr><td><h4 id="d4a5516mn945"><strong>1Password SDK</strong></h4></td><td>Go、JavaScript、Python を使用してプログラム的にシークレットにアクセスします。</td><td><a href="https://developer.1password.com/docs/sdks/">もっと詳しく知る</a></td></tr><tr><td><h4 id="nqxd4lhuf3y6"><strong>シークレットオートメーション</strong></h4></td><td>シークレット参照を使用して、シークレット管理ワークフローを保護します。</td><td><a href="https://developer.1password.com/docs/secrets-automation/">もっと詳しく知る</a></td></tr><tr><td><h4 id="tn1dgk1lh57s"><strong>VSコード</strong></h4></td><td>コード内のシークレット参照をCreate・プレビュー・読み取りできます。</td><td><a href="https://developer.1password.com/docs/vscode/">もっと詳しく知る</a></td></tr><tr><td><h4 id="lkb07zatqhig"><strong>1Passwordの統合</strong></h4></td><td>Kubernetes、CircleCI、GitHub Actions、Jenkins、Terraform、Pulumi、Postmanなどのシークレットに安全にアクセスします。</td><td><a href="https://developer.1password.com/docs/vscode/">もっと詳しく知る</a></td></tr></tbody></table>

### **シークレット参照** <a href="#cvsa37f0irgn" id="cvsa37f0irgn"></a>

#### **1Passwordデスクトップアプリ** <a href="#zdfhp493lhq" id="zdfhp493lhq"></a>

1Password デスクトップ アプリでシークレット参照をコピーするオプションを表示するには、まず[1Password CLI との統合を](https://developer.1password.com/docs/cli/app-integration)オンにします。次に、次の手順を実行します。

①参照したいシークレットがSaveされているアイテムを開きます。\
②参照したいシークレットを含むフィールドの横にある<img src="/files/McbEUJzzWLuTIMjN3gM7" alt="" data-size="line">をクリックし、**Copy Secret Reference**を選択します。

<img src="/files/YpzOeQ00W0a8lbfZu041" alt="1Password で「シークレット参照のコピー」オプションが選択された項目。" width="375">

#### **With 1Password for VS Code** <a href="#id-5dee2yi75d47" id="id-5dee2yi75d47"></a>

1Password for VS Codeを使うと、コードを編集するときに1Passwordから[シークレット参照](https://developer.1password.com/docs/vscode/#get-values)を挿入できます。まず、[拡張機能をインストールします](https://developer.1password.com/docs/vscode/)。次に、次の手順を実行します。

①[Command Palette](https://code.visualstudio.com/api/ux-guidelines/command-palette)を開きます。

②1Password: `Get from 1Password` と入力します。

③アイテム名またはIDを入力します。

④使うフィールドを選択します。

#### **With 1Password CLI** <a href="#qiyfnct0htqr" id="qiyfnct0htqr"></a>

1Password CLIでシークレットリファレンスを取得するには、`--format json`フラグを付けて[`op item get`](https://developer.1password.com/docs/cli/reference/management-commands/item/#item-get)を実行し、フィールドラベルを指定する`--fields`フラグを含めます。次にJSON 出力からシークレット参照を取得するために[jq](https://jqlang.github.io/jq/)を使用します。例:

```
$ op item get GitHub --format json --fields username | jq .reference
```

<details>

<summary>結果を見る...</summary>

"op\://development/GitHub/username"

</details>

項目の全てのフィールドのシークレット参照を取得するには、フィールドを指定せずに `--format json` フラグを指定して[`op item get`](https://developer.1password.com/docs/cli/reference/management-commands/item/#item-get)を使用します。

<details>

<summary>JSON出力の例</summary>

```
op item get GitHub --format json
```

各フィールドオブジェクトには、`reference`そのシークレット参照を含むキーが含まれます。この例の`GitHub`アイテムの場合、出力は次のようになります。

```
"fields": [
{
"id": "username",
"type": "STRING",
"purpose": "USERNAME",
"label": "username",
"value": "wendy_appleseed@agilebits.com",
"reference": "op://development/GitHub/username"
},
{
"id": "password",
"type": "CONCEALED",
"purpose": "PASSWORD",
"label": "password",
"value": "GADbhK6MjNZrRftGMqto",
"entropy": 115.5291519165039,
"reference": "op://development/GitHub/password",
"password_details": {
"entropy": 115,
"generated": true,
"strength": "FANTASTIC"
}
},
{
"id": "notesPlain",
"type": "STRING",
"purpose": "NOTES",
"label": "notesPlain",
"reference": "op://development/GitHub/notesPlain"
},
{
"id": "5ni6bw735myujqe4elwbzuf2ee",
"section": {
"id": "hv46kvrohfj75q6g45km2uultq",
"label": "credentials"
},
"type": "CONCEALED",
"label": "personal_token",
"value": "ghp_WzgPAEutsFRZH9uxWYtw",
"reference": "op://development/GitHub/credentials/personal_token"
}
]
}
```

</details>

### **構文規則** <a href="#hwywise6rq0v" id="hwywise6rq0v"></a>

#### **サポートされている**[**文字**](https://developer.1password.com/docs/cli/secret-reference-syntax/#supported-characters) <a href="#a5xxdg2mswyb" id="a5xxdg2mswyb"></a>

シークレット参照では大文字と小文字が区別されず、次の文字がサポートされます。

* 英数字 ( `a-z`、`A-Z`、`0-9`)
* `-`、、`_`および`.`空白文字

シークレット参照に空白が含まれている場合は、シークレット参照を引用符で囲みます。例:

```
$ op read "op://development/aws/Access Keys/access_key_id"
```

サポートされていない文字を含むシークレット参照の部分は、名前ではなく[一意の識別子 (ID)](https://developer.1password.com/docs/cli/reference/#unique-identifiers-ids)で参照する必要があります。

ID を取得するには、[`op item get`](https://developer.1password.com/docs/cli/reference/management-commands/item#item-get)出力を JSON に設定して実行します。例えば、`test/`という名前のカスタム テキスト フィールドの ID を取得するには、次のようにします。

```
op item get PagerDuty --fields label=test/ --format json
```

<details>

<summary>結果を見る...</summary>

```
{
"id": "hu4vwo3bjkawq2uw2fkn5pkjzu",
"section": {
"id": "add more"
},
"type": "STRING",
"label": "text/",
"value": "t",
"reference": "op://Management/PagerDuty/add more/hu4vwo3bjkawq2uw2fkn5pkjzu"
}
```

</details>

**ファイルの添付**

添付ファイルを参照するには、フィールド名の代わりにファイル名を使用します。

```
$ op://vault-name/item-name/[section-name/]file-name
```

**外部設定変数**

異なる環境で異なるシークレット セットを使う場合は、シークレット参照内に変数を含め、シークレットを切り替えるように変数を設定できます。

例えば、資格情報が `dev` および `prod` という名前の 1Password コンテナーにSaveされていると仮定すると、以下の例の `APP_ENV` 変数を `dev` に設定して開発資格情報をロードしたり、 `prod` に設定して実稼働資格情報をロードしたりできます。

{% code title="アプリ.env" %}

```
MYSQL_DATABASE = "op://$APP_ENV/mysql/database"
MYSQL_USERNAME = "op://$APP_ENV/mysql/username"
MYSQL_PASSWORD = "op://$APP_ENV/mysql/password"
```

{% endcode %}

変数を使用して、[環境ファイル](https://developer.1password.com/docs/cli/secrets-environment-variables#step-3-differentiate-between-environments)と構成[ファイル](https://developer.1password.com/docs/cli/secrets-config-files#step-3-differentiate-between-environments)内のシークレットのセットを切り替える方法を学習します。

#### **フィールドとファイルのメタデータ属性** <a href="#f8xwmvhw5ofc" id="f8xwmvhw5ofc"></a>

クエリ パラメータを含むシークレット参照を使用して、アイテムに関する詳細情報を取得できます。

**属性パラメータ**

アイテム フィールドとファイル添付に関する情報を取得するには、 `attribute`(または`attr`) クエリ パラメータを使用します。

{% code title="Fields" %}

```
op://<vault>/<item>[/<section>]/<field-name>?attribute=<attribute-value>
```

{% endcode %}

{% code title="File attachments" %}

```
op://<vault>/<item>[/<section>]/<file-name>?attribute=<attribute-value>
```

{% endcode %}

Field attributes:

| 属性        | 意味                                           |
| --------- | -------------------------------------------- |
| `type`    | フィールドの種類                                     |
| `value`   | フィールドの内容                                     |
| `id`      | フィールドの一意の識別子                                 |
| `purpose` | 組み込みフィールドの指定（「ユーザー名」、「パスワード」、または「メモ」）        |
| `otp`     | ワンタイムパスワードフィールドを使用してワンタイムパスワードコードを生Createします |

File attachment attributes:

| 属性        | 意味            |
| --------- | ------------- |
| `type`    | フィールドの種類      |
| `content` | 添付ファイルの内容     |
| `size`    | 添付ファイルのサイズ    |
| `id`      | 添付ファイルの一意の識別子 |
| `name`    | 添付ファイルの名前     |

例えば、アイテムのワンタイム パスワード コードを取得するには、次のようにします。

```
$ op read "op://development/GitHub/Security/one-time password?attribute=otp"
```

<details>

<summary>結果を見る...</summary>

359836

</details>

フィールドのタイプを取得するには:

```
$ op read "op://Personal/aws/access credentials/username?attribute=type"
```

<details>

<summary>結果を見る...</summary>

string

</details>

添付ファイルの名前を取得するには:

```
$ op read "op://app-infra/ssh/key.pem?attribute=name"
```

<details>

<summary>結果を見る...</summary>

key.pem

</details>

**SSH フォーマットパラメータ**

OpenSSH 形式で SSH 秘密キーを取得するには、SSH鍵のシークレット参照に値 `openssh` を指定した `ssh-format` クエリ パラメーターを含めます。

```
$ op read "op://Private/ssh keys/ssh key/private key?ssh-format=openssh"
```

<details>

<summary>結果を見る...</summary>

\-----BEGIN OPENSSH PRIVATE KEY-----\
b3BlbnNzaC1rZXktdjEAAAAACmFlczI1Ni1jdHIAAAAGYmNyeXB0AAAAGAAAABD3rRrf8J\
ruD0CxZTYfpbTYAAAAEAAAAAEAAAAzAAAAC3NzaC1lZDI1NTE5AAAAIJ5B/GnxX6t9jMwQ\
G7QE7r5daJLkMKTZhNZhWfvzK2y+AAAAkLgQAivYu/+12/YrZhK5keIAZf4ZgsZsZ2JI2q\
qbx23PqgO93oGy1iCxXe3kngQL4cM6lwOZPsZPKCinkN6KxEr6RnXqFRHJbMpOiGeZhTuD\
rjeo77HqFdxDqDeckB77XCKL0Ew28H5JlM/WO31XR3Z4VBAgTe+BQLjrFV8WU5UX38hpBJ\
PMJyRsK72ZUDDaGQ==\
\-----END OPENSSH PRIVATE KEY-----

</details>

### **シークレット参照の例** <a href="#b2ykjpy5q18u" id="b2ykjpy5q18u"></a>

#### **セクション内のフィールド** <a href="#s137c946wyy7" id="s137c946wyy7"></a>

管理セクション内にある PagerDuty の電子メール フィールドを参照するシークレット参照をCreateするには、次を使用します。

```
$ op://Management/PagerDuty/Admin/email
```

* ①Management アイテムがSaveされているvaultを指します
* ②PagerDuty アイテムを参照します
* ③Adimn フィールドが含まれるセクションを指します
* ④email 参照したいシークレットが配置されているフィールドを指します

<img src="/files/7O3oTEyZcVwammvS2fCq" alt="PagerDuty 1Password アイテム" width="375">

#### **セクションのないフィールド** <a href="#nanjhdko59jc" id="nanjhdko59jc"></a>

セクションの一部ではない Stripe 公開鍵 フィールドの秘密参照をCreateするには、次を使用します。

```
$ op://dev/Stripe/publishable-key
```

* ①dev アイテムがSaveされている金庫を指します
* ②Stripe アイテムを指します
* ③publishable-key 参照したい秘密が配置されているフィールドを指します。

<img src="/files/xsJDcP6KvoR6VBYtOyvh" alt="Stripe 1Password アイテム" width="375">

### **さらに詳しく** <a href="#pxc6el7j6052" id="pxc6el7j6052"></a>

* [1Password CLIでシークレットリファレンスを使う](https://developer.1password.com/docs/cli/secret-references/)
* [1Password SDKを使い始める](https://developer.1password.com/docs/sdks/)
* [シークレットを構成ファイルに読み込む](https://developer.1password.com/docs/cli/secrets-config-files/)
* [環境にシークレットをロードする](https://developer.1password.com/docs/cli/secrets-environment-variables/)
* [テンプレート構文](https://developer.1password.com/docs/cli/secrets-template-syntax/)
