Skip to main content

GenosDB SM ACLs Module

Overview

The Access Control Lists (ACLs) module provides fine-grained, node-level permissions for GenosDB. Unlike role-based access control (RBAC) which applies global permissions, ACLs allow you to control access to individual nodes, enabling collaborative applications where different users can have different permissions on specific data.

Key Features

  • Node-Level Permissions: Grant/revoke permissions per user per node
  • Flexible Permission Types: read, write, delete
  • Owner-Based Control: Node creators are automatically owners with full permissions
  • Real-Time Synchronization: Permission changes sync across all peers
  • Integration with RBAC: Works alongside existing role-based permissions
  • Automatic Middleware: Enforces permissions on all database operations

How permissions work

Quick Start

1. Enable ACLs

2. Create a Node with ACLs

3. Grant Permissions

4. Check Permissions in Your App

API Reference

db.sm.acls.set(value, id?)

Creates or updates a node with ACL protection. Parameters:
  • value (object): The data to store
  • id (string, optional): Node ID. Auto-generated if not provided
Returns: Promise<string> - The node ID Example:

db.sm.acls.grant(nodeId, userAddress, permission)

Grants a permission to a user for a specific node. Only the owner can grant permissions. Parameters:
  • nodeId (string): The node ID
  • userAddress (string): Ethereum address of the user
  • permission (string): 'read', 'write', or 'delete'
Returns: Promise<void> Example:

db.sm.acls.revoke(nodeId, userAddress)

Revokes all permissions from a user for a specific node. Only the owner can revoke permissions. Parameters:
  • nodeId (string): The node ID
  • userAddress (string): Ethereum address of the user
Returns: Promise<void> Example:

db.sm.acls.delete(nodeId)

Deletes a node. Only the owner can delete their nodes. Parameters:
  • nodeId (string): The node ID to delete
Returns: Promise<void> Example:

db.sm.acls.getPermissions(nodeId)

Gets the permission structure for a node. Parameters:
  • nodeId (string): The node ID
Returns: Promise<{owner: string, collaborators: object}> Example:

Permission Types

read

  • Allows viewing the node’s value and edges
  • Required for db.get(nodeId) operations
  • Does not allow modifications

write

  • Includes read permissions
  • Allows updating the node’s value with db.sm.acls.set()
  • Allows creating edges to/from the node

delete

  • Includes read and write permissions
  • Allows deleting the node with db.sm.acls.delete()
  • Note: delete permission is not automatically granted with write

Integration with RBAC

ACLs work alongside GenosDB’s Role-Based Access Control system:
Permission Evaluation Order:
  1. RBAC Check: User must have the required role permission
  2. ACL Check: If RBAC passes, ACL permissions are checked
  3. Operation: Only executes if both checks pass

Real-World Examples

Collaborative Document Editor

Task Management System

Security Considerations

Owner Privileges

  • Automatic Ownership: Node creators become owners with full permissions
  • Owner-Only Operations: Only owners can grant/revoke permissions and delete nodes
  • No Self-Revocation: Owners cannot revoke their own permissions

Permission Validation

  • Middleware Enforcement: All operations are validated through ACL middleware
  • Real-Time Checks: Permissions are checked before each operation
  • Cryptographic Verification: Operations are signed and verified by all peers
  • Enforced against malicious peers (since 0.14.0): incoming operations are checked in verifyIncomingOperations against the cryptographically-verified author, so a modified peer cannot write a node it does not own — even by bypassing the UI

Best Practices

  1. Validate Permissions Client-Side: Always check permissions before showing UI controls
  2. Handle Permission Errors: Gracefully handle cases where users lose permissions
  3. Use Appropriate Permissions: Grant minimal required permissions
  4. Monitor Access Patterns: Log permission changes for security auditing
  5. Regular Cleanup: Periodically review and revoke unnecessary permissions

Troubleshooting

Common Issues

“No write permission” Error
Permissions not syncing
  • Ensure rtc: true is enabled
  • Check that all peers are connected
  • Verify user addresses are correct (case-sensitive)
Owner cannot be changed
  • Owner is set at creation and cannot be modified
  • To transfer ownership, create a new node and grant permissions

Migration from Manual Permission Checks

If you’re currently using manual permission checks:

Performance Notes

  • Minimal Overhead: ACL checks are performed only when necessary
  • Cached Results: Permission checks use cached node data when available
  • Efficient Queries: Use indexed queries to filter accessible nodes
  • Batch Operations: Group permission checks to reduce network calls

Browser Compatibility

  • Modern Browsers: Full support for all features
  • HTTPS Required: WebAuthn requires secure context
  • P2P Support: WebRTC-enabled browsers for real-time sync
  • Storage: OPFS support for persistent storage

For more examples and advanced usage, see the testbed implementation in the examples directory.