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.
AI エージェントが シェルや AWS API にアクセスしながらシークレット(認証情報)、API キー、トークン、パスワードを扱う場合、aws secretsmanager get-secret-value を呼び出してプレーンテキスト形式の値をコンテキストウィンドウ(会話履歴)に受け取ることができます。これはリスクです:シークレットがログ、会話履歴、または後続のツール呼び出しに漏らされる可能性があります。
このスキルはより安全なパターンを提示します:動的参照を使用し、ラッパースクリプト(asm-exec)がランタイムで解決するため、エージェントはシークレット値を見ることがありません。
最善の努力による防御であり、セキュリティの境界ではありません。 これは最も一般的な漏洩経路を防ぎますが、すべての回避方法を止めることはできません。IAM の最小権限、CloudTrail 監視、VPC エンドポイントポリシーと組み合わせて使用してください。
シークレットを扱う際は、以下のルールに従う必要があります:
get-secret-value または batch-get-secret-value を呼び出してはいけません — AWS CLI、SDK、MCP ツール、curl、その他のメカニズムを通じてもです。{{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"
{{resolve:...}} パターンでスキャンしますhttps://aws-mcp.us-east-1.api.aws/mcp)、SigV4 署名済みリクエストで aws___run_script ツールを呼び出し(このツールは call_boto3 経由でシークレットを取得するサーバー側 Python スクリプトを実行)AWS_REGION / AWS_DEFAULT_REGION からシークレットのリージョンを決定し、リゾルバーに渡しますre.sub で解決値を置換します(単一パス — シークレット値が {{resolve:...}} を含む場合の再スキャン注入を防止)subprocess.run で実行 — シークレット値は asm-exec プロセス内にのみ存在し、エージェントのコンテキストウィンドウには決して現れませんローカル AWS CLI フォールバックはありません。
asm-execは参照を解決するためにaws secretsmanager get-secret-valueをシェルアウトしません。解決は SMA または MCP エンドポイント経由のみで行われるため、プレーンテキスト値がキャプチャされる可能性があるローカルプロセスの stdout に書き込まれることはありません。
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_REGION を設定するか完全な ARN を使用して、正しいリージョンが対象になるようにしてください。SMA セットアップガイドを参照してください。
asm-exec -- psql "postgresql://{{resolve:secretsmanager:prod/db:SecretString:username}}:{{resolve:secretsmanager:prod/db:SecretString:password}}@db.example.com:5432/mydb"
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 権限を持っていることを確認してください。シークレット名が完全に一致していることを確認します(大文字と小文字は区別されます)。
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 コンソールでシークレット構造を確認するか、シークレット所有者に利用可能なキーを確認してもらってください。
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.
You MUST follow these rules when working with secrets:
get-secret-value or batch-get-secret-value -- not via AWS
CLI, SDK, MCP tools, curl, or any other mechanism.{{resolve:secretsmanager:...}} references -- these are
resolved at runtime by asm-exec without exposing values to you.{{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 |
asm-execasm-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.
# 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"
{{resolve:...}} patternshttps://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)AWS_REGION / AWS_DEFAULT_REGION, and passes it to the resolverre.sub with a callable (single-pass --
prevents re-scan injection if a secret value contains {{resolve:...}})subprocess.run -- secret values exist only in the
asm-exec process, never in the agent's context windowNo local AWS CLI fallback for resolution.
asm-execdoes not shell out toaws secretsmanager get-secret-valueto 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.
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).
Either backend must be reachable, with credentials that have
secretsmanager:GetSecretValue permission:
AWS_REGION (or use a full ARN) so the correct
region is targeted.See SMA setup guide.
asm-exec -- psql "postgresql://{{resolve:secretsmanager:prod/db:SecretString:username}}:{{resolve:secretsmanager:prod/db:SecretString:password}}@db.example.com:5432/mydb"
asm-exec -- docker run -e "DB_PASSWORD={{resolve:secretsmanager:prod/db:SecretString:password}}" myapp:latest
# Generate config with resolved secrets, write to file
asm-exec -- sh -c 'echo "password={{resolve:secretsmanager:app/db:SecretString:password}}" > /tmp/app.conf'
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.
Verify the secret exists and your IAM role has secretsmanager:GetSecretValue
permission. Check the secret name matches exactly (case-sensitive).
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.
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).
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 による自動翻訳です。