|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +suite("test_iceberg_sys_table_auth", "p0,external,doris,external_docker,external_docker_doris") { |
| 19 | + |
| 20 | + String enabled = context.config.otherConfigs.get("enableIcebergTest") |
| 21 | + if (enabled == null || !enabled.equalsIgnoreCase("true")) { |
| 22 | + logger.info("disable iceberg test.") |
| 23 | + return |
| 24 | + } |
| 25 | + |
| 26 | + String catalog_name = "test_iceberg_systable_auth_ctl" |
| 27 | + String db_name = "test_db" |
| 28 | + String rest_port = context.config.otherConfigs.get("iceberg_rest_uri_port") |
| 29 | + String minio_port = context.config.otherConfigs.get("iceberg_minio_port") |
| 30 | + String externalEnvIp = context.config.otherConfigs.get("externalEnvIp") |
| 31 | + sql """drop catalog if exists ${catalog_name}""" |
| 32 | + sql """ |
| 33 | + CREATE CATALOG ${catalog_name} PROPERTIES ( |
| 34 | + 'type'='iceberg', |
| 35 | + 'iceberg.catalog.type'='rest', |
| 36 | + 'uri' = 'http://${externalEnvIp}:${rest_port}', |
| 37 | + "s3.access_key" = "admin", |
| 38 | + "s3.secret_key" = "password", |
| 39 | + "s3.endpoint" = "http://${externalEnvIp}:${minio_port}", |
| 40 | + "s3.region" = "us-east-1" |
| 41 | + );""" |
| 42 | + |
| 43 | + sql """switch ${catalog_name}""" |
| 44 | + sql """use ${db_name}""" |
| 45 | + |
| 46 | + // Create test table |
| 47 | + sql """drop table if exists test_iceberg_systable_auth_tbl1;""" |
| 48 | + sql """create table test_iceberg_systable_auth_tbl1 (id int);""" |
| 49 | + sql """insert into test_iceberg_systable_auth_tbl1 values(1);""" |
| 50 | + sql """insert into test_iceberg_systable_auth_tbl1 values(2);""" |
| 51 | + sql """insert into test_iceberg_systable_auth_tbl1 values(3);""" |
| 52 | + sql """insert into test_iceberg_systable_auth_tbl1 values(4);""" |
| 53 | + sql """insert into test_iceberg_systable_auth_tbl1 values(5);""" |
| 54 | + |
| 55 | + // Create test user without table permission |
| 56 | + String user = "test_iceberg_systable_auth_user" |
| 57 | + String pwd = 'C123_567p' |
| 58 | + try_sql("DROP USER '${user}'@'%'") |
| 59 | + sql """CREATE USER '${user}'@'%' IDENTIFIED BY '${pwd}'""" |
| 60 | + |
| 61 | + if (isCloudMode()) { |
| 62 | + def clusters = sql " SHOW CLUSTERS; " |
| 63 | + assertTrue(!clusters.isEmpty()) |
| 64 | + def validCluster = clusters[0][0] |
| 65 | + sql """GRANT USAGE_PRIV ON CLUSTER `${validCluster}` TO '${user}'@'%'"""; |
| 66 | + } |
| 67 | + |
| 68 | + sql """create database if not exists internal.regression_test""" |
| 69 | + sql """GRANT SELECT_PRIV ON internal.regression_test.* TO '${user}'@'%'""" |
| 70 | + |
| 71 | + // Test that user without table permission cannot query system tables |
| 72 | + connect(user, "${pwd}", context.config.jdbcUrl) { |
| 73 | + // Test snapshots system table via iceberg_meta function |
| 74 | + test { |
| 75 | + sql """ |
| 76 | + select committed_at, snapshot_id, parent_id, operation from iceberg_meta( |
| 77 | + "table" = "${catalog_name}.${db_name}.test_iceberg_systable_auth_tbl1", |
| 78 | + "query_type" = "snapshots"); |
| 79 | + """ |
| 80 | + exception "denied" |
| 81 | + } |
| 82 | + // Test snapshots system table via direct access |
| 83 | + test { |
| 84 | + sql """ |
| 85 | + select committed_at, snapshot_id, parent_id, operation from ${catalog_name}.${db_name}.test_iceberg_systable_auth_tbl1\$snapshots |
| 86 | + """ |
| 87 | + exception "denied" |
| 88 | + } |
| 89 | + // Test files system table via iceberg_meta function |
| 90 | + test { |
| 91 | + sql """ |
| 92 | + select * from iceberg_meta( |
| 93 | + "table" = "${catalog_name}.${db_name}.test_iceberg_systable_auth_tbl1", |
| 94 | + "query_type" = "files"); |
| 95 | + """ |
| 96 | + exception "denied" |
| 97 | + } |
| 98 | + // Test files system table via direct access |
| 99 | + test { |
| 100 | + sql """ |
| 101 | + select * from ${catalog_name}.${db_name}.test_iceberg_systable_auth_tbl1\$files |
| 102 | + """ |
| 103 | + exception "denied" |
| 104 | + } |
| 105 | + // Test entries system table via iceberg_meta function |
| 106 | + test { |
| 107 | + sql """ |
| 108 | + select * from iceberg_meta( |
| 109 | + "table" = "${catalog_name}.${db_name}.test_iceberg_systable_auth_tbl1", |
| 110 | + "query_type" = "entries"); |
| 111 | + """ |
| 112 | + exception "denied" |
| 113 | + } |
| 114 | + // Test entries system table via direct access |
| 115 | + test { |
| 116 | + sql """ |
| 117 | + select * from ${catalog_name}.${db_name}.test_iceberg_systable_auth_tbl1\$entries |
| 118 | + """ |
| 119 | + exception "denied" |
| 120 | + } |
| 121 | + // Test history system table via iceberg_meta function |
| 122 | + test { |
| 123 | + sql """ |
| 124 | + select * from iceberg_meta( |
| 125 | + "table" = "${catalog_name}.${db_name}.test_iceberg_systable_auth_tbl1", |
| 126 | + "query_type" = "history"); |
| 127 | + """ |
| 128 | + exception "denied" |
| 129 | + } |
| 130 | + // Test history system table via direct access |
| 131 | + test { |
| 132 | + sql """ |
| 133 | + select * from ${catalog_name}.${db_name}.test_iceberg_systable_auth_tbl1\$history |
| 134 | + """ |
| 135 | + exception "denied" |
| 136 | + } |
| 137 | + } |
| 138 | + |
| 139 | + // Grant permission and verify user can query system tables |
| 140 | + sql """GRANT SELECT_PRIV ON ${catalog_name}.${db_name}.test_iceberg_systable_auth_tbl1 TO '${user}'@'%'""" |
| 141 | + connect(user, "${pwd}", context.config.jdbcUrl) { |
| 142 | + // Test snapshots system table with permission |
| 143 | + sql """ |
| 144 | + select committed_at, snapshot_id, parent_id, operation from iceberg_meta( |
| 145 | + "table" = "${catalog_name}.${db_name}.test_iceberg_systable_auth_tbl1", |
| 146 | + "query_type" = "snapshots"); |
| 147 | + """ |
| 148 | + sql """select committed_at, snapshot_id, parent_id, operation from ${catalog_name}.${db_name}.test_iceberg_systable_auth_tbl1\$snapshots""" |
| 149 | + |
| 150 | + // Test files system table with permission |
| 151 | + sql """ |
| 152 | + select * from iceberg_meta( |
| 153 | + "table" = "${catalog_name}.${db_name}.test_iceberg_systable_auth_tbl1", |
| 154 | + "query_type" = "files"); |
| 155 | + """ |
| 156 | + sql """select * from ${catalog_name}.${db_name}.test_iceberg_systable_auth_tbl1\$files""" |
| 157 | + |
| 158 | + // Test entries system table with permission |
| 159 | + sql """ |
| 160 | + select * from iceberg_meta( |
| 161 | + "table" = "${catalog_name}.${db_name}.test_iceberg_systable_auth_tbl1", |
| 162 | + "query_type" = "entries"); |
| 163 | + """ |
| 164 | + sql """select * from ${catalog_name}.${db_name}.test_iceberg_systable_auth_tbl1\$entries""" |
| 165 | + |
| 166 | + // Test history system table with permission |
| 167 | + sql """ |
| 168 | + select * from iceberg_meta( |
| 169 | + "table" = "${catalog_name}.${db_name}.test_iceberg_systable_auth_tbl1", |
| 170 | + "query_type" = "history"); |
| 171 | + """ |
| 172 | + sql """select * from ${catalog_name}.${db_name}.test_iceberg_systable_auth_tbl1\$history""" |
| 173 | + } |
| 174 | + try_sql("DROP USER '${user}'@'%'") |
| 175 | +} |
| 176 | + |
0 commit comments