-
Notifications
You must be signed in to change notification settings - Fork 186
Address Security issues in Connector and Agent #4380
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: main
Are you sure you want to change the base?
Address Security issues in Connector and Agent #4380
Conversation
mingshl
left a comment
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.
LGTM
|
Failed because of irrelevant error: |
common/src/main/java/org/opensearch/ml/common/transport/connector/MLCreateConnectorInput.java
Show resolved
Hide resolved
.../src/test/java/org/opensearch/ml/common/transport/connector/MLCreateConnectorInputTests.java
Show resolved
Hide resolved
Signed-off-by: rithin-pullela-aws <rithinp@amazon.com>
WalkthroughProtocol values in connector tests updated from "testProtocol" to "http". Null-tolerant parsing added to ConnectorAction. Robust validation introduced for connector credentials, backend roles, and protocol with strict type checking. Error messages simplified in connector and agent components. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
common/src/test/java/org/opensearch/ml/common/transport/connector/MLCreateConnectorInputTests.java (1)
169-172: Consider the maintainability of hardcoded protocol lists.The error message now includes an enumeration of valid protocols. While this improves clarity, it creates a maintenance point—whenever protocols are added or removed, this test expectation must be updated. The past review comment suggests using
ConnectorProtocols.VALID_PROTOCOLSdynamically or using acontains()check instead of exact string matching.Consider using a more flexible assertion:
- assertEquals( - "Connector protocol is null. Please use one of [aws_sigv4, http, mcp_sse, mcp_streamable_http]", - exception.getMessage() - ); + assertTrue(exception.getMessage().contains("Connector protocol is null")); + assertTrue(exception.getMessage().contains("aws_sigv4")); + assertTrue(exception.getMessage().contains("http"));Or verify the error message is generated from
ConnectorProtocols.VALID_PROTOCOLSif that's available in the implementation.Based on learnings, past review suggested using
ConnectorProtocols.VALID_PROTOCOLSorcontains()API to avoid maintaining hardcoded protocol lists.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
client/src/test/java/org/opensearch/ml/client/MachineLearningClientTest.java(1 hunks)client/src/test/java/org/opensearch/ml/client/MachineLearningNodeClientTest.java(1 hunks)common/src/main/java/org/opensearch/ml/common/connector/ConnectorAction.java(1 hunks)common/src/main/java/org/opensearch/ml/common/transport/connector/MLCreateConnectorInput.java(4 hunks)common/src/test/java/org/opensearch/ml/common/transport/connector/MLCreateConnectorInputTests.java(2 hunks)memory/src/main/java/org/opensearch/ml/memory/index/InteractionsIndex.java(1 hunks)ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/agent/MLAgentExecutor.java(2 hunks)
🔇 Additional comments (11)
memory/src/main/java/org/opensearch/ml/memory/index/InteractionsIndex.java (1)
356-358: LGTM! Security improvement by removing user-provided ID from error message.This change aligns with the PR objective to prevent printing unknown trace/message IDs in the traces API, avoiding potential reflection of user-controlled input in error responses.
ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/agent/MLAgentExecutor.java (2)
188-189: LGTM! Security improvement by using generic error message.The original exception is logged for debugging while returning a sanitized error to the client, preventing potential information leakage about agents.
351-357: LGTM! Security improvement by removing user-provided agent ID from error message.This prevents reflection of potentially untrusted user input in error responses.
common/src/main/java/org/opensearch/ml/common/connector/ConnectorAction.java (1)
164-203: LGTM! Null-tolerant parsing with deferred validation.Using
textOrNull()allows parsing to complete gracefully, deferring validation to the constructor where meaningful error messages are produced (lines 72-80). This prevents 500-level parsing errors and instead returns proper validation errors for nullactionType,url, ormethod.common/src/main/java/org/opensearch/ml/common/transport/connector/MLCreateConnectorInput.java (3)
110-110: LGTM! Improved protocol validation with informative error messages.Using
validateProtocol()provides clearer error messages that include the list of valid protocols when validation fails.
184-198: LGTM! Robust credential parsing with type validation.This prevents nested JSON objects in credentials and provides clear error messages. The token type (not value) is included in the exception message, which is safe from a security perspective.
206-218: LGTM! Backend roles validation with proper type checking.This prevents JSON objects in the backend_roles array. The inclusion of
VALUE_NUMBERallows numeric role identifiers.Consider whether
VALUE_NUMBERis intentional for backend roles. Typically backend roles are string identifiers. If numeric roles are not expected, this could be tightened:- if (parser.currentToken() != XContentParser.Token.VALUE_STRING - && parser.currentToken() != XContentParser.Token.VALUE_NUMBER - && parser.currentToken() != XContentParser.Token.VALUE_NULL) { + if (parser.currentToken() != XContentParser.Token.VALUE_STRING + && parser.currentToken() != XContentParser.Token.VALUE_NULL) {client/src/test/java/org/opensearch/ml/client/MachineLearningClientTest.java (1)
469-469: LGTM! Test updated to use valid protocol.The protocol change from
"testProtocol"to"http"aligns with the new stricter validation invalidateProtocol()that only accepts valid protocols.client/src/test/java/org/opensearch/ml/client/MachineLearningNodeClientTest.java (1)
1036-1036: LGTM! Valid protocol value used in test.Updating from "testProtocol" to "http" aligns with stricter protocol validation introduced in this PR.
common/src/test/java/org/opensearch/ml/common/transport/connector/MLCreateConnectorInputTests.java (2)
568-592: LGTM! Robust validation for backend roles.This test ensures that backend roles containing JSON objects (instead of strings) are rejected with a clear error message, preventing potential 500-level errors mentioned in the PR objectives.
594-616: LGTM! Robust validation for credentials.This test ensures that credential values containing JSON objects are rejected with a clear error message, preventing potential 500-level errors mentioned in the PR objectives.
Description
This PR addresses some security issues:
Connector:
Agent:
Related Issues
Resolves #[Issue number to be closed when this PR is merged]
Check List
--signoff.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.
Summary by CodeRabbit
Bug Fixes
Improvements
✏️ Tip: You can customize this high-level summary in your review settings.