-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Security solution] AWS Bedrock connector #166662
Conversation
@@ -838,6 +838,7 @@ | |||
"antlr4ts": "^0.5.0-alpha.3", | |||
"archiver": "^5.3.1", | |||
"async": "^3.2.3", | |||
"aws4": "^1.12.0", |
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.
need to add aws4
module in order to sign requests to new AWS Bedrock connector. https://www.npmjs.com/package/aws4
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.
Response Ops LGTM! Left a few minor nits but overall looks great.
) => { | ||
try { | ||
assertURL(configObject.apiUrl); | ||
urlAllowListValidator('apiUrl')(configObject, validatorServices); |
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.
is the region always a part of the apiUrl? Is it worth doing any validation that the apiUrl includes the specified region?
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.
so i was playing around with the signature yesterday to see if I really needed to send all those arguments and discovered that i can omit method
, service
and region
and still have successful results.
Looks like they can correctly infer the values from RequestSigner.matchHost()
.Therefore, I think it would be ok to omit the region from the config. WDYT?
FYI, I still need to send host
, it seems the RequestSigner.createHost()
does not get us what we need, here is the error:
Message: Unexpected API Error: ERR_TLS_CERT_ALTNAME_INVALID - Hostname/IP does not match certificate's altnames: Host: .us-east-1.amazonaws.com. is not in the cert's altnames: DNS:bedrock.us-east-1.amazonaws.com
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.
I think if we can omit the region from the connector config, that'd be great. Less chance of user error entering a region that doesn't match the api url
const variables = { domain: 'm0zepcuuu2' }; | ||
|
||
describe('Bedrock - renderParameterTemplates', () => { | ||
it('should not render body on test action', () => { |
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.
in render
, you're returning if the subaction doesn't equal run
or test
, so I'm not sure what the correct behavior is? This test passes because you're using test
but no template to render in the param body
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.
tbh I'm not sure I understand the purpose of renderParameterTemplates, I was following other connector types... in case there are mustache variables used in the test/run json form?
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.
renderParameterTemplates
is an optional function that you can register with the connector type if you need special escaping for some of the parameter values, typically while running or testing the action. This function as is is saying to only use this function for the run or test subaction and to not worry about mustache templating for any of the other subactions. Maybe you want to change it so it only renders the mustache templates during the run subaction? Then this unit test would make sense.
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.
the test and run action are the same
export type BedrockConfig = TypeOf<typeof BedrockConfigSchema>; | ||
export type BedrockSecrets = TypeOf<typeof BedrockSecretsSchema>; | ||
export type BedrockRunActionParams = TypeOf<typeof BedrockRunActionParamsSchema>; | ||
export type InvokeAIActionParams = TypeOf<typeof InvokeAIActionParamsSchema>; |
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: BedrockInvokeAIActionParams
and BedrockInvokeAIActionResponse
for consistency?
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.
@@ -23,7 +23,7 @@ export function getConnectorType(): GenerativeAiConnector { | |||
selectMessage: i18n.translate('xpack.stackConnectors.components.genAi.selectMessageText', { | |||
defaultMessage: 'Send a request to generative AI systems.', |
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.
Should this be Send a request to Open AI systems
?
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.
I'm going to fix all the language/naming in a follow up: #166960
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.
You can preview that PR here: stephmilovic#12
I will reopen against main
once this PR is merged
x-pack/plugins/stack_connectors/server/connector_types/bedrock/bedrock.ts
Outdated
Show resolved
Hide resolved
x-pack/plugins/stack_connectors/server/connector_types/gen_ai/gen_ai.ts
Outdated
Show resolved
Hide resolved
...alerting_api_integration/security_and_spaces/group2/tests/actions/connector_types/bedrock.ts
Show resolved
Hide resolved
return 'Unauthorized API Error'; | ||
} | ||
return `API Error: ${error.response?.status} - ${error.response?.statusText}${ | ||
error.response?.data?.error?.message ? ` - ${error.response.data.error?.message}` : '' |
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.
When I use an invalid model, right now it just returns Error: Status code: 400. Message: API Error: 400 - Bad Request
but there is a more informative error message inside error.response.data.message
that would be useful The provided model identifier is invalid.
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.
Definitely, i kind of breezed over error handling because I have another ticket to clean it up in GenAI connector so I was going to handle all of that at once if that is ok? https://github.com/elastic/security-team/issues/7373
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.
Here is the preview of that PR: stephmilovic#13
I will reopen against main once this PR + stephmilovic#12 are merged
@elasticmachine merge upstream |
@elasticmachine merge upstream |
@elasticmachine merge upstream |
@elasticmachine merge upstream |
@elasticmachine merge upstream |
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]Module Count
Async chunks
Page load bundle
Unknown metric groupsasync chunk count
ESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: |
Summary
New Generative AI connector to support AWS Bedrock. This change will need name change follow up as described here: #166960
Implemented with the sub actions framework. The actions are
runApi
andinvokeAI
.runApi
is the action attached to thetest
sub action.runApi
is responsible for making aPOST
request to the Bedrock API endpoint and returning the response data. This is an example payload of what Bedrock is expecting:Create connector
Test connector
Testing for ResponseOps team
My apologies for doing this all in one PR. Hopefully clear testing expectations will win me points back?
Bedrock credentials
ResponseOps should test that a connector can be created and tested from the Stack Management > Connectors page
Testing for Security Solution team
Bedrock credentials
Security Solution should test that a connectors can be created 3 places within the AI assistant, that multiple connectors can be used in a single conversation, and that the connectors work with both Langchain and non-langchain:
assistantLangChain={false}
, switch it to true or vice versa. You do not need to test the connector creation with langchain and non-langchain, but test sending messages with both langchain and non-langchain to both connector types