Skip to content

Commit 368ddee

Browse files
authored
Add Trino API integration with authorization checks (#291)
* Add Trino API integration with authorization checks - Introduced a new Trino API endpoint for authorization checks at `/trino/allowed`. - Implemented request and response schemas for Trino authorization queries. - Added logic to handle various Trino resource types including tables, schemas, and functions. - Configured the PDP to allow unauthenticated access to Trino endpoints via a new configuration flag. - Updated the Makefile to include a new build target for the latest version. - Created an example environment configuration file for easier setup. This commit enhances the PDP server's capabilities to manage Trino authorization, improving integration with Trino services. * Fix query string in Trino authorization checks by updating the resource identifier from "trino.sys" to "trino_sys" for consistency.
1 parent aab7aeb commit 368ddee

File tree

15 files changed

+2480
-10
lines changed

15 files changed

+2480
-10
lines changed

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: help build prepare build-amd64 build-arm64
1+
.PHONY: help build prepare build-amd64 build-arm64 cargo-run
22

33
.DEFAULT_GOAL := help
44

@@ -28,8 +28,14 @@ build-arm64: prepare
2828
build: prepare
2929
@docker buildx build -t permitio/pdp-v2:$(VERSION) . --load
3030

31+
build-latest: prepare
32+
@docker buildx build -t permitio/pdp-v2:latest . --load
33+
3134
run: run-prepare
3235
@docker run -it --rm -p 7766:7000 --env PDP_API_KEY=$(API_KEY) --env PDP_DEBUG=true permitio/pdp-v2:$(VERSION)
3336

3437
run-on-background: run-prepare
3538
@docker run -it --rm -d -p 7766:7000 --env PDP_API_KEY=$(API_KEY) --env PDP_DEBUG=true permitio/pdp-v2:$(VERSION)
39+
40+
cargo-run:
41+
cargo run --bin pdp-server --package pdp-server -- --port 7766

pdp-server/src/api/horizon_fallback.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ mod tests {
525525
debug: None,
526526
port: 0,
527527
use_new_authorized_users: false,
528+
allow_unauthenticated_trino: false,
528529
healthcheck_timeout: 1.0,
529530
// Point to a non-existent server with a reserved port
530531
horizon: crate::config::horizon::HorizonConfig {
@@ -591,6 +592,7 @@ mod tests {
591592
debug: None,
592593
port: 0,
593594
use_new_authorized_users: false,
595+
allow_unauthenticated_trino: false,
594596
healthcheck_timeout: 1.0,
595597
horizon: crate::config::horizon::HorizonConfig {
596598
host: horizon_mock.address().ip().to_string(),

pdp-server/src/api/mod.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pub(crate) mod authz;
33
pub(crate) mod authzen;
44
pub(crate) mod health;
55
mod horizon_fallback;
6+
pub(crate) mod trino;
67

78
use crate::api::authn_middleware::authentication_middleware;
89
use crate::api::horizon_fallback::fallback_to_horizon;
@@ -11,17 +12,27 @@ use axum::{middleware, routing::any, Router};
1112

1213
/// Combines all API routes into a single router
1314
pub(super) fn router(state: &AppState) -> Router<AppState> {
14-
Router::new()
15-
.merge(health::router())
16-
.merge(protected_routes(state))
15+
let mut root = Router::new().merge(health::router());
16+
17+
if state.config.allow_unauthenticated_trino {
18+
root = root.merge(trino::router());
19+
}
20+
21+
root.merge(protected_routes(state))
1722
}
1823

1924
/// Creates a router for protected routes that require API key authentication
2025
fn protected_routes(state: &AppState) -> Router<AppState> {
21-
// Protected routes that require API key authentication
22-
Router::new()
26+
let mut router = Router::new()
2327
.merge(authz::router())
24-
.merge(authzen::router())
28+
.merge(authzen::router());
29+
30+
if !state.config.allow_unauthenticated_trino {
31+
router = router.merge(trino::router());
32+
}
33+
34+
// Protected routes that require API key authentication
35+
router
2536
// Add fallback route to handle any unmatched requests
2637
.fallback(any(fallback_to_horizon))
2738
// we must use layer here and not route_layer because, route_layer only

0 commit comments

Comments
 (0)