DEV Community

CoreNova
CoreNova

Posted on Originally published at corenovacloud.com

Scrubbing PII Before Amazon Bedrock Invocation Logging and Locking Down Agent IMDS

Turning on Amazon Bedrock Model Invocation Logging solves auditability until your security team inspects the target S3 bucket or CloudWatch log group. Bedrock writes the raw request and response payloads as received, which means any customer email, SSN, credit card, or AWS access key passed in a prompt or tool output gets persisted to S3 and indexed in CloudWatch Logs.

At the same time, agent runtimes running on EKS or EC2 behind Bedrock AgentCore often ship with two quieter IAM gaps: EC2 instances still allow IMDSv1 (http_tokens = optional) or HttpPutResponseHopLimit > 1, and the S3 bucket holding invocation logs has an overly permissive bucket policy or KMS key policy.

1. Scrub Payloads Before InvokeModel or Converse

Amazon Bedrock logs the payload your application sends to the API, so redaction has to run before InvokeModel or Converse is called. If you run PII redaction inside your VPC (or through a zero-retention gateway) with deterministic placeholders, invocation logs only ever store tokens like [EMAIL_1] and [AWS_KEY_1].

Using CoreNova AI Guard, you can redact both user prompts and MCP tool responses in under 15ms while keeping deterministic placeholders across turns:

curl -s -X POST https://guard.corenovacloud.com/v1/redact \
  -H "Content-Type: application/json" \
  -d '{
    "text": "Customer alice@acme.com hit key AKIAIOSFODNN7EXAMPLE on card 4111111111111111",
    "return_restoration_map": true
  }'
Enter fullscreen mode Exit fullscreen mode

When an agent invokes downstream tools, McpToolResponseGuard from CoreNovaLabs/ai-guard-mcp-starter keeps allow_unscoped_fields=False by default so real values are only restored for explicitly allowlisted tools and argument keys:

from mcp_tool_response_proxy import McpToolResponseGuard

guard = McpToolResponseGuard(
    trusted_tools={"send_receipt": {"to", "cc"}},
    on_untrusted_restore="raise",
)

safe_payload = guard.sanitize_tool_result("crm_lookup", raw_tool_output)
Enter fullscreen mode Exit fullscreen mode

Because safe_payload is scrubbed before it enters the Bedrock message history, neither the foundation model nor Bedrock Invocation Logging ever sees the raw secret.

2. Gate IMDSv1, Bedrock Cost Exposure, and Log Bucket Policies in CI

Before deploying agent infrastructure, run CoreNova Cloud Audit v1.4.0 (POST /v1/scan/iac, POST /v1/scan/iam, and POST /v1/scan/s3-access) in your PR pipeline:

  • IAC_IMDSV1_ENABLED: flags Terraform/CloudFormation launch templates where http_tokens is omitted or set to optional, blocking SSRF-based IAM credential theft from agent pods.
  • IAM_BEDROCK_UNSCOPED_INVOKE and IAM_BEDROCK_COST_COMMITMENT: catch bedrock:InvokeModel* on Resource: "*" and unrestricted bedrock:CreateProvisionedModelThroughput before merge.
  • S3_PUBLIC_POLICY_READ and KMS_WILDCARD_PRINCIPAL_DECRYPT: verify who can actually read your Bedrock invocation log bucket across bucket policy, KMS key policy, SCPs, and sts:AssumeRole trust chains.

Test an IAM or Terraform snippet directly against the zero-retention sandbox:

curl -s -X POST https://audit.corenovacloud.com/v1/scan/iam \
  -H "Content-Type: application/json" \
  -d '{"policy":{"Statement":[{"Effect":"Allow","Action":["bedrock:InvokeModel*"],"Resource":"*"}]}}'
Enter fullscreen mode Exit fullscreen mode

3. Sandbox vs. In-VPC Zero-Egress Deployment

Top comments (0)