Skip to content

Conversation

@ssheikin
Copy link

@ssheikin ssheikin commented Nov 4, 2025

solves

Summary by Sourcery

Support the X-Trino-Role header by allowing users to specify a role in the data source config and passing it through backend context into SQL requests.

New Features:

  • Add UI input for configuring a Trino role in the data source settings
  • Propagate the configured role as X-Trino-Role header in SQL queries

Enhancements:

  • Extend TypeScript types and Go settings model to include the role field

@cla-bot cla-bot bot added the cla-signed label Nov 4, 2025
@sourcery-ai
Copy link

sourcery-ai bot commented Nov 4, 2025

Reviewer's Guide

This PR implements support for the X-Trino-Role header by extending the frontend configuration UI and type definitions, adding a Role field in the backend settings model, propagating the role value through the datasource context, and injecting it into SQL query arguments.

Entity relationship diagram for updated TrinoDatasourceSettings model

erDiagram
  TrinoDatasourceSettings {
    string ClientId
    string ClientSecret
    string ImpersonationUser
    string Role
    string ClientTags
  }
Loading

Class diagram for updated TrinoDataSourceOptions and TrinoDatasourceSettings

classDiagram
  class TrinoDataSourceOptions {
    tokenUrl?: string
    clientId?: string
    impersonationUser?: string
    role?: string
    clientTags?: string
  }
  class TrinoDatasourceSettings {
    ClientId string
    ClientSecret string
    ImpersonationUser string
    Role string
    ClientTags string
  }
Loading

File-Level Changes

Change Details Files
Add Role field to configuration UI
  • Introduce onRoleChange handler
  • Render new Role InlineField with Input component
src/ConfigEditor.tsx
Extend frontend type definitions to include Role
  • Add role property to TrinoDataSourceOptions interface
src/types.ts
Add Role field to backend settings model
  • Define Role in TrinoDatasourceSettings struct
pkg/trino/models/settings.go
Propagate Role through datasource context
  • Set context value for role header if provided
  • Format role header as system=ROLE{role}
pkg/trino/datasource-context.go
Include Role in SQL query arguments
  • Retrieve role from context
  • Append role named argument to SQL args
pkg/trino/datasource.go

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

@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!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `pkg/trino/datasource-context.go:45-46` </location>
<code_context>
 		ctx = context.WithValue(ctx, trinoUserHeader, user)
 	}

+	if settings.Role != "" {
+		ctx = context.WithValue(ctx, trinoRoleHeader, "system=ROLE{"+settings.Role+"}")
+	}
+
</code_context>

<issue_to_address>
**🚨 suggestion (security):** Consider validating the Role value before formatting.

If settings.Role is user-supplied, ensure it is validated or sanitized to prevent malformed or unexpected header values.

Suggested implementation:

```golang
	if settings.Role != "" {
		role := sanitizeRole(settings.Role)
		if role != "" {
			ctx = context.WithValue(ctx, trinoRoleHeader, "system=ROLE{"+role+"}")
		}
	}

```

```golang
const (
	accessTokenKey     = "accessToken"
	trinoUserHeader    = "X-Trino-User"
	trinoRoleHeader    = "X-Trino-Role"
	trinoClientTagsKey = "X-Trino-Client-Tags"
	bearerPrefix       = "Bearer "
)

// sanitizeRole ensures the role value is safe for use in the header.
// Only allows alphanumeric and underscores, returns empty string if invalid.
func sanitizeRole(role string) string {
	for _, r := range role {
		if !(r >= 'a' && r <= 'z') && !(r >= 'A' && r <= 'Z') && !(r >= '0' && r <= '9') && r != '_' {
			return ""
		}
	}
	return role
}

```
</issue_to_address>

### Comment 2
<location> `pkg/trino/datasource.go:97-98` </location>
<code_context>
 		args = append(args, sql.Named(accessTokenKey, accessToken.(string)))
 	}

+	if role != nil {
+		args = append(args, sql.Named(trinoRoleHeader, role.(string)))
+	}
+
</code_context>

<issue_to_address>
**issue (bug_risk):** Type assertion on role could panic if not a string.

Use a type check or type switch before asserting role as a string to prevent runtime panics.
</issue_to_address>

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.

@nineinchnick
Copy link
Member

Can you add an e2e test that'd verify this works?

@ssheikin
Copy link
Author

ssheikin commented Nov 4, 2025

in progress.

}

if settings.Role != "" {
ctx = context.WithValue(ctx, trinoRoleHeader, "system=ROLE{"+settings.Role+"}")
Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure if system=ROLE{ has to be hardcoded here.
It makes configuration of the plugin more user friendly, but limits specifying roles for catalogs.
Of course, as this PR does not verify input, kind of sql injection may be utilised to specify more roles 🤣

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.

2 participants