Skip to content

Conversation

@kevintang2022
Copy link
Contributor

@kevintang2022 kevintang2022 commented Dec 1, 2025

Description

When initialzing a view identity for definer mode permission checks, the reason for select is passed in as empty. This PR ensures that the same reason for select in the invoker's identity is used.

Motivation and Context

When checking definer mode view permissions, the reason for select is always set to empty, which means that permissions checks for table will contain a reason for select but for the same query, the permission check of the underlying base tables for a definer mode view will always be empty, leading to a mismatch in reason for select.

Impact

No impact on permissions checking behavior. The reason for select will now be made available for use in authorization checks for base tables of a definer mode view.

Test Plan

No impact, and existing tests pass.

Contributor checklist

  • Please make sure your submission complies with our contributing guide, in particular code style and commit standards.
  • PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced.
  • Documented new properties (with its default value), SQL syntax, functions, or other functionality.
  • If release notes are required, they follow the release notes guidelines.
  • Adequate tests were added if applicable.
  • CI passed.
  • If adding new dependencies, verified they have an OpenSSF Scorecard score of 5.0 or higher (or obtained explicit TSC approval for lower scores).

Release Notes

Please follow release notes guidelines and fill in the release notes below.

== NO RELEASE NOTE ==

Differential Revision: D88055399

Summary: title

Differential Revision: D88055399
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Dec 1, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Updates Identity construction in definer-mode and system sessions to pass through additional fields such as empty roles, catalogs, and reasonForSelect, ensuring view and materialized view queries run under a fully populated Identity consistent with the current session/connector identity.

Class diagram for Identity usage in definer and system sessions

classDiagram
    class Identity {
        - String user
        - Optional principal
        - Map roles
        - Map extraCredentials
        - Map catalogProperties
        - Optional tenant
        - Optional reasonForSelect
        - List clientTags
        + Identity(user, principal, roles, extraCredentials, catalogProperties, tenant, reasonForSelect, clientTags)
    }

    class Session {
        - Identity identity
        + Identity getIdentity()
    }

    class ConnectorIdentity {
        - String user
        - Optional principal
        - Map extraCredentials
        - Optional reasonForSelect
        + String getUser()
        + Optional getPrincipal()
        + Map getExtraCredentials()
        + Optional getReasonForSelect()
    }

    class StatementAnalyzer {
        + Scope processMaterializedView(session, owner, accessControl)
        + RelationType analyzeView(query, name, owner, session, accessControl)
    }

    class MaterializedViewUtils {
        + static Session buildOwnerSession(session, owner, accessControl)
        + static Identity getOwnerIdentity(owner, session)
    }

    class SystemConnectorSessionUtil {
        + static Session toSession(transactionHandle, connectorSession)
    }

    class ViewAccessControl {
        + ViewAccessControl(accessControl)
    }

    Session --> Identity : has
    ConnectorIdentity --> Identity : converted_to
    StatementAnalyzer --> Identity : constructs_for_definer_mode
    MaterializedViewUtils --> Identity : constructs_owner_identity
    SystemConnectorSessionUtil --> Identity : constructs_system_identity
    StatementAnalyzer --> ViewAccessControl : uses_in_definer_mode
    SystemConnectorSessionUtil --> Session : builds
    MaterializedViewUtils --> Session : builds_owner_session
Loading

File-Level Changes

Change Details Files
Update Identity creation for definer-mode view/materialized view analysis to use the expanded constructor and propagate reasonForSelect and other fields from the session identity.
  • Replace minimal Identity(owner, principal, extraCredentials) construction in materialized view processing with the full-parameter Identity constructor, passing empty maps/lists for roles and related fields, and propagating session.getIdentity().getReasonForSelect().
  • Replace minimal Identity(owner, principal, extraCredentials) construction when analyzing views in definer mode with the full-parameter Identity constructor using empty maps/lists and the session identity’s reasonForSelect.
presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/StatementAnalyzer.java
Align SystemConnectorSessionUtil’s session reconstruction with the expanded Identity fields, including reasonForSelect, to avoid losing context when crossing connector boundaries.
  • Update Identity construction from ConnectorIdentity to use the full constructor, passing empty maps/lists for new fields and forwarding connectorIdentity.getReasonForSelect().
presto-main-base/src/main/java/com/facebook/presto/connector/system/SystemConnectorSessionUtil.java
Ensure owner-based materialized view sessions use a fully populated Identity that forwards reasonForSelect and other new fields from the caller’s session.
  • Change getOwnerIdentity to construct Identity with the expanded constructor when impersonating the owner, using empty maps/lists and propagating session.getIdentity().getReasonForSelect().
presto-main-base/src/main/java/com/facebook/presto/sql/MaterializedViewUtils.java

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants