Skip to content

Commit e791e62

Browse files
committed
fix(screenshot): krokoko PR-241 review — scope IAM + cosmetic Vercel mention
Closes aws-samples#94 (the existing 'scope IAM down from bedrock-agentcore:*' followup task). Addresses krokoko's PR aws-samples#241 review: 1. (BLOCKING per review #1) IAM action wildcard — narrow bedrock-agentcore:* to the three calls the screenshot processor actually makes: - StartBrowserSession (control plane, public CLI command) - StopBrowserSession (control plane, public CLI command) - ConnectBrowserAutomationStream (SigV4-presigned WSS dial; not in the public CLI list but verified live against the deployed dev stack — IAM accepts the action name) Resource wildcard remains because AgentCore Browser sessions are ephemeral with no stable ARN; the IAM5 suppression on the construct already documents that. Previous behaviour granted every AgentCore action surface (memory, runtime, gateway, identity, code-interpreter) the screenshot path doesn't use. Tightening to the call set leaves a precise audit surface; if a future API change needs another action, IAM denies with the action name in CloudTrail and we add it explicitly. 2. (NIT per review aws-samples#7) Stale 'Vercel' wording on ScreenshotBucketName CfnOutput description, plus an adjacent comment in agent.ts that said 'Vercel-style preview deploys'. Both replaced with provider-agnostic phrasing — the pipeline listens for any provider that posts deployment_status (Vercel, Amplify, Netlify, GitHub Actions custom CD). No behavioural change in either fix.
1 parent 8c8b7e3 commit e791e62

2 files changed

Lines changed: 29 additions & 12 deletions

File tree

cdk/src/constructs/github-screenshot-integration.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,29 @@ export class GitHubScreenshotIntegration extends Construct {
186186

187187
// AgentCore Browser session lifecycle + automation-stream connect.
188188
// The data-plane API doesn't support per-resource ARNs (sessions
189-
// are ephemeral), so wildcards are required — annotated with a
190-
// cdk-nag suppression below. The wildcard set covers
191-
// `ConnectBrowserAutomationStream` (the SigV4-presigned WSS dial)
192-
// which lives under the same prefix but isn't visible in the
193-
// public CLI command list.
189+
// are ephemeral), so the resource wildcard is required — annotated
190+
// with a cdk-nag suppression below.
191+
//
192+
// Actions are scoped to the three calls the handler actually makes:
193+
// - StartBrowserSession + StopBrowserSession (REST control plane,
194+
// in the public CLI command list)
195+
// - ConnectBrowserAutomationStream (the SigV4-presigned WSS dial;
196+
// not in the public CLI command list, but verified live against
197+
// the deployed dev stack — IAM accepts the action name even
198+
// though aws cli help doesn't surface it)
199+
//
200+
// Previously this used `bedrock-agentcore:*` which granted the
201+
// entire AgentCore action surface (memory, runtime, gateway,
202+
// identity, code-interpreter). Per krokoko's PR #241 review item
203+
// #1: scope down to least privilege. If a future API change adds a
204+
// call we need, IAM will deny with the specific action name in
205+
// CloudTrail and we can add it explicitly.
194206
this.webhookProcessorFn.addToRolePolicy(new iam.PolicyStatement({
195-
actions: ['bedrock-agentcore:*'],
207+
actions: [
208+
'bedrock-agentcore:StartBrowserSession',
209+
'bedrock-agentcore:StopBrowserSession',
210+
'bedrock-agentcore:ConnectBrowserAutomationStream',
211+
],
196212
resources: ['*'],
197213
}));
198214

cdk/src/stacks/agent.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -836,11 +836,12 @@ export class AgentStack extends Stack {
836836
});
837837

838838
// --- GitHub deployment-status → screenshot pipeline ---
839-
// Listens for Vercel-style preview deploys, screenshots the
840-
// `deployment.environment_url` via AgentCore Browser, posts the
841-
// image into a fresh PR comment. Default-on: any repo whose
842-
// GitHub webhook is configured will get screenshotted on
843-
// successful preview deploys; no opt-in flag.
839+
// Listens for GitHub deployment_status events from any provider
840+
// (Vercel, Amplify Hosting, Netlify, GitHub Actions custom CD),
841+
// screenshots the `deployment.environment_url` via AgentCore
842+
// Browser, posts the image into a fresh PR comment. Default-on:
843+
// any repo whose GitHub webhook is configured will get
844+
// screenshotted on successful preview deploys; no opt-in flag.
844845
const githubScreenshot = new GitHubScreenshotIntegration(this, 'GitHubScreenshotIntegration', {
845846
api: taskApi.api,
846847
githubTokenSecret,
@@ -864,7 +865,7 @@ export class AgentStack extends Stack {
864865

865866
new CfnOutput(this, 'ScreenshotBucketName', {
866867
value: githubScreenshot.screenshotBucket.bucket.bucketName,
867-
description: 'Private S3 bucket hosting Vercel-preview screenshots (served via CloudFront)',
868+
description: 'Private S3 bucket hosting preview-deploy screenshots (served via CloudFront)',
868869
});
869870

870871
new CfnOutput(this, 'ScreenshotCloudFrontDomain', {

0 commit comments

Comments
 (0)