Skip to content

Conversation

andythsu
Copy link
Member

@andythsu andythsu commented Aug 5, 2025

Description

Use identity's groups instead of OriginalIdentity's groups in session. Issue is described here

This PR specifically resolves Option 2 in the issue

Release notes

( ) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
(X) Release notes are required, with the following suggested text:

## Section
* Fix access control check when access is granted through groups in `SET SESSION AUTHORIZATION`  ({issue}`26344`)

@cla-bot cla-bot bot added the cla-signed label Aug 5, 2025
@andythsu andythsu requested a review from homar August 5, 2025 15:29
@wendigo wendigo requested a review from kokosing August 6, 2025 06:23
@kokosing
Copy link
Member

kokosing commented Aug 6, 2025

@homar can you please provide the review here?

@kokosing
Copy link
Member

kokosing commented Aug 6, 2025

@andythsu can you please provide unit tests?

@homar
Copy link
Member

homar commented Aug 6, 2025

@homar can you please provide the review here?

Yep that was clearly a mistake from my side. If you check SessionRepresentation it is clear that we need groups from identity here not originalIdentity.
However adding a test would be very beneficial

@kokosing
Copy link
Member

kokosing commented Aug 6, 2025

I believe such test could be added to TestImpersonation.

@andythsu
Copy link
Member Author

andythsu commented Aug 6, 2025

There's also https://github.com/trinodb/trino/blob/master/testing/trino-tests/src/test/java/io/trino/execution/TestUserImpersonationAccessControl.java that although the name suggests "test impersonation", there are no tests in this file that actually touches on the impersonation part. I believe we can merge it with https://github.com/trinodb/trino/blob/master/testing/trino-tests/src/test/java/io/trino/security/TestAccessControl.java. Thoughts? (I can do it in a separate PR)

Copy link

cla-bot bot commented Aug 6, 2025

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: asu80.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email [email protected]
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

@andythsu
Copy link
Member Author

andythsu commented Aug 6, 2025

@kokosing I added a unit test

Copy link
Member

@kokosing kokosing left a comment

Choose a reason for hiding this comment

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

Thank you!

@Timeout(10)
public void testSessionRepresentationReturnsCorrectGroupsDuringImpersonation()
{
// given
Copy link
Member

Choose a reason for hiding this comment

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

please remove these comments.

.build();

// then
Set<String> originalUserGroups = aliceImpersonationSession.toSessionRepresentation()
Copy link
Member

Choose a reason for hiding this comment

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

Please instead run the SQL to check the. See https://trino.io/docs/current/functions/session.html and current_groups().

Also please make sure that this test is failing when you revert the change to make sure this test actually provides a true coverage.

Copy link
Member Author

@andythsu andythsu Aug 7, 2025

Choose a reason for hiding this comment

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

The current_groups() actually shows the right groups. This bug only happens in

  • show schemas from <catalog>
  • show tables from <catalog>.<schema>

Other operations will work fine.

It looks like other operations don't call toSessionRepresentation but only these two operations will call this method, and hence this error.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, please use current_group() and also test:

show schemas from <catalog>
show tables from <catalog>.<schema>

@andythsu
Copy link
Member Author

andythsu commented Aug 9, 2025

@kokosing I moved my tests to a new file because it requires quite different setup from https://github.com/trinodb/trino/blob/master/testing/trino-tests/src/test/java/io/trino/security/TestImpersonation.java

In addition, I ran these tests without my change and it returned

image

which is expected

Copy link
Member

@kokosing kokosing left a comment

Choose a reason for hiding this comment

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

Please squash the commits. Apply comment. Ping me once it is green to be merged. Thank you!

@@ -0,0 +1,144 @@
package io.trino.security;
Copy link
Member

Choose a reason for hiding this comment

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

add copyright

@andythsu andythsu force-pushed the fix_groups branch 2 times, most recently from 85cdc67 to 4961940 Compare August 12, 2025 14:25
@andythsu
Copy link
Member Author

@kokosing everything passed!

@kokosing
Copy link
Member

I improved release notes a bit. Thank you!

@kokosing kokosing merged commit ef9fc02 into trinodb:master Aug 13, 2025
95 checks passed
@github-actions github-actions bot added this to the 477 milestone Aug 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants