Skip to content

fix(query): validate security policy metadata in planner cache#19897

Merged
TCeason merged 3 commits into
databendlabs:mainfrom
TCeason:data_mask-test
May 21, 2026
Merged

fix(query): validate security policy metadata in planner cache#19897
TCeason merged 3 commits into
databendlabs:mainfrom
TCeason:data_mask-test

Conversation

@TCeason

@TCeason TCeason commented May 20, 2026

Copy link
Copy Markdown
Collaborator

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

Summary

Planner cache used to validate cached plans only by table schema and snapshot. This could reuse a stale plan after row access policy or masking policy metadata changed on a table.

This change records security policy metadata in the planner cache context and compares it on cache lookup. Normal table queries keep the SQL-only cache key. Queries involving security policies use a secure key that also includes tenant, current user, current role, and secondary roles, avoiding cross-user reuse when policy bodies depend on session context such as current_user().

Also enable planner cache in security policy regression suites and add targeted coverage for RAP attach/detach, masking policy set/unset, and same-role different-user masking policy plans.

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

@github-actions github-actions Bot added the pr-bugfix this PR patches a bug in codebase label May 20, 2026

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

Copy link
Copy Markdown

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: 34bfdffcbb

ℹ️ 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/sql/src/planner/planner.rs Outdated
@TCeason TCeason force-pushed the data_mask-test branch 2 times, most recently from cc085ab to f2d2f39 Compare May 20, 2026 14:50
  Planner cache used to validate cached plans only by table schema and
  snapshot. This could reuse a stale plan after row access policy or masking
  policy metadata changed on a table.

  This change records security policy metadata in the planner cache context
  and compares it on cache lookup. Normal table queries keep the SQL-only
  cache key. Queries involving security policies use a secure key that also
  includes tenant, current user, current role, and secondary roles, avoiding
  cross-user reuse when policy bodies depend on session context such as
  current_user().

  Also enable planner cache in security policy regression suites and add
  targeted coverage for RAP attach/detach, masking policy set/unset, and
  same-role different-user masking policy plans.
@TCeason TCeason changed the title fix(query): include current role in planner cache key to prevent masking policy bypass fix(query): validate security policy metadata in planner cache May 21, 2026
@TCeason TCeason added this pull request to the merge queue May 21, 2026
Merged via the queue into databendlabs:main with commit a279781 May 21, 2026
92 checks passed
@TCeason TCeason deleted the data_mask-test branch May 21, 2026 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-bugfix this PR patches a bug in codebase

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants