Skip to content

Commit 2f81f57

Browse files
srstricklandScott Stricklandtuannvm
authored
feat: Implement Trino user impersonation and query attribution (#132)
* feat: Implement Trino user impersonation and query attribution This commit introduces user impersonation for Trino, allowing queries to be executed on behalf of authenticated OAuth users. This enhances auditability and enables Trino's native access control to enforce user-specific permissions. Key features include: - **User Impersonation**: MCP now propagates the authenticated OAuth user's identity to Trino via the `X-Trino-User` header. This ensures that Trino logs and access control reflect the actual user executing the query, rather than a generic service account. - **Configurable Principal Field**: Users can configure which JWT claim (username, email, or subject) is used as the impersonated user in Trino. - **Query Attribution**: MCP now consistently sets the `X-Trino-Source` header, identifying `mcp-trino` and its version as the source of queries, improving monitoring and debugging. - **Comprehensive Documentation**: A new `impersonation.md` guide provides detailed setup instructions, configuration options, security considerations, and troubleshooting for Trino impersonation. Closes: #118 * Extend trino impersonation to cover all tools * Clean up logging as suggested by CodeRabbit --------- Co-authored-by: Scott Strickland <[email protected]> Co-authored-by: Tommy Nguyen <[email protected]>
1 parent 25954a0 commit 2f81f57

File tree

8 files changed

+797
-65
lines changed

8 files changed

+797
-65
lines changed

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ graph TB
101101
- ✅ StreamableHTTP support with JWT authentication (upgraded from SSE)
102102
- ✅ Backward compatibility with SSE endpoints
103103
- ✅ Compatible with Cursor, Claude Desktop, Windsurf, ChatWise, and any MCP-compatible clients.
104+
- ✅ User Impersonation for authenticated users via Trino's `X-Trino-User` header
104105

105106
## Installation & Quick Start
106107

@@ -156,7 +157,19 @@ export JWT_SECRET=$(openssl rand -hex 32) # Required for multi-pod deployments
156157
export TRINO_ALLOWED_SCHEMAS="hive.analytics,hive.marts,hive.reporting"
157158
```
158159

159-
For complete configuration, see [Deployment Guide](docs/deployment.md), [OAuth Architecture](docs/oauth.md), and [Allowlists Guide](docs/allowlists.md).
160+
**User Impersonation:**
161+
162+
```bash
163+
# Enable Trino user impersonation (requires OAuth)
164+
export TRINO_ENABLE_IMPERSONATION=true
165+
166+
# Optional: Configure which JWT field to use (default: username)
167+
export TRINO_IMPERSONATION_FIELD=email # Options: username, email, subject
168+
169+
# MCP will execute queries as the authenticated OAuth user via X-Trino-User header
170+
```
171+
172+
For complete configuration, see [Deployment Guide](docs/deployment.md), [OAuth Guide](docs/oauth.md), [Allowlists Guide](docs/allowlists.md), and [Impersonation Guide](docs/impersonation.md).
160173

161174
## OAuth Implementation
162175

cmd/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func main() {
2323

2424
// Initialize Trino configuration
2525
log.Println("Loading Trino configuration...")
26-
trinoConfig, err := config.NewTrinoConfig()
26+
trinoConfig, err := config.NewTrinoConfigWithVersion(Version)
2727
if err != nil {
2828
log.Fatalf("Failed to load configuration: %v", err)
2929
}

0 commit comments

Comments
 (0)