Repository navigation
fix(gateway): refuse a bound NONE gateway in a Box project, explain a 403 #2888
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: box-integration
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -316,6 +316,44 @@ describe("gateway invoke", () => { | |
| expect(output.stderr()).toHaveLength(0); | ||
| }); | ||
|
|
||
| test("explains an HTTP 403 from an AWS_IAM Gateway", async () => { | ||
| const core = configuredCore({ authorizerType: "AWS_IAM" }); | ||
| core.gateway.setInvokeResponse({ | ||
| statusCode: 403, | ||
| contentType: "application/json", | ||
| requestId: "request-403", | ||
| body: body(Buffer.from('{"message":"AccessDeniedException"}')), | ||
| }); | ||
| const output = captureIO(); | ||
|
|
||
| const code = await runWithExitCode(async () => | ||
| runCommand(core, output.io, ["gateway", "invoke", "--id", GATEWAY_ID, "--payload", "{}"]), | ||
| ); | ||
|
|
||
| expect(code).toBe(ExitCode.FAILURE); | ||
| expect(output.stderr().toString()).toContain( | ||
| "If this is a Box Gateway (bound to one runtime in a Box project), its resource policy " + | ||
| "lets only that runtime's execution role invoke it.", | ||
| ); | ||
| }); | ||
|
|
||
| test("adds no access hint to an HTTP 403 from a Gateway without AWS_IAM", async () => { | ||
| const core = configuredCore(); | ||
| core.gateway.setInvokeResponse({ | ||
| statusCode: 403, | ||
| contentType: "application/json", | ||
| requestId: "request-403", | ||
| body: body(Buffer.from('{"message":"Forbidden"}')), | ||
| }); | ||
| const output = captureIO(); | ||
|
|
||
| await runWithExitCode(async () => | ||
| runCommand(core, output.io, ["gateway", "invoke", "--id", GATEWAY_ID, "--payload", "{}"]), | ||
| ); | ||
|
|
||
| expect(output.stderr().toString()).not.toContain("Box Gateway"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: consider also asserting |
||
| }); | ||
|
|
||
| test("streams a non-2xx body before returning a failure exit code", async () => { | ||
| const core = configuredCore(); | ||
| core.gateway.setInvokeResponse({ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,24 @@ function summary( | |
| ); | ||
| } | ||
|
|
||
| /** | ||
| * The hint for an HTTP 403 from an AWS_IAM Gateway. In a Box project, each Box Gateway has a | ||
| * resource policy that denies every principal except its runtime's execution role, so even an | ||
| * administrator gets AccessDenied. | ||
| */ | ||
| export function gatewayAccessDeniedHint( | ||
| statusCode: number, | ||
| authorizerType: string | undefined, | ||
| ): string | undefined { | ||
| if (statusCode !== 403 || authorizerType !== "AWS_IAM") return undefined; | ||
| return ( | ||
| "Access denied. If this is a Box Gateway (bound to one runtime in a Box project), its " + | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: the hint says what fails but not how to test the gateway. You could add a clause like "To exercise it, invoke the runtime ( |
||
| "resource policy lets only that runtime's execution role invoke it. Your credentials " + | ||
| "cannot invoke it, even with administrator access. Otherwise, check that your " + | ||
| "credentials allow bedrock-agentcore:InvokeGateway on this Gateway." | ||
| ); | ||
| } | ||
|
|
||
| export async function writeGatewayInvokeResponse( | ||
| response: GatewayInvokeResponse, | ||
| output: StreamingResponseOutput, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: this fires for every 403 from any
AWS_IAMgateway, Box or not, because the command only sees the liveGetGatewayresponse. The wording is conditional, so this is fine. If you want the Box sentence only for Box gateways, you could check whether the local project has a bound gateway whose deployed ID matches--id.