Skip to content

Commit

Permalink
[8.12] [Security solution] Update default Bedrock api url (#176090) (#…
Browse files Browse the repository at this point in the history
…176176)

# Backport

This will backport the following commits from `main` to `8.12`:
- [[Security solution] Update default Bedrock api url
(#176090)](#176090)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Steph
Milovic","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-02-02T17:43:33Z","message":"[Security
solution] Update default Bedrock api url
(#176090)","sha":"3a4ad7725a28429f25acd3ce630fb43f45ecde1e","branchLabelMapping":{"^v8.13.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:
SecuritySolution","ci:cloud-deploy","ci:cloud-redeploy","v8.13.0","Team:Security
Generative AI","v8.12.2"],"title":"[Security solution] Update default
Bedrock api
url","number":176090,"url":"https://github.com/elastic/kibana/pull/176090","mergeCommit":{"message":"[Security
solution] Update default Bedrock api url
(#176090)","sha":"3a4ad7725a28429f25acd3ce630fb43f45ecde1e"}},"sourceBranch":"main","suggestedTargetBranches":["8.12"],"targetPullRequestStates":[{"branch":"main","label":"v8.13.0","branchLabelMappingKey":"^v8.13.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/176090","number":176090,"mergeCommit":{"message":"[Security
solution] Update default Bedrock api url
(#176090)","sha":"3a4ad7725a28429f25acd3ce630fb43f45ecde1e"}},{"branch":"8.12","label":"v8.12.2","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Steph Milovic <[email protected]>
  • Loading branch information
kibanamachine and stephmilovic authored Feb 2, 2024
1 parent 0e7f027 commit c97a4a4
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ xpack.actions.preconfigured:
name: preconfigured-bedrock-connector-type
actionTypeId: .bedrock
config:
apiUrl: https://bedrock.us-east-1.amazonaws.com <1>
apiUrl: https://bedrock-runtime.us-east-1.amazonaws.com <1>
defaultModel: anthropic.claude-v2 <2>
secrets:
accessKey: key-value <3>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ export enum SUB_ACTION {
export const DEFAULT_TOKEN_LIMIT = 8191;
export const DEFAULT_BEDROCK_MODEL = 'anthropic.claude-v2';

export const DEFAULT_BEDROCK_URL = `https://bedrock.us-east-1.amazonaws.com` as const;
export const DEFAULT_BEDROCK_URL = `https://bedrock-runtime.us-east-1.amazonaws.com` as const;
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const bedrockConfig: ConfigFieldSchema[] = [
bedrockAPIUrlDocs: (
<EuiLink
data-test-subj="bedrock-api-doc"
href="https://docs.aws.amazon.com/bedrock/latest/APIReference/welcome.html"
href="https://docs.aws.amazon.com/general/latest/gr/bedrock.html"
target="_blank"
>
{`${i18n.BEDROCK} ${i18n.DOCUMENTATION}`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('BedrockConnector', () => {
Accept: '*/*',
'Content-Type': 'application/json',
},
host: 'bedrock.us-east-1.amazonaws.com',
host: 'bedrock-runtime.us-east-1.amazonaws.com',
path: '/model/anthropic.claude-v2/invoke',
service: 'bedrock',
},
Expand Down Expand Up @@ -136,7 +136,7 @@ describe('BedrockConnector', () => {
'Content-Type': 'application/json',
'x-amzn-bedrock-accept': '*/*',
},
host: 'bedrock.us-east-1.amazonaws.com',
host: 'bedrock-runtime.us-east-1.amazonaws.com',
path: '/model/anthropic.claude-v2/invoke-with-response-stream',
service: 'bedrock',
},
Expand Down Expand Up @@ -319,7 +319,7 @@ describe('BedrockConnector', () => {
).toEqual(`API Error: Resource Not Found - Resource not found`);
});

it('returns auhtorization error', () => {
it('returns authorization error', () => {
const err = {
response: {
headers: {},
Expand All @@ -333,7 +333,27 @@ describe('BedrockConnector', () => {

// @ts-expect-error expects an axios error as the parameter
expect(connector.getResponseErrorMessage(err)).toEqual(
`Unauthorized API Error - The api key was invalid.`
`Unauthorized API Error: The api key was invalid.`
);
});

it('returns endpoint error', () => {
const err = {
response: {
headers: {},
status: 400,
statusText: 'Bad Request',
data: {
message: 'The requested operation is not recognized by the service.',
},
},
} as AxiosError<{ message?: string }>;

// @ts-expect-error expects an axios error as the parameter
expect(connector.getResponseErrorMessage(err)).toEqual(
`API Error: The requested operation is not recognized by the service.
The Kibana Connector in use may need to be reconfigured with an updated Amazon Bedrock endpoint, like \`bedrock-runtime\`.`
);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,18 @@ export class BedrockConnector extends SubActionConnector<Config, Secrets> {
if (!error.response?.status) {
return `Unexpected API Error: ${error.code ?? ''} - ${error.message ?? 'Unknown error'}`;
}
if (
error.response.status === 400 &&
error.response?.data?.message === 'The requested operation is not recognized by the service.'
) {
// Leave space in the string below, \n is not being rendered in the UI
return `API Error: ${error.response.data.message}
The Kibana Connector in use may need to be reconfigured with an updated Amazon Bedrock endpoint, like \`bedrock-runtime\`.`;
}
if (error.response.status === 401) {
return `Unauthorized API Error${
error.response?.data?.message ? ` - ${error.response.data.message}` : ''
error.response?.data?.message ? `: ${error.response.data.message}` : ''
}`;
}
return `API Error: ${error.response?.statusText}${
Expand Down

0 comments on commit c97a4a4

Please sign in to comment.