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エージェント(自動実行プログラム)がシークレット、認証情報、APIキー、トークン、パスワードなどをシェルやAWSの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)と全値を使用(json-keyなし)
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___call_awsツールを呼び出しAWS_REGION/AWS_DEFAULT_REGION)からシークレットのリージョンを判定し、リゾルバーに渡しますre.subを呼び出し可能な関数で解決値に置換します(1回のスキャンのみ。シークレット値に{{resolve:...}}が含まれていても再スキャンの注入を防止)subprocess.runでターゲットコマンドを実行します。シークレット値はasm-execプロセス内にのみ存在し、エージェントのコンテキストウィンドウには現れませんローカルAWS CLIフォールバックはありません。
asm-execは参照解決のためにaws secretsmanager get-secret-valueをシェルアウト(別プロセス起動)しません。解決は SMA または MCPエンドポイント経由でのみ行われるため、平文値がローカルプロセスの標準出力に書き込まれて取得されることはありません。
MCPエンドポイントはすべてのツール呼び出しをAWS SigV4で認証します。asm-execはPython標準ライブラリ(hashlib/hmac)のみを使用して自身でリクエストに署名します。bootocore への依存もなく、mcp-proxy-for-awsプロキシの起動も不要なため、ラッパーは軽量で一時的なプロセスのままです。署名サービスとリージョンはエンドポイントホスト名から推定されます(例:aws-mcp.us-east-1.api.aws → サービスaws-mcp、リージョンus-east-1)。この署名リージョンはシークレット自身のリージョン(サーバー側CLIコマンドに--regionで渡される)とは独立しています。
署名用認証情報は、環境変数(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署名を参照)。そうすれば、そのバックエンドが認証できます。
どちらのバックエンドにもアクセスできなかったか、値が返されていません。SMAが実行中であるか、AWS認証情報が有効であることを確認してください(aws sts get-caller-identityを実行)。シークレットのリージョンが正しいこと(AWS_REGIONを設定するか、フルARNを使用)を確認してください。アイデンティティがそのシークレットに対してsecretsmanager:GetSecretValueを持っていることを確認してください。MCPエンドポイントからの401は、シークレットの欠落ではなく、SigV4署名または認証情報の問題を示しています。
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___call_aws tool over a SigV4-signed requestAWS_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 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 --region to the server-side CLI command.
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. 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.
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 による自動翻訳です。