feat: Rust SDK crate (agentmesh-rust) for native governance integration#563
Conversation
- mcp-proxy: shebang must be line 1 (TS18026) - copilot, mcp-server: typescript ^6.0.2 → ^5.7.0 (eslint <6.0.0) - NuGet: replace ESRP Sign+Release with NuGetCommand@2 push via NuGet.org service connection Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…crosoft#557, microsoft#558) Upstream bug fixes from AzureClaw vendored agentmesh-sdk: TypeScript SDK (identity.ts): - Add stripKeyPrefix() — strips ed25519:/x25519: prefixes before base64 decoding (fixes key decode failures with typed key formats) - Add safeBase64Decode() — convenience wrapper for safe prefix-aware decoding - Update fromJSON() to use safeBase64Decode() so serialized keys with type prefixes round-trip correctly - Export both functions from index.ts Proto (registration.proto): - Add GovernanceService with EvaluatePolicy, RecordAudit, GetTrustScore RPCs for language-agnostic governance integration - Add PolicyRequest, PolicyDecision, AuditEntry, AuditAck, TrustQuery, TrustScoreResult message types Tests: - 12 new tests in key-prefix.test.ts covering prefix stripping, safe decode, and fromJSON round-trip with prefixed keys Closes microsoft#557, Closes microsoft#558 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ration Implements Phase 1 (P0) and Phase 2 (P1) of issue microsoft#556: Phase 1 — Core governance (P0): - policy.rs: YAML-based policy evaluation with 4-way decisions (allow/deny/requires-approval/rate-limit), wildcard patterns, condition matching, and scoped capability rules - trust.rs: Trust scoring (0-1000, 5 tiers) with configurable reward/penalty, threshold checks, and optional JSON persistence - audit.rs: SHA-256 hash-chain audit logging with tamper detection, integrity verification, and filtered queries - types.rs: Shared types (PolicyDecision, TrustTier, TrustScore, AuditEntry, GovernanceResult) Phase 2 — Identity (P1): - identity.rs: Ed25519 agent identity via ed25519-dalek with DID generation, sign/verify, and JSON serialization Unified client (lib.rs): - AgentMeshClient combining all modules with execute_with_governance pipeline (policy → audit → trust update) Includes 30 unit tests + 1 doc-test, all passing. Follows Go SDK patterns and aligns with AzureClaw governance.rs. Closes microsoft#556 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
🤖 AI Agent: security-scanner — Security Review for `feat: Rust SDK crate (agentmesh-rust) for native governance integration`Security Review for
|
| Finding | Rating | Recommendation Summary |
|---|---|---|
| Prompt injection defense bypass | 🔴 CRITICAL | Validate policy_yaml input using a strict schema. |
| Policy engine circumvention | 🟠 HIGH | Enforce governance pipeline routing for all actions. |
| Trust chain weaknesses | 🟠 HIGH | Implement SPIFFE/SVID validation and certificate pinning. |
| Credential exposure | 🔴 CRITICAL | Avoid logging sensitive information; update documentation with warnings. |
| Sandbox escape | 🔵 LOW | Document sandboxing requirements for untrusted environments. |
| Deserialization attacks | 🟠 HIGH | Validate YAML/JSON input against schemas before deserialization. |
| Race conditions | 🟡 MEDIUM | Use synchronization primitives for thread-safe audit log updates. |
| Supply chain risks | 🟡 MEDIUM | Use cargo-audit, pin dependencies, and consider vendorizing critical crates. |
Final Recommendation
This pull request introduces critical functionality to the microsoft/agent-governance-toolkit repository, but it has several security concerns that need to be addressed before merging. The most critical issues are related to prompt injection defense and credential exposure, as they could lead to significant security vulnerabilities. Addressing these issues is essential to ensure the integrity and security of the AgentMesh governance framework.
There was a problem hiding this comment.
🤖 AI Agent: code-reviewer
Review of PR: feat: Rust SDK crate (agentmesh-rust) for native governance integration
🔴 CRITICAL: Security Issues
-
Policy Evaluation Logic (policy.rs):
- Issue: The policy evaluation logic in
policy.rsis not provided in the PR. Without reviewing the implementation, it is impossible to verify the correctness of the 4-way decision-making process (allow/deny/requires-approval/rate-limit). Any flaws in this logic could lead to security bypass. - Action: Provide the full implementation of the policy evaluation logic for review. Ensure that all edge cases are covered, including:
- Proper handling of wildcard action patterns.
- Correct evaluation of conditions.
- Prevention of bypasses due to malformed or unexpected inputs.
- Handling of conflicting rules (e.g., when multiple rules match an action).
- Issue: The policy evaluation logic in
-
Trust Scoring (trust.rs):
- Issue: The trust scoring mechanism relies on configurable reward/penalty values and thresholds. If these values are not properly validated or if there are logic errors, it could lead to trust escalation or denial of service.
- Action: Ensure that the trust scoring logic is robust and includes safeguards against:
- Arbitrary manipulation of trust scores.
- Overflow/underflow in score calculations.
- Inconsistent trust tier assignments.
-
Audit Logging (audit.rs):
- Issue: The tamper-evident audit log implementation is not provided in the PR. Without reviewing the hash-chain implementation, it is unclear if it is resistant to tampering or replay attacks.
- Action: Provide the implementation of the audit log for review. Ensure:
- Proper use of cryptographic primitives (e.g., SHA-256) for hash chaining.
- Prevention of hash collisions.
- Verification of the integrity of the entire chain, not just individual entries.
-
Agent Identity (identity.rs):
- Issue: The
identity.rsmodule uses theed25519-dalekcrate for cryptographic operations. While this is a well-regarded library, the implementation details (e.g., key generation, signing, and verification) are not provided in the PR. - Action: Provide the implementation of
identity.rsfor review. Verify:- Proper key generation and storage practices.
- Secure handling of private keys (e.g., avoiding memory leaks, using zeroization).
- Correct implementation of signing and verification processes.
- Issue: The
-
Sandbox Escape Vectors:
- Issue: The PR does not provide any information about sandboxing or isolation mechanisms for the Rust SDK. This is critical for preventing malicious agents from escaping their execution environment.
- Action: Clarify the sandboxing strategy for the Rust SDK. If no sandboxing is implemented, this is a significant security risk that must be addressed.
🟡 WARNING: Potential Breaking Changes
-
GovernanceService in
registration.proto:- Issue: The addition of the
GovernanceServiceand its associated RPCs (EvaluatePolicy,RecordAudit,GetTrustScore) inregistration.protois a breaking change for any clients consuming this protocol. Existing clients will need to update their implementations to handle these new RPCs. - Action: Clearly document this breaking change in the release notes and communicate it to downstream consumers. Consider versioning the protocol to avoid breaking existing clients.
- Issue: The addition of the
-
Unified Client (
AgentMeshClient):- Issue: The
AgentMeshClientintroduces a new governance pipeline (execute_with_governance). If this replaces an existing method or changes its behavior, it could break existing integrations. - Action: Ensure backward compatibility by maintaining the old method (if applicable) or providing a clear migration guide for users.
- Issue: The
💡 Suggestions for Improvement
-
Test Coverage:
- While the PR mentions 31 tests, it is unclear if they cover all edge cases, especially for security-critical components like policy evaluation, trust scoring, and audit logging.
- Action: Provide a detailed breakdown of test cases and their coverage. Include tests for:
- Invalid or malformed inputs.
- Edge cases in policy evaluation (e.g., overlapping rules, conflicting conditions).
- Tampering attempts on the audit log.
- Replay attacks on the identity module.
-
Concurrency and Thread Safety:
- Issue: The PR does not mention whether the Rust SDK is thread-safe. This is critical for concurrent agent execution.
- Action: Ensure that all shared state (e.g., trust scores, audit logs) is properly synchronized. Use thread-safe data structures like
Arc<Mutex<T>>orRwLockwhere necessary. Add tests for concurrent execution scenarios.
-
Error Handling:
- Issue: The PR mentions the use of the
thiserrorcrate for error handling but does not provide details on how errors are propagated or logged. - Action: Ensure that all errors are properly handled and logged. Avoid leaking sensitive information in error messages.
- Issue: The PR mentions the use of the
-
Documentation:
- Issue: The PR lacks detailed documentation for the Rust SDK, especially for the
AgentMeshClientand its governance pipeline. - Action: Add comprehensive documentation, including:
- Examples of how to use the SDK.
- Detailed explanations of the governance pipeline and its components.
- Guidelines for configuring policies, trust scoring, and audit logging.
- Issue: The PR lacks detailed documentation for the Rust SDK, especially for the
-
Dependency Audit:
- Issue: The
serde_yamlcrate is marked as deprecated in theCargo.lockfile. - Action: Replace
serde_yamlwith a maintained alternative or verify that the deprecation does not pose a security risk.
- Issue: The
-
Performance Considerations:
- Issue: The PR does not mention any performance benchmarks for the Rust SDK, especially for critical operations like policy evaluation and audit logging.
- Action: Conduct performance testing and provide benchmarks. Optimize any identified bottlenecks.
-
Cross-Language Consistency:
- Issue: The Rust SDK is designed to match the Go SDK's
ExecuteWithGovernancepattern. However, there is no mention of how consistency between the SDKs is ensured. - Action: Add tests or documentation to verify that the Rust SDK behaves identically to the Go SDK for the same inputs.
- Issue: The Rust SDK is designed to match the Go SDK's
Summary of Actionable Feedback
🔴 CRITICAL
- Provide the full implementation of
policy.rsfor review to ensure correctness and prevent security bypass. - Ensure the trust scoring mechanism in
trust.rsis robust and resistant to manipulation. - Provide the implementation of
audit.rsfor review to verify the integrity of the tamper-evident audit log. - Provide the implementation of
identity.rsfor review to ensure secure cryptographic operations. - Clarify and implement sandboxing or isolation mechanisms to prevent sandbox escape.
🟡 WARNING
- Document the breaking changes introduced by the new
GovernanceServiceinregistration.proto. - Ensure backward compatibility for the
AgentMeshClientand provide a migration guide if necessary.
💡 SUGGESTION
- Provide a detailed breakdown of test coverage and add tests for edge cases and security scenarios.
- Ensure thread safety for concurrent agent execution.
- Improve error handling and logging to avoid leaking sensitive information.
- Replace the deprecated
serde_yamlcrate or verify its security implications. - Conduct performance testing and provide benchmarks for critical operations.
- Ensure cross-language consistency between the Rust SDK and the Go SDK.
Please address the critical issues and warnings before merging this PR. Let me know if you need further clarification or assistance!
There was a problem hiding this comment.
🤖 AI Agent: code-reviewer
Pull Request Review: Rust SDK Crate for AgentMesh Governance Framework
🔴 CRITICAL: Security Issues
-
Policy Engine Correctness (False Negatives):
- The policy engine in
policy.rssupports YAML-based configurations with wildcard action patterns and condition matching. However, there is no mention of how invalid or malformed YAML configurations are handled. If the YAML parser fails silently or defaults to permissive behavior, it could lead to false negatives, allowing unauthorized actions.- Action: Add strict validation for YAML configurations and ensure that invalid configurations result in a hard failure with clear error messages.
- The policy engine in
-
Trust Scoring Logic:
- The trust scoring mechanism in
trust.rsis critical for enforcing governance. However, there is no mention of safeguards against integer overflow when calculating trust scores (e.g., adding rewards or penalties). This could lead to incorrect trust evaluations.- Action: Use Rust's
checked_add,checked_sub, or similar methods to prevent overflow in trust score calculations.
- Action: Use Rust's
- The trust scoring mechanism in
-
Audit Log Integrity:
- The audit log uses a SHA-256 hash chain for tamper detection. However, there is no mention of how the initial hash (genesis hash) is securely established or how the chain is protected against rollback attacks.
- Action: Document and implement a mechanism to securely establish and verify the genesis hash. Consider using a trusted timestamping service or cryptographic signatures to prevent rollback attacks.
- The audit log uses a SHA-256 hash chain for tamper detection. However, there is no mention of how the initial hash (genesis hash) is securely established or how the chain is protected against rollback attacks.
-
Ed25519 Key Management:
- The
identity.rsmodule usesed25519-dalekfor key generation and signing. However, there is no mention of how private keys are securely stored or managed. If private keys are exposed, the entire identity system is compromised.- Action: Implement secure key storage mechanisms (e.g., hardware security modules, encrypted files) and document best practices for key management.
- The
-
Sandbox Escape Vectors:
- The
execute_with_governancemethod inAgentMeshClientprocesses actions, including potentially dangerous ones likeshell:*. There is no mention of how these actions are executed or whether they are sandboxed. If shell commands are executed directly, this could lead to sandbox escapes or remote code execution.- Action: Ensure that all actions, especially shell commands, are executed in a secure sandboxed environment. Validate and sanitize all inputs to prevent command injection.
- The
🟡 WARNING: Potential Breaking Changes
-
Public API Stability:
- The
README.mdmentions that the SDK is in "Public Preview" and that APIs may change before version 1.0. This could lead to breaking changes for early adopters.- Action: Clearly document any planned breaking changes in the release notes and provide migration guides for users.
- The
-
Dependency on Deprecated Crates:
- The
serde_yamlcrate is marked as0.9.34+deprecated. Using deprecated crates could lead to compatibility issues in the future.- Action: Replace
serde_yamlwith a maintained alternative or confirm that the deprecation does not impact the SDK's functionality.
- Action: Replace
- The
💡 Suggestions for Improvement
-
Thread Safety:
- The SDK does not explicitly mention whether
AgentMeshClientor its components are thread-safe. Since concurrent agent execution is a focus area, this should be clarified.- Action: Use Rust's
SendandSynctraits to enforce thread safety where applicable. Add tests to verify thread-safe behavior under concurrent usage.
- Action: Use Rust's
- The SDK does not explicitly mention whether
-
Type Safety and Validation:
- The shared types in
types.rs(e.g.,PolicyDecision,TrustScore) should enforce stricter validation. For example,TrustScoreshould ensure that values are within the valid range (0–1000).- Action: Use Rust's
newtypepattern or custom constructors to enforce invariants at compile time.
- Action: Use Rust's
- The shared types in
-
Backward Compatibility Tests:
- There is no mention of tests to ensure backward compatibility with existing Go and TypeScript SDKs.
- Action: Add integration tests to verify that the Rust SDK produces the same results as the Go and TypeScript SDKs for identical inputs.
- There is no mention of tests to ensure backward compatibility with existing Go and TypeScript SDKs.
-
Documentation Improvements:
- The
README.mdprovides a good overview, but it lacks detailed examples for advanced use cases (e.g., rate-limiting policies, multi-agent scenarios).- Action: Expand the documentation with more examples and edge cases to help users understand the full capabilities of the SDK.
- The
-
Minimal Dependencies:
- While the SDK uses well-known crates, some dependencies (e.g.,
rand,serde_yaml) could be replaced with lighter alternatives to reduce the attack surface and improve performance.- Action: Audit dependencies and replace heavy or unnecessary ones with lighter alternatives.
- While the SDK uses well-known crates, some dependencies (e.g.,
General Observations
- The implementation appears to follow Rust best practices, such as using
thiserrorfor error handling andserdefor serialization. - The use of
ed25519-dalekis appropriate for cryptographic operations, but care must be taken to ensure secure key management. - The inclusion of 31 tests is a good start, but additional tests for edge cases, thread safety, and backward compatibility are recommended.
Summary of Actions
-
Critical Security Fixes:
- Validate YAML configurations to prevent false negatives.
- Prevent integer overflow in trust scoring.
- Secure the audit log's genesis hash and prevent rollback attacks.
- Implement secure key storage for Ed25519 private keys.
- Ensure sandboxing and input validation for action execution.
-
Warnings:
- Document potential breaking changes and provide migration guides.
- Replace deprecated dependencies like
serde_yaml.
-
Suggestions:
- Ensure thread safety with
SendandSynctraits. - Enforce stricter type safety with
newtypepatterns. - Add backward compatibility tests with Go and TypeScript SDKs.
- Expand documentation with advanced examples.
- Audit and optimize dependencies.
- Ensure thread safety with
By addressing these issues, the Rust SDK can become a robust and secure addition to the AgentMesh governance framework.
Summary
Implements the �gentmesh Rust SDK crate as proposed in #556 — Phase 1 (P0) and Phase 2 (P1).
Phase 1 — Core governance (P0)
Phase 2 — Identity (P1)
Unified client
\AgentMeshClient\ combines all modules with \�xecute_with_governance()\ pipeline (policy → audit → trust update), matching the Go SDK's \ExecuteWithGovernance\ pattern.
Tests
31 tests passing (30 unit tests + 1 doc-test) covering:
Dependencies
Minimal, well-known crates: \serde, \serde_yaml, \serde_json, \sha2, \�d25519-dalek,
and, \ hiserror.
Location
\packages/agent-mesh/sdks/rust/agentmesh/\ — alongside existing Go and TypeScript SDKs.
Closes #556