Course contentsShow
← Software Engineering
Lesson 1029 of 1,93331. Authentication and AuthorizationFree lesson

Resource-Based and Relationship-Based Authorization

Explore resource ownership patterns and relationship-based models like Google Zanzibar for complex permission graphs.

Resource-Based and Relationship-Based Authorization

What you'll learn: How to model authorization based on who owns a resource and who has relationships with whom, enabling fine-grained access control beyond simple roles.

The Ownership Problem

Traditional RBAC gives users roles like "editor" or "viewer," but it doesn't naturally handle questions like: "Can Alice edit this specific document?" The answer often depends on resource ownership (Alice created it) or relationships (Bob shared it with Alice).

Resource-Based Authorization

Resource-based authorization ties permissions directly to individual resources. Each resource tracks who owns it and who has specific permissions. Think of Google Docs: you can share one document with Alice (editor access) and a different document with Bob (view-only), without giving them system-wide roles.

The authorization check becomes: "Does User X have permission Y on Resource Z?"

# Conceptual check
if document.owner == current_user or current_user in document.editors:
    allow_edit()

This scales poorly for complex permission graphs, though.

Relationship-Based Authorization (Google Zanzibar)

Relationship-based models like Google Zanzibar represent permissions as a graph of relationships. Instead of storing permissions redundantly, you define relationships like:

  • "Alice is an owner of Document123"
  • "Document123 is in Folder456"
  • "Bob is a viewer of Folder456"

The system infers: Bob can view Document123 because of the transitive viewer relationship through the folder.

This approach handles inheritance, groups, nested resources, and delegation elegantly. It answers: "What are all the paths connecting this user to this resource?"

When to Use Each

  • Resource-based: Simple ownership (blog posts, user profiles, tasks)
  • Relationship-based: Complex hierarchies (org charts, nested folders, shared workspaces)

Key Takeaway: Resource-based authorization ties permissions to individual objects, while relationship-based models like Zanzibar use permission graphs to handle complex, transitive access patterns efficiently.