Skip to content

DRAFT(query): task support rbac#19427

Draft
TCeason wants to merge 2 commits intodatabendlabs:mainfrom
TCeason:task_owner
Draft

DRAFT(query): task support rbac#19427
TCeason wants to merge 2 commits intodatabendlabs:mainfrom
TCeason:task_owner

Conversation

@TCeason
Copy link
Copy Markdown
Collaborator

@TCeason TCeason commented Feb 9, 2026

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

This PR introduces a complete RBAC (Role-Based Access Control) system for Tasks in Databend, aligning task permission management with the existing ownership model used by databases, tables, UDFs, and other objects.

SQL Syntax

   GRANT CREATE TASK ON *.* TO ROLE <role>
   GRANT OWNERSHIP ON TASK <task_name> TO ROLE <role>

New Privilege Type

  • Added CreateTask privilege (1 << 32) to control who can create tasks.

Task Ownership Model

  • Extended OwnershipObject and GrantObject enums with a Task variant, enabling GRANT OWNERSHIP ON TASK TO ROLE
    syntax.
  • When a task is created, ownership is automatically assigned to the creator's current role.
  • Task ownership is synced to CloudControl via AlterTask(ChangeOwnerRole).

Privilege Enforcement

  • CREATE TASK requires CreateTask privilege on *.*
  • ALTER/DROP/DESCRIBE/EXECUTE TASK requires either task ownership (via role) or Super privilege.
  • system.tasks and system.task_history tables are filtered by ownership — users only see tasks owned by their roles (unless they have Super).

Private Task Mode Support

  • Improved handling for private task mode where CloudControl is not configured — ownership is managed purely through local meta-service.

Tests

  • Unit Test
  • Logic Test
  • Benchmark Test
  • No Test - Explain why

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Breaking Change (fix or feature that could cause existing functionality not to work as expected)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

This change is Reviewable

  Add comprehensive RBAC support for Task objects including:

  **Core Features:**
  - Add GrantObject::Task and OwnershipObject::Task for task-level permissions
  - Add CreateTask privilege type and validate on task creation
  - Enforce ownership/super privilege for alter/drop/desc/execute task
  - Filter system.tasks and system.task_history by owner visibility
  - Rewrite SHOW TASKS to query system.tasks with visibility check
  - Support GRANT/REVOKE ... ON TASK <name> syntax
  - Handle IF EXISTS gracefully in privilege validation

  **CloudControl Sync (for GRANT OWNERSHIP):**
  - Add ChangeOwner enum to AlterTaskRequest proto for owner sync
  - Sync task ownership changes to CloudControl when GRANT OWNERSHIP ON TASK
  - Use CloudControl-first write strategy with rollback on Meta failure
  - Skip CloudControl sync in private task mode (config.task.on)
  - Skip unnecessary RPC when owner is already the same

  **Implementation Details:**
  - Task owner is stored in both CloudControl (Task.owner) and Meta (OwnershipObject)
  - GRANT OWNERSHIP ON TASK now updates both systems atomically
  - Rollback is best-effort with warning logs if Meta update fails
  - Private deployments bypass CloudControl entirely
@TCeason TCeason requested a review from drmingdrmer as a code owner February 9, 2026 01:25
@github-actions github-actions Bot added the pr-feature this PR introduces a new feature to the codebase label Feb 9, 2026
@TCeason TCeason changed the title feat(query): task support rbac DRAFT(query): task support rbac Feb 9, 2026
@TCeason TCeason marked this pull request as draft February 9, 2026 01:30
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 9, 2026

This pull request's title is not fulfill the requirements. @TCeason please update it 🙏.

Valid format:

fix(query): fix group by string bug
  ^         ^---------------------^
  |         |
  |         +-> Summary in present tense.
  |
  +-------> Type: rfc, feat, fix, refactor, ci, docs, chore

Valid types:

  • rfc: this PR proposes a new RFC
  • feat: this PR introduces a new feature to the codebase
  • fix: this PR patches a bug in codebase
  • refactor: this PR changes the code base without new features or bugfix
  • ci: this PR changes build/testing/ci steps
  • docs: this PR changes the documents or websites
  • chore: this PR only has small changes that no need to record

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 12299cd2ef

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/query/storages/system/src/tasks_table.rs Outdated
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 12299cd2ef

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/query/storages/system/src/tasks_table.rs Outdated
  **Private task execution with owner role:**
  - Task SQL now executes with the task owner's role instead of user's default role
  - Added `execute_sql_with_role` method to support role-restricted execution
  - Both task query and WHEN condition evaluation use owner role

  **Private task visibility filtering:**
  - `system.tasks` now filters by ownership for non-admin users in private mode
  - Only task owners (or admin/super users) can see their tasks

  **Private mode task existence check:**
  - `GRANT ... ON TASK` now supports private mode via Meta API
  - `ALTER/DROP TASK IF EXISTS` privilege check uses Meta in private mode
  - No longer requires CloudControl for task existence validation

  **Notes:**
  - `system.task_history` in private mode queries `system_task.task_run` table
  - Users need `SELECT` privilege on `system_task` database to view task history
  - Ownership-based filtering for task_history requires additional implementation
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 9, 2026

🤖 CI Job Analysis

Workflow: 21810002685

📊 Summary

  • Total Jobs: 85
  • Failed Jobs: 2
  • Retryable: 0
  • Code Issues: 2

NO RETRY NEEDED

All failures appear to be code/test issues requiring manual fixes.

🔍 Job Details

  • linux / test_stateless_cluster: Not retryable (Code/Test)
  • linux / test_stateless_standalone: Not retryable (Code/Test)

🤖 About

Automated analysis using job annotations to distinguish infrastructure issues (auto-retried) from code/test issues (manual fixes needed).

@TCeason TCeason removed the request for review from drmingdrmer February 9, 2026 02:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-feature this PR introduces a new feature to the codebase

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants