Add system for get_required_privileges by seoc01 · Pull Request #605 · documentdb/documentdb · GitHub
Skip to content

Add system for get_required_privileges - #605

Open
seoc01 wants to merge 1 commit into
documentdb:mainfrom
seoc01:rbac
Open

seoc01 wants to merge 1 commit into
documentdb:mainfrom
seoc01:rbac

Conversation

@seoc01

@seoc01 seoc01 commented May 8, 2026

Copy link
Copy Markdown

Summary

This change implements the foundational authorization privilege extraction system for DocumentDB, introducing a new get_required_privileges() function that analyzes MongoDB commands and returns the required resource privileges needed to execute them. This is the first step in building a MongoDB-compatible Role-Based Access Control (RBAC) system.

Overview

This CR introduces a static privilege extraction system that:

  1. Parses MongoDB command BSON specifications
  2. Determines which resources (database/collection) are accessed
  3. Identifies what privilege actions (find, insert, update, etc.) are required
  4. Internal UDF for testing privilege extraction for commands

Current Scope: Implements extraction for find commands as a proof-of-concept. Future commands will follow the same pattern.

Test Coverage (authorization_get_required_privileges_find.sql - 16 tests)

PostgreSQL Interface:

  • command_get_required_privileges() - PG_FUNCTION_INFO_V1 wrapper
    • Input: BSON command specification
    • Output: BSON with format:
      {
        "ok": 1.0,
        "canDeterminePrivileges": true,
        "privileges": [
          {
            "resource": {"db": "test", "collection": "users"},
            "actions": ["find"]
          }
        ]
      }
    • Returns canDeterminePrivileges: false for unsupported commands

Positive Test Cases:

  • Basic find command
  • Find with filters, projections, sort
  • Different collections and databases
  • Special characters in collection names
  • Boundary conditions (very long names)

@seoc01
seoc01 requested a review from a team as a code owner May 8, 2026 20:21
@documentdb-triage-tool documentdb-triage-tool Bot added the enhancement New feature or request label May 8, 2026
@documentdb-triage-tool

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request write-operations

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

1 participant