Repository navigation
feat: support role hierarchy, clean up orphaned permissions, and add RBAC to SDK and dashboard. - #101
Merged
Merged
Conversation
…RBAC to SDK and dashboard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements Phase 2: RBAC (Role-Based Access Control) for AgentGuard, introducing granular, time-bounded resource permissions along with full integration across the smart contract, TypeScript SDK, and operator dashboard.
In addition to core RBAC operations (
grant_permission,revoke_permission,check_access), this changeset resolves three critical system requirements:check_accessnow evaluates role inheritance (Admin >= Premium >= Basic), allowing higher-tier permission grants to satisfy lower-tier access requirements on a resource.DataKey::AgentPermissions), ensuringderegister_agentcompletely purges all active permissions and eliminates orphaned entries if an address is re-registered.@agentguard/sdkclient and HTTP middleware, and added interactive resource permission management and simulation verification to the console dashboard.Changes
1. Soroban Smart Contract (
contracts/agent_guard/)grant_permission(owner, agent_id, resource_id, role, expires_at): Authenticates owner, validatesexpires_at > ledger_timestamp, records grant in persistent storage, and updates the agent index.revoke_permission(owner, agent_id, resource_id, role): Validates ownership and existing grant, removes entry from persistent storage, and removes key from the agent index.check_access(agent_id, resource_id, required_role): Checks agent status (Active) and inspects candidate roles in descending order (Admin→Premium→Basic). Returnstrueif any unexpired grant satisfies or exceedsrequired_role.deregister_agentreads all indexedPermissionKeys for the agent, invokesdelete_permissionon each, and clearsDataKey::AgentPermissions(agent_id).ResourceRoleGrantedandResourceRoleRevokedcontract events with indexed topics foragent_idandresource_id.2. TypeScript SDK (
sdk/)AgentGuardClient):checkAccess(agentPublicKey, resourceId, requiredRole): Promise<boolean>.requireAccess(agentPublicKey, resourceId, requiredRole): Promise<void>.grantPermission(...)andrevokePermission(...)transaction builders.Permissioninterface andAgentPermissionDeniedError.enforceAgentPermission(...)andrequirePermission(guard, resourceId, role)for route-level authorization viax-agent-public-key.3. Operator Console & Dashboard (
dashboard/)AgentDetail.tsx):Verify.tsx):verify_agent) and Resource Permission (check_access).demo.ts/session.tsx):settlement_api).checkAccess,grantPermission, andrevokePermission.Test & Verification Results
cargo testcargo clippy --workspace --all-targets -- -D warningscargo fmt --all -- --checknpm run build(insdk/)tsc)npm run build(indashboard/)Key Test Scenarios Covered
Adminpermission satisfiesPremiumandBasicaccess checks on the target resource.Premiumpermission satisfiesBasic, but rejectsAdmin.falseupon reaching or exceeding ledger timestamp.check_accessregardless of permission validity.deregister_agentpermanently deletes all permission entries from storage; subsequent re-registration of the same address has zero leftover access.