Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ commands:
- script: >-
helm install minio
--namespace $NAMESPACE
--version 12.6.4
--version 15.0.7
-f helm-bitnami-minio-values.yaml
--repo https://charts.bitnami.com/bitnami minio
oci://registry-1.docker.io/bitnamicharts/minio
timeout: 240
96 changes: 75 additions & 21 deletions tests/templates/kuttl/opa-authorization/check-opa.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from trino.exceptions import TrinoUserError

import urllib3

urllib3.disable_warnings()

# Currently missing operation checks:
Expand All @@ -32,7 +33,13 @@
# ExecuteQuery, FilterCatalogs
{
"query": "SHOW CATALOGS",
"expected": [["iceberg"], ["lakehouse"], ["system"], ["tpcds"], ["tpch"]],
"expected": [
["iceberg"],
["lakehouse"],
["system"],
["tpcds"],
["tpch"],
],
},
# ExecuteQuery, FilterCatalogs, ImpersonateUser
{
Expand All @@ -44,18 +51,34 @@
{
"query": "SET SESSION iceberg.test=true",
# The requests are authorized, just a fake property
"error": "Session property 'iceberg.test' does not exist",
"error": "Session property iceberg.test does not exist",
},
# ## SCHEMA ##
# ExecuteQuery, AccessCatalog, ShowSchemas, SelectFromColumns, FilterCatalogs, FilterSchemas
{
"query": "SHOW SCHEMAS in tpch",
"expected": [["information_schema"], ["sf1"], ["sf100"], ["sf1000"], ["sf10000"], ["sf100000"], ["sf300"], ["sf3000"], ["sf30000"], ["tiny"]],
"expected": [
["information_schema"],
["sf1"],
["sf100"],
["sf1000"],
["sf10000"],
["sf100000"],
["sf300"],
["sf3000"],
["sf30000"],
["tiny"],
],
},
# ExecuteQuery, AccessCatalog, ShowSchemas, SelectFromColumns, FilterCatalogs, FilterSchemas
{
"query": "SHOW SCHEMAS in system",
"expected": [["information_schema"], ["jdbc"], ["metadata"], ["runtime"]],
"expected": [
["information_schema"],
["jdbc"],
["metadata"],
["runtime"],
],
},
# ExecuteQuery, AccessCatalog, CreateSchema
{
Expand All @@ -65,7 +88,11 @@
# ExecuteQuery, AccessCatalog, ShowCreateSchema
{
"query": "SHOW CREATE SCHEMA iceberg.test",
"expected": [["CREATE SCHEMA iceberg.test\nAUTHORIZATION USER admin\nWITH (\n location = 's3a://trino/iceberg/test'\n)"]],
"expected": [
[
"CREATE SCHEMA iceberg.test\nAUTHORIZATION USER admin\nWITH (\n location = 's3a://trino/iceberg/test'\n)"
]
],
},
# ExecuteQuery, AccessCatalog, SetSchemaAuthorization
{
Expand All @@ -88,7 +115,16 @@
# ExecuteQuery, AccessCatalog, ShowTables, SelectFromColumns, FilterCatalogs, FilterTables
{
"query": "SHOW TABLES in tpch.sf1",
"expected": [["customer"], ["lineitem"], ["nation"], ["orders"], ["part"], ["partsupp"], ["region"], ["supplier"]],
"expected": [
["customer"],
["lineitem"],
["nation"],
["orders"],
["part"],
["partsupp"],
["region"],
["supplier"],
],
},
# ExecuteQuery, AccessCatalog, CreateTable
{
Expand Down Expand Up @@ -129,7 +165,10 @@
# ExecuteQuery, AccessCatalog, ShowColumns, SelectFromColumns, FilterCatalogs, FilterTables, FilterColumns
{
"query": "DESCRIBE iceberg.test.test",
"expected": [["col1", "bigint", "", "This is a column comment!"], ["col2", "bigint", "", ""]],
"expected": [
["col1", "bigint", "", "This is a column comment!"],
["col2", "bigint", "", ""],
],
},
# ExecuteQuery, AccessCatalog, InsertIntoTable
{
Expand Down Expand Up @@ -194,7 +233,11 @@
# ExecuteQuery, AccessCatalog, ShowCreateTable
{
"query": "SHOW CREATE VIEW iceberg.test.v_customer_renamed",
"expected": [["CREATE VIEW iceberg.test.v_customer_renamed COMMENT 'This is a test view!' SECURITY DEFINER AS\nSELECT\n name\n, address\nFROM\n tpch.sf1.customer"]],
"expected": [
[
"CREATE VIEW iceberg.test.v_customer_renamed COMMENT 'This is a test view!' SECURITY DEFINER AS\nSELECT\n name\n, address\nFROM\n tpch.sf1.customer"
]
],
},
# ExecuteQuery, AccessCatalog, DropView
{
Expand Down Expand Up @@ -250,7 +293,7 @@
# ## SystemSessionProperties ##
# ExecuteQuery, SetSystemSessionProperty
{
"query": "SET SESSION optimize_hash_generation = true",
"query": "SET SESSION dictionary_aggregation = true",
"expected": [],
},
# ## PROCEDURES ##
Expand All @@ -266,14 +309,13 @@
"query": "SELECT COUNT(*) FROM (SELECT * FROM system.runtime.queries LIMIT 1)",
"expected": [[1]],
},

# ## CLEAN UP ##
# ExecuteQuery, AccessCatalog, DropSchema
{
"query": "DROP SCHEMA iceberg.test",
"expected": [],
},
]
],
},
{
# User lakehouse can:
Expand Down Expand Up @@ -313,7 +355,18 @@
},
{
"query": "SELECT * FROM lakehouse.sf1.customer ORDER BY name LIMIT 1",
"expected": [[1, 'Customer#000000001', 'IVhzIApeRb ot,c,E', 15, '25-989-741-2988', 711.56, 'BUILDING', 'to the even, regular platelets. regular, ironic epitaphs nag e']],
"expected": [
[
1,
"Customer#000000001",
"IVhzIApeRb ot,c,E",
15,
"25-989-741-2988",
711.56,
"BUILDING",
"to the even, regular platelets. regular, ironic epitaphs nag e",
]
],
},
{
"query": "SELECT * FROM tpch.tiny.customer ORDER BY name LIMIT 1",
Expand All @@ -323,8 +376,8 @@
# fake values, authorization is checked first
"query": "INSERT INTO lakehouse.tiny.customer VALUES(1)",
"error": "Access Denied: Cannot insert into table lakehouse.tiny.customer",
}
]
},
],
},
{
# User banned-user cannot do anything
Expand All @@ -337,7 +390,7 @@
"query": "SHOW CATALOGS",
"error": "Access Denied: Cannot execute query",
},
]
],
},
{
# User iceberg can:
Expand Down Expand Up @@ -404,13 +457,12 @@
"query": "DROP SCHEMA iceberg.test2",
"expected": [],
},
]
}
],
},
]


class TestOpa:

def __init__(self, test_data, namespace):
self.data = test_data
self.namespace = namespace
Expand All @@ -428,7 +480,9 @@ def run(self):
impersonation = test["impersonation"]

# could be optimized to not create a connection for every call (currently due to user impersonation)
connection = TestOpa.get_connection(user, password, self.namespace, impersonation)
connection = TestOpa.get_connection(
user, password, self.namespace, impersonation
)

if "error" in test:
error = test["error"]
Expand All @@ -444,8 +498,8 @@ def run(self):
print("")

def log(user, query):
timestamp = datetime.utcnow().isoformat(sep=' ', timespec='milliseconds')
print(f'[{timestamp}] - {user:20s} -> {query}')
timestamp = datetime.utcnow().isoformat(sep=" ", timespec="milliseconds")
print(f"[{timestamp}] - {user:20s} -> {query}")

def run_query(connection, query):
cursor = connection.cursor()
Expand Down