Skip to content

fix(gateway): report a Bedrock API key that is not valid as rejected - #235

Merged
fylorn merged 1 commit into
mainfrom
fix/bedrock-invalid-key-probe
Sep 29, 2026
Merged

fylorn merged 1 commit into
mainfrom
fix/bedrock-invalid-key-probe

Conversation

@fylorn

@fylorn fylorn commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Why

"Check connection" on a Bedrock upstream, and the background model fetch, run probe_bedrock. It lists the region's models and took any AccessDeniedException to mean the credential works but lacks bedrock:ListFoundationModels.

AWS answers an invalid Bedrock API key with AccessDeniedException as well. Asking the control plane and the runtime with fabricated keys gives:

  • a malformed key: {"Message":"Invalid API Key format: Must start with pre-defined prefix"} (or Delimiter ':' not found)
  • a well-formed key that does not exist: {"Message":"Authentication failed: Please make sure your API Key is valid."}

Both return HTTP 403 with x-amzn-errortype: AccessDeniedException. So a mistyped key passed the check with "The credential works, and it has no permission to list models", and the model fetch logged the same.

What changes

An AccessDeniedException counts as missing list permission only when AWS's message says the identity "is not authorized", which is IAM's own denial: User: arn:… is not authorized to perform: bedrock:ListFoundationModels … (identified in probe.rs). Any other one is a rejected key (gw.probe.key_rejected). AWS's message is only inspected and never passed on, since it names the account.

No message codes change.

Tests

  • tw-control/tests/bedrock.rs: a new test sends both real messages above with AccessDeniedException, and the probe fails with gw.probe.key_rejected.
  • The existing "no permission to list" case now uses IAM's full sentence and still reports gw.probe.bedrock_list_denied without the account ID.

cargo fmt --check, cargo clippy --workspace --all-targets -D warnings and cargo test --workspace pass locally.

🤖 Generated with Claude Code

Checking a Bedrock upstream took any AccessDeniedException from the model
listing to mean the credential works but may not list models. AWS answers
a Bedrock API key that is not valid with AccessDeniedException too
("Authentication failed: Please make sure your API Key is valid.",
"Invalid API Key format: ..."), so a mistyped key passed the check and the
background model fetch said the credential works.

Only an AccessDeniedException whose message says the identity "is not
authorized" (IAM's "User: arn:... is not authorized to perform: ...") now
counts as missing list permission; any other one is a rejected key. AWS's
message is only inspected, never passed on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fylorn
fylorn merged commit 38f7443 into main Sep 29, 2026
4 checks passed
@fylorn
fylorn deleted the fix/bedrock-invalid-key-probe branch September 29, 2026 06:04
@fylorn fylorn mentioned this pull request Sep 29, 2026
fylorn added a commit that referenced this pull request Sep 29, 2026
Patch release for #235.

- Bump the workspace version to 0.55.2
- release-notes/0.55.2.md

The control-plane protocol (28) and the request store schema (22) are
unchanged.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant