• Projects
  • Service
  • About
  • branding.bz
  • Podcast
  • Tips
  • FAQ
  • Recruit
  • Download
  • Contact
  • branding.bz(ブランド構築SaaS)
  • DESIGN NOW(デザインメディア)
  • X
  • LinkedIn
  • Spotify
  • Facebook

213-0011 神奈川県川崎市高津区久本3-6-7-303

© 2026 ID INC. All rights reserved

claude-skills/スキル
SKILLOfficialdevelopment

aws-secrets-manager

プラグイン
aws-core
ソース
GitHub で見る ↗
説明

AWS Secrets Manager(クラウド環境での機密情報の一元管理サービス)のための秘密情報保護機能です。 機密情報、API キー、トークン、パスワードなどを安全に管理しながら、AI エージェントが秘密値を直接取得するのを防ぎます。asm-exec という実行時の動的参照(プログラム実行時に必要な値を自動的に呼び出す仕組み)を用いることで、平文のデータが言語モデルのコンテキストウィンドウ(処理対象のテキスト領域)に入らないようにしています。

原文を表示

Secret safety for AWS Secrets Manager, secret management, credentials, API keys, tokens, and passwords. Prevents AI agents from directly fetching secret values and teaches runtime dynamic references with asm-exec so plaintext never enters the LLM context window.

ユースケース
  • 機密情報を安全に管理する
  • APIキーを保護する
  • パスワードを秘密値として扱う
  • 言語モデルへの流出を防ぐ
本文(日本語訳)

エージェントでシークレットを安全に扱う

概要

AI エージェントが シェルや AWS API にアクセスしながらシークレット(認証情報)、API キー、トークン、パスワードを扱う場合、aws secretsmanager get-secret-value を呼び出してプレーンテキスト形式の値をコンテキストウィンドウ(会話履歴)に受け取ることができます。これはリスクです:シークレットがログ、会話履歴、または後続のツール呼び出しに漏らされる可能性があります。

このスキルはより安全なパターンを提示します:動的参照を使用し、ラッパースクリプト(asm-exec)がランタイムで解決するため、エージェントはシークレット値を見ることがありません。

最善の努力による防御であり、セキュリティの境界ではありません。 これは最も一般的な漏洩経路を防ぎますが、すべての回避方法を止めることはできません。IAM の最小権限、CloudTrail 監視、VPC エンドポイントポリシーと組み合わせて使用してください。

ルール

シークレットを扱う際は、以下のルールに従う必要があります:

  1. get-secret-value または batch-get-secret-value を呼び出してはいけません — AWS CLI、SDK、MCP ツール、curl、その他のメカニズムを通じてもです。
  2. Secrets Manager Agent(SMA)デーモン(localhost:2773 またはその他のループバック変種)からシークレット値を直接読み出そうとしてはいけません。
  3. {{resolve:secretsmanager:...}} 参照を使用する必要があります — これらはランタイムで asm-exec によって解決され、値はあなたに公開されません。

{{resolve:...}} 構文

{{resolve:secretsmanager:<secret-id>:<field-type>:<json-key>:<version-stage>}}
要素 必須 デフォルト 例
secret-id はい — prod/db-creds または完全な ARN
field-type いいえ SecretString SecretString
json-key いいえ (全体の値) password
version-stage いいえ AWSCURRENT AWSPENDING

asm-exec の使用

asm-exec はコマンド引数と環境変数内の {{resolve:...}} 参照を解決し、対象コマンドを実行するラッパーです。シークレット値は子プロセス内にのみ存在し、エージェントのコンテキストには決して現れません。

使い方

# データベースのパスワードを psql に渡す(値は隠される)
asm-exec -- psql \
  "host=mydb.example.com \
   user={{resolve:secretsmanager:prod/db-creds:SecretString:username}} \
   password={{resolve:secretsmanager:prod/db-creds:SecretString:password}}" \
  -c "SELECT * FROM users LIMIT 10"

# デフォルトの field-type(SecretString)と全体の値を使用
asm-exec -- curl -H "Authorization: Bearer {{resolve:secretsmanager:prod/api-token}}" \
  https://api.example.com/data

# 1 つのコマンドで複数のシークレットを使用
asm-exec -- mysql \
  -h {{resolve:secretsmanager:prod/mysql:SecretString:host}} \
  -u {{resolve:secretsmanager:prod/mysql:SecretString:username}} \
  -p{{resolve:secretsmanager:prod/mysql:SecretString:password}} \
  -e "SHOW TABLES"

動作の仕組み

  1. すべてのコマンド引数を {{resolve:...}} パターンでスキャンします
  2. 各参照を以下の順でいずれかのバックエンド経由で解決します:
    1. AWS Secrets Manager Agent(SMA)(localhost:2773、低遅延でキャッシュ対応)
    2. AWS MCP エンドポイント(https://aws-mcp.us-east-1.api.aws/mcp)、SigV4 署名済みリクエストで aws___run_script ツールを呼び出し(このツールは call_boto3 経由でシークレットを取得するサーバー側 Python スクリプトを実行)
    3. ARN のリージョンセグメントから、またはそのセグメントから AWS_REGION / AWS_DEFAULT_REGION からシークレットのリージョンを決定し、リゾルバーに渡します
  3. re.sub で解決値を置換します(単一パス — シークレット値が {{resolve:...}} を含む場合の再スキャン注入を防止)
  4. ターゲットコマンドを subprocess.run で実行 — シークレット値は asm-exec プロセス内にのみ存在し、エージェントのコンテキストウィンドウには決して現れません

ローカル AWS CLI フォールバックはありません。 asm-exec は参照を解決するために aws secretsmanager get-secret-value をシェルアウトしません。解決は SMA または MCP エンドポイント経由のみで行われるため、プレーンテキスト値がキャプチャされる可能性があるローカルプロセスの stdout に書き込まれることはありません。

SigV4 署名

MCP エンドポイントはすべてのツール呼び出しを AWS SigV4 で認証します。asm-exec は Python 標準ライブラリ(hashlib/hmac)のみを使用してリクエストに署名します — botocore に依存したり、mcp-proxy-for-aws-cli プロキシを立ち上げたりせず、ラッパーを軽量なエフェメラル(一時的な)プロセスに保ちます。署名サービスとリージョンはエンドポイントのホスト名から推測されます(例:aws-mcp.us-east-1.api.aws → サービス aws-mcp、リージョン us-east-1)。この署名リージョンはシークレット自体のリージョンとは独立しており、シークレット自体のリージョンはサーバー側の call_boto3 呼び出しに region_name 引数として渡されます。

署名用の認証情報は環境変数(AWS_ACCESS_KEY_ID など)、aws configure export-credentials(AWS CLI v2)、aws configure get(AWS CLI v1)の順で解決されます。

前提条件

いずれかのバックエンドが到達可能である必要があり、secretsmanager:GetSecretValue 権限を持つ認証情報が必要です:

  • **AWS Secrets Manager Agent(SMA)**が localhost:2773 で実行されている、または
  • AWS 認証情報が MCP エンドポイントの SigV4 署名用に解決可能(上記を参照)。リージョン間にわたるシークレットの場合は、AWS_REGION を設定するか完全な ARN を使用して、正しいリージョンが対象になるようにしてください。

SMA セットアップガイドを参照してください。

よくあるパターン

データベース接続

asm-exec -- psql "postgresql://{{resolve:secretsmanager:prod/db:SecretString:username}}:{{resolve:secretsmanager:prod/db:SecretString:password}}@db.example.com:5432/mydb"

Docker でシークレットを使う

asm-exec -- docker run -e "DB_PASSWORD={{resolve:secretsmanager:prod/db:SecretString:password}}" myapp:latest

設定ファイルのテンプレート化

# 解決されたシークレットで設定を生成し、ファイルに書き込む
asm-exec -- sh -c 'echo "password={{resolve:secretsmanager:app/db:SecretString:password}}" > /tmp/app.conf'

構造的な強制(プラグインフック)

aws-core プラグインが有効な場合、PreToolUse フック(ツール実行前の検査機能)は get-secret-value または batch-get-secret-value への呼び出しを自動的にブロックします — AWS CLI、MCP ツール、または SMA への直接アクセス経由でも。手動設定は不要です。

フックは plugins/aws-core/com.anthropic.claude-code/hooks/hooks.json で定義され、プラグインがインストールされると自動的に有効になります。

トラブルシューティング

「シークレットが見つかりません」エラー

シークレットが存在し、IAM ロールが secretsmanager:GetSecretValue 権限を持っていることを確認してください。シークレット名が完全に一致していることを確認します(大文字と小文字は区別されます)。

SMA 接続拒否

Secrets Manager Agent が実行されていない可能性があります。これは致命的ではありません:asm-exec は SigV4 署名済み MCP エンドポイントにフォールスルーします。AWS 認証情報が解決可能であること(上記の SigV4 署名を参照)を確認し、そのバックエンドが認証できるようにしてください。

「解決に失敗」エラー

両方のバックエンドに到達できないか、値が返されませんでした。MCP 解決が失敗した場合、asm-exec は特定の原因を stderr に出力します(asm-exec: MCP resolution failed: ...)— タイムアウト、到達不可能なエンドポイント、HTTP ステータス、拒否された権限、または欠落値 — ため、まずその行を読んでください。SMA が実行されているか、AWS 認証情報が有効であること(aws sts get-caller-identity)、シークレットのリージョンが正しいこと(AWS_REGION を設定するか完全な ARN を使用)、およびアイデンティティがシークレットの secretsmanager:GetSecretValue 権限を持っていることを確認してください。MCP エンドポイントからの 401 は、シークレットの欠落ではなく、SigV4 署名または認証情報の問題を示します。失敗がタイムアウトである場合、サーバー側呼び出しがデフォルトの 30 秒より長く必要な場合があります — ASM_EXEC_MCP_TIMEOUT(秒)で引き上げてください。

解決が空の文字列になる

JSON キーがシークレット値に存在しない可能性があります。AWS コンソールでシークレット構造を確認するか、シークレット所有者に利用可能なキーを確認してもらってください。

原文(English)を表示

Using Secrets Safely with Agents

Overview

When AI agents handle secrets, credentials, API keys, tokens, or passwords with shell or AWS API access, they can call aws secretsmanager get-secret-value and receive plaintext values in their context window. This creates risk: secrets may leak into logs, conversation history, or downstream tool calls.

This skill teaches a safer pattern: dynamic references resolved at runtime by a wrapper script (asm-exec), so the agent never sees the secret value.

Best-effort defense, not a security boundary. This prevents the most common leakage path but cannot stop all evasion vectors. Combine with IAM least-privilege, CloudTrail monitoring, and VPC endpoint policies.

Rules

You MUST follow these rules when working with secrets:

  1. MUST NOT call get-secret-value or batch-get-secret-value -- not via AWS CLI, SDK, MCP tools, curl, or any other mechanism.
  2. MUST NOT attempt to read secret values from the Secrets Manager Agent (SMA) daemon directly (localhost:2773 or any loopback variant).
  3. MUST use {{resolve:secretsmanager:...}} references -- these are resolved at runtime by asm-exec without exposing values to you.

The {{resolve:...}} Syntax

{{resolve:secretsmanager:<secret-id>:<field-type>:<json-key>:<version-stage>}}
Component Required Default Example
secret-id Yes -- prod/db-creds or full ARN
field-type No SecretString SecretString
json-key No (full value) password
version-stage No AWSCURRENT AWSPENDING

Using asm-exec

asm-exec is a wrapper that resolves {{resolve:...}} references in command arguments and environment variables, then execs the target command. The secret value exists only in the child process -- never in the agent's context.

Usage

# Pass a database password to psql without exposing it
asm-exec -- psql \
  "host=mydb.example.com \
   user={{resolve:secretsmanager:prod/db-creds:SecretString:username}} \
   password={{resolve:secretsmanager:prod/db-creds:SecretString:password}}" \
  -c "SELECT * FROM users LIMIT 10"

# Use default field-type (SecretString) and full value (no json-key)
asm-exec -- curl -H "Authorization: Bearer {{resolve:secretsmanager:prod/api-token}}" \
  https://api.example.com/data

# Multiple secrets in one command
asm-exec -- mysql \
  -h {{resolve:secretsmanager:prod/mysql:SecretString:host}} \
  -u {{resolve:secretsmanager:prod/mysql:SecretString:username}} \
  -p{{resolve:secretsmanager:prod/mysql:SecretString:password}} \
  -e "SHOW TABLES"

How It Works

  1. Scans all command arguments for {{resolve:...}} patterns
  2. Resolves each reference through the first available backend, in order:
    1. AWS Secrets Manager Agent (SMA) on localhost:2773 (zero-latency, cached)
    2. AWS MCP endpoint (https://aws-mcp.us-east-1.api.aws/mcp), calling the aws___run_script tool over a SigV4-signed request (the tool runs a short server-side Python script that fetches the secret via call_boto3)
    3. Determines the secret's region from an ARN's region segment, or from AWS_REGION / AWS_DEFAULT_REGION, and passes it to the resolver
  3. Substitutes resolved values using re.sub with a callable (single-pass -- prevents re-scan injection if a secret value contains {{resolve:...}})
  4. Runs the target command via subprocess.run -- secret values exist only in the asm-exec process, never in the agent's context window

No local AWS CLI fallback for resolution. asm-exec does not shell out to aws secretsmanager get-secret-value to resolve references. Resolution happens only through SMA or the MCP endpoint, so the plaintext value is never written to a local process's stdout where it could be captured.

SigV4 signing

The MCP endpoint authenticates every tool call with AWS SigV4. asm-exec signs requests itself using only the Python standard library (hashlib/hmac) -- it does not depend on botocore or spin up the mcp-proxy-for-aws-cli proxy, keeping the wrapper a lightweight ephemeral process. The signing service and region are inferred from the endpoint hostname (e.g. aws-mcp.us-east-1.api.aws -> service aws-mcp, region us-east-1); this signing region is independent of the secret's own region, which is passed as the region_name argument to the server-side call_boto3 call.

Credentials for signing are resolved in order: environment variables (AWS_ACCESS_KEY_ID etc.), aws configure export-credentials (AWS CLI v2), then aws configure get (AWS CLI v1).

Prerequisites

Either backend must be reachable, with credentials that have secretsmanager:GetSecretValue permission:

  • AWS Secrets Manager Agent (SMA) running on localhost:2773, OR
  • AWS credentials resolvable for SigV4 signing of the MCP endpoint (see above). For cross-region secrets, set AWS_REGION (or use a full ARN) so the correct region is targeted.

See SMA setup guide.

Common Patterns

Database connections

asm-exec -- psql "postgresql://{{resolve:secretsmanager:prod/db:SecretString:username}}:{{resolve:secretsmanager:prod/db:SecretString:password}}@db.example.com:5432/mydb"

Docker with secrets

asm-exec -- docker run -e "DB_PASSWORD={{resolve:secretsmanager:prod/db:SecretString:password}}" myapp:latest

Configuration file templating

# Generate config with resolved secrets, write to file
asm-exec -- sh -c 'echo "password={{resolve:secretsmanager:app/db:SecretString:password}}" > /tmp/app.conf'

Structural Enforcement (Plugin Hook)

When the aws-core plugin is enabled, a PreToolUse hook automatically blocks any attempt to call get-secret-value or batch-get-secret-value -- via AWS CLI, MCP tools, or direct SMA access. No manual configuration needed.

The hook is defined at plugins/aws-core/com.anthropic.claude-code/hooks/hooks.json and activates automatically when the plugin is installed.

Troubleshooting

"Secret not found" errors

Verify the secret exists and your IAM role has secretsmanager:GetSecretValue permission. Check the secret name matches exactly (case-sensitive).

SMA connection refused

The Secrets Manager Agent may not be running. This is non-fatal: asm-exec falls through to the SigV4-signed MCP endpoint. Ensure AWS credentials are resolvable (see SigV4 signing above) so that backend can authenticate.

"Failed to resolve" errors

Both backends were unreachable or returned no value. When MCP resolution fails, asm-exec prints the specific cause to stderr (asm-exec: MCP resolution failed: ...) -- a timeout, an unreachable endpoint, an HTTP status, a denied permission, or a missing value -- so read that line first. Check that either SMA is running or AWS credentials are valid (aws sts get-caller-identity), that the secret's region is correct (set AWS_REGION or use a full ARN), and that your identity has secretsmanager:GetSecretValue on the secret. A 401 from the MCP endpoint indicates a SigV4 signing or credential problem, not a missing secret. If the failure is a timeout, the server-side call may need longer than the default 30s -- raise it with ASM_EXEC_MCP_TIMEOUT (seconds).

Resolution produces empty string

The JSON key may not exist in the secret value. Verify the secret structure in the AWS Console or ask the secret owner to confirm the available keys.

原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。