🔐output-dev-credentials
- プラグイン
- outputai
- ソース
- GitHub で見る ↗
説明
`@outputai/credentials` を使用して、Output SDK ワークフロー内で暗号化されたシークレットを保存・参照します。 次のような場合に使用: APIキー、データベースパスワード、またはサードパーティトークンを統合する際。
原文を表示
Store and reference encrypted secrets in Output SDK workflows using @outputai/credentials. Use when integrating API keys, database passwords, or third-party tokens.
ユースケース
- ✓APIキーを統合するとき
- ✓データベースパスワードを統合するとき
- ✓サードパーティトークンを統合するとき
- ✓暗号化されたシークレットを保存・参照するとき
本文(日本語訳)
暗号化クレデンシャル管理
概要
@outputai/credentials パッケージは、Output SDK ワークフロー向けに暗号化されたシークレット管理機能を提供します。
process.env による環境変数パターンを、スコープ付きクレデンシャルとディープマージをサポートする、構造化された暗号化 YAML ベースのシステムへ置き換えます。
このスキルを使用するタイミング
次のような場合に使用:
- ワークフローに API キーやトークンを追加する
process.envから暗号化クレデンシャルへ移行する- ワークフローごと、または環境ごとのシークレットをセットアップする
- クレデンシャル未設定エラー(
MissingCredentialError、MissingKeyError)をデバッグする - カスタムクレデンシャルプロバイダー(Vault、AWS Secrets Manager 等)を設定する
ライブラリ API
インポート
import { credentials } from '@outputai/credentials';
credentials.get(path, defaultValue?)
デフォルト値を指定できる安全な読み取りメソッドです。例外はスローしません。
// 値が存在しない場合は undefined を返す
const region = credentials.get('aws.region');
// 値が存在しない場合はデフォルト値を返す
const region = credentials.get('aws.region', 'us-east-1');
credentials.require(path)
厳格な読み取りメソッドです。指定したパスが見つからない場合は MissingCredentialError をスローします。
const apiKey = credentials.require('anthropic.api_key');
エラーの種類
import { MissingCredentialError, MissingKeyError } from '@outputai/credentials';
| エラー | スローされる条件 | 対処法 |
|---|---|---|
MissingCredentialError |
credentials.require() で指定したパスが見つからない |
output credentials edit でクレデンシャルを追加する |
MissingKeyError |
復号化キーが利用できない | 環境変数 OUTPUT_CREDENTIALS_KEY を設定するか、.key ファイルを作成する |
CLI コマンド
# クレデンシャルを初期化(キーと暗号化 YAML テンプレートを生成)
output credentials init # グローバル
output credentials init -e production # 環境ごと
output credentials init -w payment_processing # ワークフローごと
# クレデンシャルを編集(復号化 → $EDITOR で開く → 保存時に再暗号化)
output credentials edit # グローバル
output credentials edit -e production # 環境ごと
output credentials edit -w payment_processing # ワークフローごと
# 復号化したクレデンシャルを表示(デバッグ用)
output credentials show # グローバル
output credentials show -e development # 環境ごと
# 単一クレデンシャルの値を取得
output credentials get anthropic.api_key # グローバル
output credentials get stripe.key -w payment_processing # ワークフローごと
フラグ:
-e/--environment: 対象環境を指定(production、development 等)-w/--workflow: 対象ワークフローを指定-f/--force: 既存クレデンシャルを上書き(init のみ)- 注意:
-eと-wは同時に使用できません(相互排他)
3 層スコープシステム
1. グローバルクレデンシャル
config/credentials.yml.enc # 暗号化 YAML
config/credentials.key # 復号化キー(コミット禁止)
キーの環境変数: OUTPUT_CREDENTIALS_KEY
2. 環境ごとのクレデンシャル
config/credentials/production.yml.enc
config/credentials/production.key
キーの環境変数: OUTPUT_CREDENTIALS_KEY_PRODUCTION
3. ワークフローごとのクレデンシャル
src/workflows/{name}/credentials.yml.enc
src/workflows/{name}/credentials.key
キーの環境変数: OUTPUT_CREDENTIALS_KEY_{WORKFLOW_NAME}(大文字)
キー解決の優先順位
各スコープにおいて、キーは以下の順で解決されます:
- 環境変数(
OUTPUT_CREDENTIALS_KEY、OUTPUT_CREDENTIALS_KEY_{ENV}、またはOUTPUT_CREDENTIALS_KEY_{WORKFLOW}) - ディスク上のキーファイル(例:
config/credentials.key) - どちらも見つからない場合は
MissingKeyErrorをスロー
ワークフロー固有のキーが存在しない場合、ワークフロークレデンシャルはグローバルキーにフォールバックします。
クレデンシャルのマージ
ワークフローが独自のクレデンシャルを持つ場合、グローバルクレデンシャルに対してディープマージが行われます。 同一パスでは、ワークフロー側の値が優先されます:
# グローバル (config/credentials.yml.enc)
anthropic:
api_key: sk-ant-global
aws:
region: us-east-1
# ワークフロー (src/workflows/my_workflow/credentials.yml.enc)
anthropic:
api_key: sk-ant-workflow-specific
stripe:
secret_key: sk_live_workflow
# 実行時のマージ結果:
# anthropic.api_key -> sk-ant-workflow-specific (ワークフロー側で上書き)
# aws.region -> us-east-1 (グローバルから引き継ぎ)
# stripe.secret_key -> sk_live_workflow (ワークフロー側で追加)
process.env からの移行
移行前(旧パターン)
import { httpClient } from '@outputai/http';
const API_KEY = process.env.SERVICE_API_KEY || '';
const client = httpClient({
prefixUrl: 'https://api.service.com',
headers: { Authorization: `Bearer ${API_KEY}` }
});
移行後(クレデンシャルパターン)
import { httpClient } from '@outputai/http';
import { credentials } from '@outputai/credentials';
const apiKey = credentials.require('service.api_key');
const client = httpClient({
prefixUrl: 'https://api.service.com',
headers: { Authorization: `Bearer ${apiKey}` }
});
移行手順
output credentials initを実行して暗号化ファイルとキーを生成するoutput credentials editを実行してシークレットを追加するprocess.env.Xの読み取り箇所をcredentials.require('x')またはcredentials.get('x', default)に置き換える.envファイルから環境変数を削除する*.keyを.gitignoreに追加する
カスタムプロバイダー
デフォルトの暗号化 YAML バックエンドを Vault や AWS Secrets Manager 等に置き換えることができます:
import { setProvider } from '@outputai/credentials';
setProvider({
loadGlobal: ({ environment }) => {
return fetchFromVault(`credentials/${environment || 'default'}`);
},
loadForWorkflow: ({ workflowName, environment }) => {
return fetchFromVault(`workflows/${workflowName}`) ?? null;
}
});
プロバイダーインターフェース
interface CredentialsProvider {
loadGlobal(context: { environment: string | undefined }): Record<string, unknown>;
loadForWorkflow(context: {
workflowName: string;
workflowDir: string | undefined;
environment?: string | undefined;
}): Record<string, unknown> | null;
}
セキュリティに関する注意事項
.keyファイルは絶対にコミットしない —*.keyを.gitignoreに追加してください.yml.encファイルはコミット可能 — キーなしでは読み取れません- キーファイルのパーミッション — モード
0o600(オーナーのみ読み書き可能)で作成されます - 一時ファイルのクリーンアップ —
edit実行時、削除前に平文をヌルバイトで上書きします - CI/CD での利用 — パイプライン内で
OUTPUT_CREDENTIALS_KEY環境変数を設定してください - 暗号化方式 — 暗号化ごとにユニークなランダムナンスを使用した AES-256-GCM
確認チェックリスト
- [ ]
credentialsを@outputai/credentialsからインポートしている - [ ] 必須シークレットには
credentials.require()を使用している(process.envは使用しない) - [ ] 任意の値には
credentials.get()をデフォルト値付きで使用している - [ ]
*.keyを.gitignoreに記載している - [ ]
output credentials initでクレデンシャルを初期化している - [ ]
output credentials editでシークレットを追加している
関連スキル
output-credentials-init— クレデンシャルファイルの初回初期化output-credentials-edit— クレデンシャル値の参照と編集output-credentials-env-vars—credential:規約を使用してクレデンシャルを環境変数に紐付けるoutput-dev-http-client-create— クレデンシャルを使用する HTTP クライアントの作成output-dev-step-function— ステップ関数内でのクレデンシャル利用output-error-http-client— HTTP クライアントに関するトラブルシューティング
原文(English)を表示
Encrypted Credentials Management
Overview
The @outputai/credentials package provides encrypted secrets management for Output SDK workflows. It replaces process.env patterns with a structured, encrypted YAML-based system that supports scoped credentials with deep merging.
When to Use This Skill
- Adding API keys or tokens to a workflow
- Migrating from
process.envto encrypted credentials - Setting up per-workflow or per-environment secrets
- Debugging missing credential errors (
MissingCredentialError,MissingKeyError) - Configuring custom credential providers (Vault, AWS Secrets Manager)
Library API
Import
import { credentials } from '@outputai/credentials';
credentials.get(path, defaultValue?)
Safe read with optional default. Never throws.
// Returns value or undefined
const region = credentials.get('aws.region');
// Returns value or default
const region = credentials.get('aws.region', 'us-east-1');
credentials.require(path)
Strict read. Throws MissingCredentialError if not found.
const apiKey = credentials.require('anthropic.api_key');
Error Types
import { MissingCredentialError, MissingKeyError } from '@outputai/credentials';
| Error | Thrown When | Fix |
|---|---|---|
MissingCredentialError |
credentials.require() path not found |
Add the credential via output credentials edit |
MissingKeyError |
No decryption key available | Set OUTPUT_CREDENTIALS_KEY env var or create .key file |
CLI Commands
# Initialize credentials (generates key + encrypted YAML template)
output credentials init # Global
output credentials init -e production # Environment-specific
output credentials init -w payment_processing # Workflow-specific
# Edit credentials (decrypts, opens $EDITOR, re-encrypts on save)
output credentials edit # Global
output credentials edit -e production # Environment
output credentials edit -w payment_processing # Workflow
# Show decrypted credentials (debugging)
output credentials show # Global
output credentials show -e development # Environment
# Get single credential value
output credentials get anthropic.api_key # Global
output credentials get stripe.key -w payment_processing # Workflow
Flags:
-e/--environment: Target environment (production, development)-w/--workflow: Target a specific workflow-f/--force: Overwrite existing credentials (init only)- Note:
-eand-ware mutually exclusive
Three-Tier Scope System
1. Global Credentials
config/credentials.yml.enc # Encrypted YAML
config/credentials.key # Decryption key (DO NOT COMMIT)
Key env var: OUTPUT_CREDENTIALS_KEY
2. Environment-Specific Credentials
config/credentials/production.yml.enc
config/credentials/production.key
Key env var: OUTPUT_CREDENTIALS_KEY_PRODUCTION
3. Per-Workflow Credentials
src/workflows/{name}/credentials.yml.enc
src/workflows/{name}/credentials.key
Key env var: OUTPUT_CREDENTIALS_KEY_{WORKFLOW_NAME} (uppercased)
Key Resolution Chain
For each scope, the key is resolved in order:
- Environment variable (
OUTPUT_CREDENTIALS_KEY,OUTPUT_CREDENTIALS_KEY_{ENV}, orOUTPUT_CREDENTIALS_KEY_{WORKFLOW}) - Key file on disk (e.g.,
config/credentials.key) - Throws
MissingKeyErrorif neither found
Workflow credentials fall back to the global key if no workflow-specific key exists.
Credential Merging
When a workflow has its own credentials, they deep-merge over global credentials. Workflow values win at the same path:
# Global (config/credentials.yml.enc)
anthropic:
api_key: sk-ant-global
aws:
region: us-east-1
# Workflow (src/workflows/my_workflow/credentials.yml.enc)
anthropic:
api_key: sk-ant-workflow-specific
stripe:
secret_key: sk_live_workflow
# Merged result at runtime:
# anthropic.api_key -> sk-ant-workflow-specific (overridden by workflow)
# aws.region -> us-east-1 (from global)
# stripe.secret_key -> sk_live_workflow (added by workflow)
Migration from process.env
Before (old pattern)
import { httpClient } from '@outputai/http';
const API_KEY = process.env.SERVICE_API_KEY || '';
const client = httpClient({
prefixUrl: 'https://api.service.com',
headers: { Authorization: `Bearer ${API_KEY}` }
});
After (credentials pattern)
import { httpClient } from '@outputai/http';
import { credentials } from '@outputai/credentials';
const apiKey = credentials.require('service.api_key');
const client = httpClient({
prefixUrl: 'https://api.service.com',
headers: { Authorization: `Bearer ${apiKey}` }
});
Migration Steps
- Run
output credentials initto create the encrypted file and key - Run
output credentials editto add your secrets - Replace
process.env.Xreads withcredentials.require('x')orcredentials.get('x', default) - Remove environment variables from
.envfiles - Add
*.keyto.gitignore
Custom Providers
Replace the default encrypted YAML backend with Vault, AWS Secrets Manager, etc.:
import { setProvider } from '@outputai/credentials';
setProvider({
loadGlobal: ({ environment }) => {
return fetchFromVault(`credentials/${environment || 'default'}`);
},
loadForWorkflow: ({ workflowName, environment }) => {
return fetchFromVault(`workflows/${workflowName}`) ?? null;
}
});
Provider Interface
interface CredentialsProvider {
loadGlobal(context: { environment: string | undefined }): Record<string, unknown>;
loadForWorkflow(context: {
workflowName: string;
workflowDir: string | undefined;
environment?: string | undefined;
}): Record<string, unknown> | null;
}
Security Considerations
- Never commit
.keyfiles - Add*.keyto.gitignore - Safe to commit
.yml.encfiles - Cannot be read without the key - Key file permissions - Created with mode
0o600(owner-only read/write) - Temp file cleanup - Plaintext overwritten with null bytes before deletion during
edit - Use env vars in CI/CD - Set
OUTPUT_CREDENTIALS_KEYin your pipeline - Encryption - AES-256-GCM with unique random nonce per encryption
Verification Checklist
- [ ]
credentialsimported from@outputai/credentials - [ ]
credentials.require()used for mandatory secrets (notprocess.env) - [ ]
credentials.get()used with default for optional values - [ ]
*.keylisted in.gitignore - [ ] Credentials initialized via
output credentials init - [ ] Secrets added via
output credentials edit
Related Skills
output-credentials-init- Initializing credentials files for the first timeoutput-credentials-edit- Viewing and editing credential valuesoutput-credentials-env-vars- Wiring credentials to env vars with thecredential:conventionoutput-dev-http-client-create- Creating HTTP clients that use credentialsoutput-dev-step-function- Using credentials in step functionsoutput-error-http-client- Troubleshooting HTTP client issues
原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。