15 package com.cloudera.impala.analysis;
17 import static org.junit.Assert.assertEquals;
18 import static org.junit.Assert.fail;
20 import java.util.ArrayList;
21 import java.util.Arrays;
22 import java.util.Collection;
23 import java.util.List;
24 import java.util.UUID;
26 import junit.framework.Assert;
28 import org.apache.hive.service.cli.thrift.TGetColumnsReq;
29 import org.apache.hive.service.cli.thrift.TGetSchemasReq;
30 import org.apache.hive.service.cli.thrift.TGetTablesReq;
31 import org.apache.sentry.provider.common.ResourceAuthorizationProvider;
32 import org.apache.sentry.provider.file.LocalGroupResourceAuthorizationProvider;
33 import org.junit.After;
35 import org.junit.runner.RunWith;
36 import org.junit.runners.Parameterized;
37 import org.junit.runners.Parameterized.Parameters;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
56 import com.cloudera.impala.thrift.TMetadataOpRequest;
57 import com.cloudera.impala.thrift.TMetadataOpcode;
58 import com.cloudera.impala.thrift.TNetworkAddress;
59 import com.cloudera.impala.thrift.TPrivilege;
60 import com.cloudera.impala.thrift.TPrivilegeLevel;
61 import com.cloudera.impala.thrift.TPrivilegeScope;
62 import com.cloudera.impala.thrift.TQueryCtx;
63 import com.cloudera.impala.thrift.TResultSet;
64 import com.cloudera.impala.thrift.TSessionState;
66 import com.google.common.base.Preconditions;
67 import com.google.common.collect.Lists;
69 @RunWith(Parameterized.class)
71 private final static Logger LOG =
72 LoggerFactory.getLogger(AuthorizationTest.class);
84 private final static String AUTHZ_POLICY_FILE =
"/test-warehouse/authz-policy.ini";
85 private final static User USER =
new User(System.getProperty(
"user.name"));
88 private final static User ADMIN_USER =
new User(
"admin_user");
95 protected static final String SERVER_HOST =
"localhost";
96 private static boolean isSetup_ =
false;
103 return Arrays.asList(
new Object[][] {{null}, {AUTHZ_POLICY_FILE}});
107 authzConfig_ = AuthorizationConfig.createHadoopGroupAuthConfig(
"server1", policyFile,
108 System.getenv(
"IMPALA_HOME") +
"/fe/src/test/resources/sentry-site.xml");
109 authzConfig_.validateConfig();
110 if (!isSetup_ && policyFile == null) {
116 analysisContext_ =
new AnalysisContext(catalog_, queryCtx_, authzConfig_);
117 fe_ =
new Frontend(authzConfig_, catalog_);
120 private void setup() throws Exception {
125 String roleName =
"admin";
126 sentryService.createRole(USER, roleName,
true);
128 TPrivilege privilege =
new TPrivilege(
"", TPrivilegeLevel.ALL,
129 TPrivilegeScope.SERVER,
false);
130 privilege.setServer_name(
"server1");
131 sentryService.grantRolePrivilege(USER, roleName, privilege);
132 sentryService.revokeRoleFromGroup(USER,
"admin", USER.getName());
135 roleName =
"insert_functional_alltypes";
136 roleName = roleName.toLowerCase();
137 sentryService.createRole(USER, roleName,
true);
138 sentryService.grantRoleToGroup(USER, roleName, USER.getName());
140 privilege =
new TPrivilege(
"", TPrivilegeLevel.INSERT, TPrivilegeScope.TABLE,
142 privilege.setServer_name(
"server1");
143 privilege.setDb_name(
"functional");
144 privilege.setTable_name(
"alltypes");
145 sentryService.grantRolePrivilege(USER, roleName, privilege);
148 roleName =
"insert_parquet";
149 sentryService.createRole(USER, roleName,
true);
150 sentryService.grantRoleToGroup(USER, roleName, USER.getName());
152 privilege =
new TPrivilege(
"", TPrivilegeLevel.INSERT, TPrivilegeScope.TABLE,
154 privilege.setServer_name(
"server1");
155 privilege.setDb_name(
"functional_parquet");
157 sentryService.grantRolePrivilege(USER, roleName, privilege);
160 roleName =
"all_newdb";
161 sentryService.createRole(USER, roleName,
true);
162 sentryService.grantRoleToGroup(USER, roleName, USER.getName());
164 privilege =
new TPrivilege(
"", TPrivilegeLevel.ALL, TPrivilegeScope.DATABASE,
166 privilege.setServer_name(
"server1");
167 privilege.setDb_name(
"newdb");
168 sentryService.grantRolePrivilege(USER, roleName, privilege);
170 privilege =
new TPrivilege(
"", TPrivilegeLevel.ALL, TPrivilegeScope.URI,
172 privilege.setServer_name(
"server1");
173 privilege.setUri(
"hdfs://localhost:20500/test-warehouse/new_table");
175 sentryService.grantRolePrivilege(USER, roleName, privilege);
178 roleName =
"all_tpch";
179 sentryService.createRole(USER, roleName,
true);
180 sentryService.grantRoleToGroup(USER, roleName, USER.getName());
181 privilege =
new TPrivilege(
"", TPrivilegeLevel.ALL, TPrivilegeScope.URI,
false);
182 privilege.setServer_name(
"server1");
183 privilege.setUri(
"hdfs://localhost:20500/test-warehouse/tpch.lineitem");
184 sentryService.grantRolePrivilege(USER, roleName, privilege);
186 privilege =
new TPrivilege(
"", TPrivilegeLevel.ALL, TPrivilegeScope.DATABASE,
false);
187 privilege.setServer_name(
"server1");
188 privilege.setDb_name(
"tpch");
189 sentryService.grantRolePrivilege(USER, roleName, privilege);
192 roleName =
"select_tpcds";
193 sentryService.createRole(USER, roleName,
true);
194 sentryService.grantRoleToGroup(USER, roleName, USER.getName());
196 privilege =
new TPrivilege(
"", TPrivilegeLevel.SELECT, TPrivilegeScope.TABLE,
false);
197 privilege.setServer_name(
"server1");
198 privilege.setDb_name(
"tpcds");
200 sentryService.grantRolePrivilege(USER, roleName, privilege);
203 roleName =
"select_functional_alltypesagg";
204 sentryService.createRole(USER, roleName,
true);
205 sentryService.grantRoleToGroup(USER, roleName, USER.getName());
207 privilege =
new TPrivilege(
"", TPrivilegeLevel.SELECT, TPrivilegeScope.TABLE,
false);
208 privilege.setServer_name(
"server1");
209 privilege.setDb_name(
"functional");
210 privilege.setTable_name(
"alltypesagg");
211 sentryService.grantRolePrivilege(USER, roleName, privilege);
214 roleName =
"select_functional_complex_view";
215 sentryService.createRole(USER, roleName,
true);
216 sentryService.grantRoleToGroup(USER, roleName, USER.getName());
218 privilege =
new TPrivilege(
"", TPrivilegeLevel.SELECT, TPrivilegeScope.TABLE,
false);
219 privilege.setServer_name(
"server1");
220 privilege.setDb_name(
"functional");
221 privilege.setTable_name(
"complex_view");
222 sentryService.grantRolePrivilege(USER, roleName, privilege);
225 roleName =
"select_functional_view_view";
226 sentryService.createRole(USER, roleName,
true);
227 sentryService.grantRoleToGroup(USER, roleName, USER.getName());
229 privilege =
new TPrivilege(
"", TPrivilegeLevel.SELECT, TPrivilegeScope.TABLE,
false);
230 privilege.setServer_name(
"server1");
231 privilege.setDb_name(
"functional");
232 privilege.setTable_name(
"view_view");
233 sentryService.grantRolePrivilege(USER, roleName, privilege);
236 roleName =
"all_functional_seq_snap";
238 sentryService.dropRole(USER, roleName,
true);
239 sentryService.createRole(USER, roleName,
true);
240 sentryService.grantRoleToGroup(USER, roleName, USER.getName());
242 privilege =
new TPrivilege(
"", TPrivilegeLevel.ALL, TPrivilegeScope.DATABASE,
false);
243 privilege.setServer_name(
"server1");
244 privilege.setDb_name(
"functional_seq_snap");
245 sentryService.grantRolePrivilege(USER, roleName, privilege);
250 AuthzError(
"select * from functional.complex_view_sub",
251 "User '%s' does not have privileges to execute 'SELECT' on: " +
252 "functional.complex_view_sub");
259 String roleName =
"testRoleName";
260 roleName = roleName.toLowerCase();
262 sentryService.createRole(USER, roleName,
true);
263 String dbName = UUID.randomUUID().toString();
265 TPrivilege privilege =
266 new TPrivilege(
"", TPrivilegeLevel.ALL, TPrivilegeScope.DATABASE,
false);
267 privilege.setServer_name(
"server1");
268 privilege.setDb_name(dbName);
269 sentryService.grantRoleToGroup(USER, roleName, USER.getName());
270 sentryService.grantRolePrivilege(USER, roleName, privilege);
272 for (
int i = 0; i < 2; ++i) {
273 privilege =
new TPrivilege(
"", TPrivilegeLevel.SELECT, TPrivilegeScope.TABLE,
275 privilege.setServer_name(
"server1");
276 privilege.setDb_name(dbName);
277 privilege.setTable_name(
"test_tbl_" + String.valueOf(i));
278 sentryService.grantRolePrivilege(USER, roleName, privilege);
287 if (catalog_.
getDb(
"tpch").numFunctions() != 0) {
288 fail(
"Failed to clean up functions in tpch.");
295 AuthzOk(
"select * from functional.alltypesagg");
297 AuthzOk(
"select * from functional_seq_snap.alltypes");
301 AuthzOk(
"select * from functional.complex_view");
305 AuthzOk(
"select * from functional.view_view");
308 AuthzError(
"select * from functional.complex_view_sub",
309 "User '%s' does not have privileges to execute 'SELECT' on: " +
310 "functional.complex_view_sub");
313 AuthzOk(
"select a.id from functional.view_view a "
314 +
"join functional.alltypesagg b ON (a.id = b.id)");
318 AuthzError(
"select a.id from functional.view_view a "
319 +
"join functional.alltypes b ON (a.id = b.id)",
320 "User '%s' does not have privileges to execute 'SELECT' on: " +
321 "functional.alltypes");
327 AuthzError(
"select * from alltypes",
328 "User '%s' does not have privileges to execute 'SELECT' on: default.alltypes");
331 AuthzError(
"select * from functional.alltypes",
332 "User '%s' does not have privileges to execute 'SELECT' on: " +
333 "functional.alltypes");
336 AuthzError(
"select * from functional.complex_view_sub",
337 "User '%s' does not have privileges to execute 'SELECT' on: " +
338 "functional.complex_view_sub");
341 AuthzError(
"select 1 from functional.alltypes",
342 "User '%s' does not have privileges to execute 'SELECT' on: " +
343 "functional.alltypes");
346 AuthzError(
"select 1 from functional.notbl",
347 "User '%s' does not have privileges to execute 'SELECT' on: functional.notbl");
350 AuthzError(
"select 1 from nodb.alltypes",
351 "User '%s' does not have privileges to execute 'SELECT' on: nodb.alltypes");
354 AuthzError(
"select a.* from (select * from functional.alltypes) a",
355 "User '%s' does not have privileges to execute 'SELECT' on: " +
356 "functional.alltypes");
358 AuthzOk(
"select a.* from (select * from functional.alltypesagg) a");
363 AuthzOk(
"select * from functional.alltypesagg union all " +
364 "select * from functional.alltypesagg");
366 AuthzError(
"select * from functional.alltypesagg union all " +
367 "select * from functional.alltypes",
368 "User '%s' does not have privileges to execute 'SELECT' on: " +
369 "functional.alltypes");
374 AuthzOk(
"insert into functional_parquet.alltypes " +
375 "partition(month,year) select * from functional_seq_snap.alltypes");
378 AuthzOk(
"insert into functional.alltypes partition(month,year) " +
379 "select b.* from functional.alltypesagg a join (select * from " +
380 "functional_seq_snap.alltypes) b on (a.int_col = b.int_col)");
383 AuthzError(
"insert into functional.alltypesagg select 1",
384 "User '%s' does not have privileges to execute 'INSERT' on: " +
385 "functional.alltypesagg");
389 AuthzError(
"insert into functional.alltypes_view select 1",
390 "User '%s' does not have privileges to execute 'INSERT' on: " +
391 "functional.alltypes_view");
394 AuthzError(
"insert into functional.alltypes " +
395 "select * from functional.alltypes",
396 "User '%s' does not have privileges to execute 'SELECT' on: " +
397 "functional.alltypes");
400 AuthzError(
"insert into functional.alltypes " +
401 "select * from functional.alltypesagg a join (select * from " +
402 "functional_seq.alltypes) b on (a.int_col = b.int_col)",
403 "User '%s' does not have privileges to execute 'SELECT' on: " +
404 "functional_seq.alltypes");
410 AuthzOk(
"with t as (select * from functional.alltypesagg) select * from t");
412 AuthzError(
"with t as (select * from functional.alltypes) select * from t",
413 "User '%s' does not have privileges to execute 'SELECT' on: " +
414 "functional.alltypes");
416 AuthzOk(
"with t as (select * from functional.complex_view) select * from t");
419 AuthzOk(
"with t as (select * from functional_seq_snap.alltypes) " +
420 "insert into functional_parquet.alltypes partition(month,year) select * from t");
422 AuthzError(
"with t as (select * from functional_parquet.alltypes) " +
423 "insert into functional_parquet.alltypes partition(month,year) select * from t",
424 "User '%s' does not have privileges to execute 'SELECT' on: " +
425 "functional_parquet.alltypes");
427 AuthzError(
"with t as (select * from functional.alltypes_view) " +
428 "insert into functional_parquet.alltypes partition(month,year) select * from t",
429 "User '%s' does not have privileges to execute 'SELECT' on: " +
430 "functional.alltypes_view");
435 AuthzOk(
"explain select * from functional.alltypesagg");
436 AuthzOk(
"explain insert into functional_parquet.alltypes " +
437 "partition(month,year) select * from functional_seq_snap.alltypes");
440 AuthzError(
"explain select * from functional.alltypes",
441 "User '%s' does not have privileges to execute 'SELECT' on: " +
442 "functional.alltypes");
445 AuthzError(
"explain insert into functional_parquet.alltypes " +
446 "partition(month,year) select * from functional.alltypes",
447 "User '%s' does not have privileges to execute 'SELECT' on: " +
448 "functional.alltypes");
450 AuthzError(
"explain insert into functional.alltypes " +
451 "select * from functional.alltypes",
452 "User '%s' does not have privileges to execute 'SELECT' on: " +
453 "functional.alltypes");
456 AuthzOk(
"explain select * from functional_seq_snap.alltypes_view");
457 AuthzOk(
"explain insert into functional_parquet.alltypes " +
458 "partition(month,year) select * from functional_seq_snap.alltypes_view");
461 AuthzError(
"explain select * from functional.alltypes_view",
462 "User '%s' does not have privileges to execute 'SELECT' on: " +
463 "functional.alltypes_view");
465 AuthzError(
"explain insert into functional.alltypes_view " +
466 "select * from functional_seq_snap.alltypes ",
467 "User '%s' does not have privileges to execute 'INSERT' on: " +
468 "functional.alltypes_view");
471 AuthzError(
"explain select * from functional.complex_view",
472 "User '%s' does not have privileges to EXPLAIN this statement.");
474 AuthzError(
"explain with t as (select * from functional.complex_view) " +
476 "User '%s' does not have privileges to EXPLAIN this statement.");
479 AuthzError(
"explain with t as (select * from functional.complex_view) " +
481 "User '%s' does not have privileges to EXPLAIN this statement.");
484 AuthzError(
"explain select * from functional.view_view",
485 "User '%s' does not have privileges to EXPLAIN this statement.");
487 AuthzError(
"explain insert into functional_seq_snap.alltypes " +
488 "partition(month,year) select * from functional.view_view",
489 "User '%s' does not have privileges to EXPLAIN this statement.");
493 AuthzError(
"explain select a.id from functional.view_view a "
494 +
"join functional.alltypes b ON (a.id = b.id)",
495 "User '%s' does not have privileges to execute 'SELECT' on: " +
496 "functional.alltypes");
500 AuthzError(
"explain select a.id from functional.view_view a "
501 +
"join functional.complex_view b ON (a.id = b.id)",
502 "User '%s' does not have privileges to EXPLAIN this statement.");
508 AuthzOk(
"use functional");
509 AuthzOk(
"use tpcds");
514 AuthzOk(
"use default");
516 AuthzError(
"use functional_seq",
517 "User '%s' does not have privileges to access: functional_seq.*");
520 AuthzError(
"use nodb",
521 "User '%s' does not have privileges to access: nodb.*");
525 AuthzOk(
"use newdb");
526 fail(
"Expected AnalysisException");
527 }
catch (AnalysisException e) {
528 Assert.assertEquals(e.getMessage(),
"Database does not exist: newdb");
532 AuthzOk(
"use _impala_builtins");
538 AuthzOk(
"invalidate metadata functional.alltypesagg");
539 AuthzOk(
"refresh functional.alltypesagg");
540 AuthzOk(
"invalidate metadata functional.view_view");
541 AuthzOk(
"refresh functional.view_view");
543 AuthzError(
"invalidate metadata unknown_db.alltypessmall",
544 "User '%s' does not have privileges to access: unknown_db.alltypessmall");
545 AuthzError(
"invalidate metadata functional_seq.alltypessmall",
546 "User '%s' does not have privileges to access: functional_seq.alltypessmall");
547 AuthzError(
"invalidate metadata functional.alltypes_view",
548 "User '%s' does not have privileges to access: functional.alltypes_view");
549 AuthzError(
"invalidate metadata functional.unknown_table",
550 "User '%s' does not have privileges to access: functional.unknown_table");
551 AuthzError(
"invalidate metadata functional.alltypessmall",
552 "User '%s' does not have privileges to access: functional.alltypessmall");
553 AuthzError(
"refresh functional.alltypessmall",
554 "User '%s' does not have privileges to access: functional.alltypessmall");
555 AuthzError(
"refresh functional.alltypes_view",
556 "User '%s' does not have privileges to access: functional.alltypes_view");
558 AuthzError(
"invalidate metadata",
559 "User '%s' does not have privileges to access: server");
567 sentryService.grantRoleToGroup(USER,
"admin", USER.getName());
569 AuthzOk(
"invalidate metadata");
571 sentryService.revokeRoleFromGroup(USER,
"admin", USER.getName());
578 AuthzOk(
"create table tpch.new_table (i int)");
579 AuthzOk(
"create table tpch.new_lineitem like tpch.lineitem");
581 AuthzOk(
"create table if not exists tpch.lineitem (i int)");
583 AuthzOk(
"create table tpch.lineitem (i int)");
584 fail(
"Expected analysis error.");
585 }
catch (AnalysisException e) {
586 Assert.assertEquals(e.getMessage(),
"Table already exists: tpch.lineitem");
590 AuthzOk(
"create table tpch.new_table as select * from functional.alltypesagg");
591 AuthzError(
"create table tpch.new_table as select * from functional.alltypes",
592 "User '%s' does not have privileges to execute 'SELECT' on: " +
593 "functional.alltypes");
595 AuthzError(
"create table functional.tbl tblproperties('a'='b')" +
597 "User '%s' does not have privileges to execute 'CREATE' on: " +
601 AuthzError(
"create table if not exists functional_seq.alltypes (i int)",
602 "User '%s' does not have privileges to execute 'CREATE' on: " +
603 "functional_seq.alltypes");
606 AuthzOk(
"create table tpch.new_table (i int) location " +
607 "'hdfs://localhost:20500/test-warehouse/new_table'");
610 AuthzError(
"create table tpch.new_lineitem like tpch_seq.lineitem",
611 "User '%s' does not have privileges to access: tpch_seq.lineitem");
614 AuthzError(
"create table tpch_rc.new like tpch.lineitem",
615 "User '%s' does not have privileges to execute 'CREATE' on: tpch_rc.new");
618 AuthzError(
"create table new_table (i int)",
619 "User '%s' does not have privileges to execute 'CREATE' on: default.new_table");
622 AuthzError(
"create table functional.alltypes (i int)",
623 "User '%s' does not have privileges to execute 'CREATE' on: " +
624 "functional.alltypes");
627 AuthzError(
"create table nodb.alltypes (i int)",
628 "User '%s' does not have privileges to execute 'CREATE' on: " +
632 AuthzError(
"create table tpch.new_table (i int) location " +
633 "'hdfs://localhost:20500/test-warehouse/alltypes'",
634 "User '%s' does not have privileges to access: " +
635 "hdfs://localhost:20500/test-warehouse/alltypes");
637 AuthzError(
"create table _impala_builtins.tbl(i int)",
638 "Cannot modify system database.");
641 AuthzError(
"create table tpch.table_DNE like parquet "
642 +
"'hdfs://localhost:20500/test-warehouse/alltypes'",
643 "User '%s' does not have privileges to access: "
644 +
"hdfs://localhost:20500/test-warehouse/alltypes");
649 AuthzOk(
"create view tpch.new_view as select * from functional.alltypesagg");
650 AuthzOk(
"create view tpch.new_view (a, b, c) as " +
651 "select int_col, string_col, timestamp_col from functional.alltypesagg");
653 AuthzOk(
"create view if not exists tpch.lineitem as " +
654 "select * from functional.alltypesagg");
657 AuthzOk(
"create view tpch.lineitem as select * from functional.alltypesagg");
658 fail(
"Expected analysis error.");
659 }
catch (AnalysisException e) {
660 Assert.assertEquals(e.getMessage(),
"Table already exists: tpch.lineitem");
664 AuthzError(
"create view if not exists functional_seq.alltypes as " +
665 "select * from functional.alltypesagg",
666 "User '%s' does not have privileges to execute 'CREATE' on: " +
667 "functional_seq.alltypes");
670 AuthzError(
"create view tpch.new_view as select * from functional.alltypes",
671 "User '%s' does not have privileges to execute 'SELECT' on: " +
672 "functional.alltypes");
675 AuthzError(
"create view tpch_rc.new as select * from functional.alltypesagg",
676 "User '%s' does not have privileges to execute 'CREATE' on: tpch_rc.new");
679 AuthzError(
"create view new_view as select * from functional.alltypesagg",
680 "User '%s' does not have privileges to execute 'CREATE' on: default.new_view");
683 AuthzError(
"create view functional.alltypes_view as " +
684 "select * from functional.alltypesagg",
685 "User '%s' does not have privileges to execute 'CREATE' on: " +
686 "functional.alltypes_view");
689 AuthzError(
"create view nodb.alltypes as select * from functional.alltypesagg",
690 "User '%s' does not have privileges to execute 'CREATE' on: " +
693 AuthzError(
"create view _impala_builtins.new_view as "
694 +
"select * from functional.alltypesagg",
695 "Cannot modify system database.");
701 AuthzError(
"create database functional",
702 "User '%s' does not have privileges to execute 'CREATE' on: functional");
705 AuthzError(
"create database nodb",
706 "User '%s' does not have privileges to execute 'CREATE' on: nodb");
709 AuthzError(
"create database if not exists _impala_builtins",
710 "Cannot modify system database.");
719 sentryService.grantRoleToGroup(USER,
"admin", USER.getName());
723 AuthzOk(
"create database newdb");
729 AuthzOk(
"create database newdb location " +
730 "'hdfs://localhost:20500/test-warehouse/new_table'");
732 sentryService.revokeRoleFromGroup(USER,
"admin", USER.getName());
740 AuthzOk(
"drop database tpch");
742 AuthzOk(
"drop database if exists newdb");
745 AuthzOk(
"drop database newdb");
746 fail(
"Expected analysis error");
747 }
catch (AnalysisException e) {
748 Assert.assertEquals(e.getMessage(),
"Database does not exist: newdb");
752 AuthzError(
"drop database functional",
753 "User '%s' does not have privileges to execute 'DROP' on: functional");
754 AuthzError(
"drop database if exists functional",
755 "User '%s' does not have privileges to execute 'DROP' on: functional");
758 AuthzError(
"drop database nodb",
759 "User '%s' does not have privileges to execute 'DROP' on: nodb");
760 AuthzError(
"drop database if exists nodb",
761 "User '%s' does not have privileges to execute 'DROP' on: nodb");
763 AuthzError(
"drop database _impala_builtins",
764 "Cannot modify system database.");
770 AuthzOk(
"drop table tpch.lineitem");
771 AuthzOk(
"drop table if exists tpch.lineitem");
774 AuthzError(
"drop table functional.alltypes",
775 "User '%s' does not have privileges to execute 'DROP' on: functional.alltypes");
776 AuthzError(
"drop table if exists functional.alltypes",
777 "User '%s' does not have privileges to execute 'DROP' on: functional.alltypes");
780 AuthzError(
"drop table alltypes",
781 "User '%s' does not have privileges to execute 'DROP' on: default.alltypes");
784 AuthzError(
"drop table nodb.alltypes",
785 "User '%s' does not have privileges to execute 'DROP' on: nodb.alltypes");
788 AuthzError(
"drop table functional.notbl",
789 "User '%s' does not have privileges to execute 'DROP' on: functional.notbl");
792 AuthzError(
"drop table functional.view_view",
793 "User '%s' does not have privileges to execute 'DROP' on: functional.view_view");
796 AuthzError(
"drop table if exists _impala_builtins.tbl",
797 "Cannot modify system database.");
803 AuthzOk(
"drop view functional_seq_snap.alltypes_view");
804 AuthzOk(
"drop view if exists functional_seq_snap.alltypes_view");
807 AuthzError(
"drop view functional.alltypes_view",
808 "User '%s' does not have privileges to execute 'DROP' on: functional.alltypes");
809 AuthzError(
"drop view if exists functional.alltypes_view",
810 "User '%s' does not have privileges to execute 'DROP' on: functional.alltypes");
813 AuthzError(
"drop view alltypes",
814 "User '%s' does not have privileges to execute 'DROP' on: default.alltypes");
817 AuthzError(
"drop view nodb.alltypes",
818 "User '%s' does not have privileges to execute 'DROP' on: nodb.alltypes");
821 AuthzError(
"drop view functional.notbl",
822 "User '%s' does not have privileges to execute 'DROP' on: functional.notbl");
825 AuthzError(
"drop view functional.alltypes",
826 "User '%s' does not have privileges to execute 'DROP' on: functional.alltypes");
829 AuthzError(
"drop view _impala_builtins.my_view",
830 "Cannot modify system database.");
836 AuthzOk(
"ALTER TABLE functional_seq_snap.alltypes ADD COLUMNS (c1 int)");
837 AuthzOk(
"ALTER TABLE functional_seq_snap.alltypes REPLACE COLUMNS (c1 int)");
838 AuthzOk(
"ALTER TABLE functional_seq_snap.alltypes CHANGE int_col c1 int");
839 AuthzOk(
"ALTER TABLE functional_seq_snap.alltypes DROP int_col");
840 AuthzOk(
"ALTER TABLE functional_seq_snap.alltypes RENAME TO functional_seq_snap.t1");
841 AuthzOk(
"ALTER TABLE functional_seq_snap.alltypes SET FILEFORMAT PARQUET");
842 AuthzOk(
"ALTER TABLE functional_seq_snap.alltypes SET LOCATION " +
843 "'/test-warehouse/new_table'");
844 AuthzOk(
"ALTER TABLE functional_seq_snap.alltypes SET TBLPROPERTIES " +
845 "('a'='b', 'c'='d')");
846 AuthzOk(
"ALTER TABLE functional_seq_snap.alltypes SET LOCATION " +
847 "'hdfs://localhost:20500/test-warehouse/new_table'");
848 AuthzOk(
"ALTER TABLE functional_seq_snap.alltypes PARTITION(year=2009, month=1) " +
849 "SET LOCATION 'hdfs://localhost:20500/test-warehouse/new_table'");
851 AuthzOk(
"ALTER TABLE functional_seq_snap.alltypes SET CACHED IN 'testPool'");
855 AuthzError(
"ALTER TABLE functional_seq_snap.alltypes SET LOCATION " +
856 "'hdfs://localhost:20500/test-warehouse/no_access'",
857 "User '%s' does not have privileges to access: " +
858 "hdfs://localhost:20500/test-warehouse/no_access");
859 AuthzError(
"ALTER TABLE functional_seq_snap.alltypes SET LOCATION " +
860 "'/test-warehouse/no_access'",
861 "User '%s' does not have privileges to access: " +
862 "hdfs://localhost:20500/test-warehouse/no_access");
863 AuthzError(
"ALTER TABLE functional_seq_snap.alltypes PARTITION(year=2009, month=1) " +
864 "SET LOCATION '/test-warehouse/no_access'",
865 "User '%s' does not have privileges to access: " +
866 "hdfs://localhost:20500/test-warehouse/no_access");
869 AuthzError(
"ALTER TABLE functional_seq_snap.alltypes SET LOCATION " +
870 "'hdfs://localhost:20510/test-warehouse/new_table'",
871 "User '%s' does not have privileges to access: " +
872 "hdfs://localhost:20510/test-warehouse/new_table");
874 AuthzError(
"ALTER TABLE functional.alltypes SET FILEFORMAT PARQUET",
875 "User '%s' does not have privileges to execute 'ALTER' on: functional.alltypes");
876 AuthzError(
"ALTER TABLE functional.alltypes ADD COLUMNS (c1 int)",
877 "User '%s' does not have privileges to execute 'ALTER' on: functional.alltypes");
878 AuthzError(
"ALTER TABLE functional.alltypes REPLACE COLUMNS (c1 int)",
879 "User '%s' does not have privileges to execute 'ALTER' on: functional.alltypes");
880 AuthzError(
"ALTER TABLE functional.alltypes CHANGE int_col c1 int",
881 "User '%s' does not have privileges to execute 'ALTER' on: functional.alltypes");
882 AuthzError(
"ALTER TABLE functional.alltypes DROP int_col",
883 "User '%s' does not have privileges to execute 'ALTER' on: functional.alltypes");
884 AuthzError(
"ALTER TABLE functional.alltypes rename to functional_seq_snap.t1",
885 "User '%s' does not have privileges to execute 'ALTER' on: functional.alltypes");
886 AuthzError(
"ALTER TABLE functional.alltypes add partition (year=1, month=1)",
887 "User '%s' does not have privileges to execute 'ALTER' on: functional.alltypes");
888 AuthzError(
"ALTER TABLE functional.alltypes set cached in 'testPool'",
889 "User '%s' does not have privileges to execute 'ALTER' on: functional.alltypes");
890 AuthzError(
"ALTER TABLE functional.alltypes set uncached",
891 "User '%s' does not have privileges to execute 'ALTER' on: functional.alltypes");
894 AuthzError(
"ALTER TABLE functional.view_view SET FILEFORMAT PARQUET",
895 "User '%s' does not have privileges to execute 'ALTER' on: functional.view_view");
896 AuthzError(
"ALTER TABLE functional.view_view ADD COLUMNS (c1 int)",
897 "User '%s' does not have privileges to execute 'ALTER' on: functional.view_view");
898 AuthzError(
"ALTER TABLE functional.view_view REPLACE COLUMNS (c1 int)",
899 "User '%s' does not have privileges to execute 'ALTER' on: functional.view_view");
900 AuthzError(
"ALTER TABLE functional.view_view CHANGE int_col c1 int",
901 "User '%s' does not have privileges to execute 'ALTER' on: functional.view_view");
902 AuthzError(
"ALTER TABLE functional.view_view DROP int_col",
903 "User '%s' does not have privileges to execute 'ALTER' on: functional.view_view");
904 AuthzError(
"ALTER TABLE functional.view_views rename to functional_seq_snap.t1",
905 "User '%s' does not have privileges to execute 'ALTER' on: functional.view_view");
908 AuthzError(
"ALTER TABLE functional_seq_snap.alltypes rename to functional.alltypes",
909 "User '%s' does not have privileges to execute 'CREATE' on: " +
910 "functional.alltypes");
913 AuthzError(
"ALTER TABLE functional_seq_snap.alltypes rename to " +
914 "functional.alltypes_view",
915 "User '%s' does not have privileges to execute 'CREATE' on: " +
916 "functional.alltypes");
919 AuthzError(
"ALTER TABLE functional.alltypes_view rename to " +
920 "functional_seq_snap.new_view",
921 "User '%s' does not have privileges to execute 'ALTER' on: " +
922 "functional.alltypes_view");
925 AuthzError(
"ALTER TABLE functional.notbl rename to functional_seq_snap.newtbl",
926 "User '%s' does not have privileges to execute 'ALTER' on: functional.notbl");
929 AuthzError(
"ALTER TABLE nodb.alltypes rename to functional_seq_snap.newtbl",
930 "User '%s' does not have privileges to execute 'ALTER' on: nodb.alltypes");
933 AuthzError(
"ALTER TABLE functional.notbl ADD COLUMNS (c1 int)",
934 "User '%s' does not have privileges to execute 'ALTER' on: functional.notbl");
937 AuthzError(
"ALTER TABLE nodb.alltypes ADD COLUMNS (c1 int)",
938 "User '%s' does not have privileges to execute 'ALTER' on: nodb.alltypes");
941 AuthzError(
"ALTER TABLE alltypes ADD COLUMNS (c1 int)",
942 "User '%s' does not have privileges to execute 'ALTER' on: default.alltypes");
944 AuthzError(
"ALTER TABLE alltypes SET TBLPROPERTIES ('a'='b', 'c'='d')",
945 "User '%s' does not have privileges to execute 'ALTER' on: default.alltypes");
950 AuthzOk(
"ALTER VIEW functional_seq_snap.alltypes_view rename to " +
951 "functional_seq_snap.v1");
954 AuthzError(
"ALTER VIEW functional_seq_snap.alltypes_view rename to " +
955 "functional.alltypes",
956 "User '%s' does not have privileges to execute 'CREATE' on: " +
957 "functional.alltypes");
960 AuthzError(
"ALTER VIEW functional_seq_snap.alltypes_view rename to " +
961 "functional.alltypes_view",
962 "User '%s' does not have privileges to execute 'CREATE' on: " +
963 "functional.alltypes_view");
966 AuthzError(
"ALTER VIEW functional.alltypes rename to " +
967 "functional_seq_snap.new_view",
968 "User '%s' does not have privileges to execute 'ALTER' on: " +
969 "functional.alltypes");
972 AuthzError(
"ALTER VIEW functional.notbl rename to functional_seq_snap.newtbl",
973 "User '%s' does not have privileges to execute 'ALTER' on: functional.notbl");
976 AuthzError(
"ALTER VIEW nodb.alltypes rename to functional_seq_snap.newtbl",
977 "User '%s' does not have privileges to execute 'ALTER' on: nodb.alltypes");
980 AuthzError(
"ALTER VIEW functional.notbl rename to functional_seq_snap.new_view",
981 "User '%s' does not have privileges to execute 'ALTER' on: functional.notbl");
984 AuthzError(
"ALTER VIEW nodb.alltypes rename to functional_seq_snap.new_view",
985 "User '%s' does not have privileges to execute 'ALTER' on: nodb.alltypes");
988 AuthzError(
"ALTER VIEW alltypes rename to functional_seq_snap.new_view",
989 "User '%s' does not have privileges to execute 'ALTER' on: default.alltypes");
992 AuthzError(
"alter view functional.alltypes_view as " +
993 "select * from functional.alltypesagg",
994 "User '%s' does not have privileges to execute 'ALTER' on: " +
995 "functional.alltypes_view");
998 AuthzError(
"alter view functional_seq_snap.alltypes_view " +
999 "as select * from functional.alltypes_view",
1000 "User '%s' does not have privileges to execute 'SELECT' on: " +
1001 "functional.alltypes_view");
1006 AuthzOk(
"compute stats functional_seq_snap.alltypes");
1008 AuthzError(
"compute stats functional.alltypes",
1009 "User '%s' does not have privileges to execute 'ALTER' on: functional.alltypes");
1010 AuthzError(
"compute stats functional.alltypesagg",
1011 "User '%s' does not have privileges to execute 'ALTER' on: " +
1012 "functional.alltypesagg");
1017 AuthzOk(
"drop stats functional_seq_snap.alltypes");
1019 AuthzError(
"drop stats functional.alltypes",
1020 "User '%s' does not have privileges to execute 'ALTER' on: functional.alltypes");
1021 AuthzError(
"drop stats functional.alltypesagg",
1022 "User '%s' does not have privileges to execute 'ALTER' on: " +
1023 "functional.alltypesagg");
1028 AuthzOk(
"describe functional.alltypesagg");
1029 AuthzOk(
"describe functional.alltypes");
1030 AuthzOk(
"describe functional.complex_view");
1033 AuthzError(
"describe alltypes",
1034 "User '%s' does not have privileges to access: default.alltypes");
1036 AuthzError(
"describe nodb.alltypes",
1037 "User '%s' does not have privileges to access: nodb.alltypes");
1039 AuthzError(
"describe functional.alltypestiny",
1040 "User '%s' does not have privileges to access: functional.alltypestiny");
1042 AuthzError(
"describe functional.alltypes_view",
1043 "User '%s' does not have privileges to access: functional.alltypes_view");
1045 AuthzError(
"describe functional_rc.alltypes",
1046 "User '%s' does not have privileges to access: functional_rc.alltypes");
1052 AuthzOk(
"load data inpath 'hdfs://localhost:20500/test-warehouse/tpch.lineitem'" +
1053 " into table functional.alltypes partition(month=10, year=2009)");
1056 AuthzError(
"load data inpath 'hdfs://localhost:20500/test-warehouse/tpch.lineitem'" +
1057 " into table functional.alltypesagg",
1058 "User '%s' does not have privileges to execute 'INSERT' on: " +
1059 "functional.alltypes");
1062 AuthzError(
"load data inpath 'hdfs://localhost:20500/test-warehouse/tpch.part'" +
1063 " into table functional.alltypes partition(month=10, year=2009)",
1064 "User '%s' does not have privileges to access: " +
1065 "hdfs://localhost:20500/test-warehouse/tpch.part");
1068 AuthzError(
"load data inpath 'hdfs://localhost:20500/test-warehouse/nope'" +
1069 " into table functional.alltypes partition(month=10, year=2009)",
1070 "User '%s' does not have privileges to access: " +
1071 "hdfs://localhost:20500/test-warehouse/nope");
1074 AuthzError(
"load data inpath 'hdfs://localhost:20500/test-warehouse/tpch.lineitem'" +
1075 " into table functional.notable",
1076 "User '%s' does not have privileges to execute 'INSERT' on: " +
1077 "functional.notable");
1078 AuthzError(
"load data inpath 'hdfs://localhost:20500/test-warehouse/tpch.lineitem'" +
1079 " into table nodb.alltypes",
1080 "User '%s' does not have privileges to execute 'INSERT' on: " +
1084 AuthzError(
"load data inpath 'hdfs://localhost:20500/test-warehouse/tpch.lineitem'" +
1085 " into table functional.alltypes_view",
1086 "User '%s' does not have privileges to execute 'INSERT' on: " +
1087 "functional.alltypes_view");
1092 AuthzOk(
"show tables in functional");
1093 AuthzOk(
"show databases");
1094 AuthzOk(
"show tables in _impala_builtins");
1095 AuthzOk(
"show functions in _impala_builtins");
1098 AuthzError(
"show tables in functional_rc",
1099 "User '%s' does not have privileges to access: functional_rc.*");
1102 AuthzError(
"show tables in nodb",
1103 "User '%s' does not have privileges to access: nodb.*");
1105 AuthzError(
"show tables",
1106 "User '%s' does not have privileges to access: default.*");
1110 AuthzOk(
"show tables in newdb");
1111 fail(
"Expected AnalysisException");
1112 }
catch (AnalysisException e) {
1113 Assert.assertEquals(e.getMessage(),
"Database does not exist: newdb");
1117 String[] statsQuals =
new String[] {
"partitions",
"table stats",
"column stats" };
1118 for (String qual: statsQuals) {
1119 AuthzOk(String.format(
"show %s functional.alltypesagg", qual));
1120 AuthzOk(String.format(
"show %s functional.alltypes", qual));
1122 AuthzError(String.format(
"show %s nodb.tbl", qual),
1123 "User '%s' does not have privileges to access: nodb.tbl");
1124 AuthzError(String.format(
"show %s functional.badtbl", qual),
1125 "User '%s' does not have privileges to access: functional.badtbl");
1126 AuthzError(String.format(
"show %s functional_rc.alltypes", qual),
1127 "User '%s' does not have privileges to access: functional_rc.alltypes");
1131 String[] partitions =
new String[] {
"",
"partition(month=10, year=2010)" };
1132 for (String partition: partitions) {
1133 AuthzOk(String.format(
"show files in functional.alltypes %s", partition));
1135 AuthzError(String.format(
"show files in nodb.tbl %s", partition),
1136 "User '%s' does not have privileges to access: nodb.tbl");
1137 AuthzError(String.format(
"show files in functional.badtbl %s", partition),
1138 "User '%s' does not have privileges to access: functional.badtbl");
1139 AuthzError(String.format(
"show files in functional_rc.alltypes %s", partition),
1140 "User '%s' does not have privileges to access: functional_rc.alltypes");
1148 List<String> expectedDbs = Lists.newArrayList(
"default",
"functional",
1149 "functional_parquet",
"functional_seq_snap",
"tpcds",
"tpch");
1151 List<String> dbs = fe_.getDbNames(
"*", USER);
1152 Assert.assertEquals(expectedDbs, dbs);
1154 dbs = fe_.getDbNames(null, USER);
1155 Assert.assertEquals(expectedDbs, dbs);
1161 List<String> expectedTbls =
1162 Lists.newArrayList(
"alltypes",
"alltypesagg",
"complex_view",
"view_view");
1164 List<String> tables = fe_.getTableNames(
"functional",
"*", USER);
1165 Assert.assertEquals(expectedTbls, tables);
1167 tables = fe_.getTableNames(
"functional", null, USER);
1168 Assert.assertEquals(expectedTbls, tables);
1173 AuthzOk(
"show create table functional.alltypesagg");
1174 AuthzOk(
"show create table functional.alltypes");
1177 AuthzError(
"show create table alltypes",
1178 "User '%s' does not have privileges to access: default.alltypes");
1180 AuthzError(
"show create table nodb.alltypes",
1181 "User '%s' does not have privileges to access: nodb.alltypes");
1183 AuthzError(
"show create table functional.alltypestiny",
1184 "User '%s' does not have privileges to access: functional.alltypestiny");
1186 AuthzError(
"show create table functional_rc.alltypes",
1187 "User '%s' does not have privileges to access: functional_rc.alltypes");
1192 TMetadataOpRequest req =
new TMetadataOpRequest();
1193 req.setSession(createSessionState(
"default", USER));
1194 req.opcode = TMetadataOpcode.GET_TABLES;
1195 req.get_tables_req =
new TGetTablesReq();
1196 req.get_tables_req.setSchemaName(
"functional");
1198 req.get_tables_req.setTableName(
"%");
1199 TResultSet resp = fe_.execHiveServer2MetadataOp(req);
1200 assertEquals(4, resp.rows.size());
1201 assertEquals(
"alltypes",
1202 resp.rows.get(0).colVals.get(2).string_val.toLowerCase());
1204 "alltypesagg", resp.rows.get(1).colVals.get(2).string_val.toLowerCase());
1206 "complex_view", resp.rows.get(2).colVals.get(2).string_val.toLowerCase());
1208 "view_view", resp.rows.get(3).colVals.get(2).string_val.toLowerCase());
1213 TMetadataOpRequest req =
new TMetadataOpRequest();
1214 req.setSession(createSessionState(
"default", USER));
1215 req.opcode = TMetadataOpcode.GET_SCHEMAS;
1216 req.get_schemas_req =
new TGetSchemasReq();
1218 req.get_schemas_req.setSchemaName(
"%");
1219 TResultSet resp = fe_.execHiveServer2MetadataOp(req);
1220 List<String> expectedDbs = Lists.newArrayList(
"default",
"functional",
1221 "functional_parquet",
"functional_seq_snap",
"tpcds",
"tpch");
1222 assertEquals(expectedDbs.size(), resp.rows.size());
1223 for (
int i = 0; i < resp.rows.size(); ++i) {
1224 assertEquals(expectedDbs.get(i),
1225 resp.rows.get(i).colVals.get(0).string_val.toLowerCase());
1232 TMetadataOpRequest req =
new TMetadataOpRequest();
1233 req.opcode = TMetadataOpcode.GET_COLUMNS;
1234 req.setSession(createSessionState(
"default", USER));
1235 req.get_columns_req =
new TGetColumnsReq();
1236 req.get_columns_req.setSchemaName(
"functional");
1237 req.get_columns_req.setTableName(
"alltypes");
1238 req.get_columns_req.setColumnName(
"stri%");
1239 TResultSet resp = fe_.execHiveServer2MetadataOp(req);
1240 assertEquals(1, resp.rows.size());
1243 req.get_columns_req.setTableName(
"alltypesnopart");
1244 resp = fe_.execHiveServer2MetadataOp(req);
1245 assertEquals(0, resp.rows.size());
1249 req.get_columns_req.setSchemaName(
"functional_seq_gzip");
1250 req.get_columns_req.setTableName(
"alltypes");
1251 resp = fe_.execHiveServer2MetadataOp(req);
1252 assertEquals(0, resp.rows.size());
1259 List<User> users = Lists.newArrayList(
1261 new User(USER.
getName() +
"/abc.host.com@REAL.COM"),
1263 for (
User user: users) {
1269 AuthzOk(context,
"select * from functional.alltypesagg");
1272 AuthzError(context,
"select * from alltypes",
1273 "User '%s' does not have privileges to execute 'SELECT' on: default.alltypes",
1285 User currentUser = USER;
1289 AuthzError(context,
"show functions",
1290 "User '%s' does not have privileges to access: default", currentUser);
1291 AuthzOk(context,
"show functions in tpch");
1293 AuthzError(context,
"create function f() returns int location " +
1294 "'/test-warehouse/libTestUdfs.so' symbol='NoArgs'",
1295 "User '%s' does not have privileges to CREATE/DROP functions.", currentUser);
1297 AuthzError(context,
"create function tpch.f() returns int location " +
1298 "'/test-warehouse/libTestUdfs.so' symbol='NoArgs'",
1299 "User '%s' does not have privileges to CREATE/DROP functions.", currentUser);
1301 AuthzError(context,
"create function notdb.f() returns int location " +
1302 "'/test-warehouse/libTestUdfs.so' symbol='NoArgs'",
1303 "User '%s' does not have privileges to CREATE/DROP functions.", currentUser);
1305 AuthzError(context,
"drop function if exists f()",
1306 "User '%s' does not have privileges to CREATE/DROP functions.", currentUser);
1308 AuthzError(context,
"drop function notdb.f()",
1309 "User '%s' does not have privileges to CREATE/DROP functions.", currentUser);
1319 sentryService.grantRoleToGroup(USER,
"admin", USER.getName());
1322 AuthzOk(
"show functions");
1323 AuthzOk(
"show functions in tpch");
1325 AuthzOk(
"create function f() returns int location " +
1326 "'/test-warehouse/libTestUdfs.so' symbol='NoArgs'");
1327 AuthzOk(
"create function tpch.f() returns int location " +
1328 "'/test-warehouse/libTestUdfs.so' symbol='NoArgs'");
1329 AuthzOk(
"drop function if exists f()");
1332 AuthzError(
"create function _impala_builtins.f() returns int location " +
1333 "'/test-warehouse/libTestUdfs.so' symbol='NoArgs'",
1334 "Cannot modify system database.");
1335 AuthzError(
"drop function if exists pi()",
1336 "Cannot modify system database.");
1340 new ArrayList<Type>(),
Type.
INT, null, null, null, null));
1342 new ArrayList<Type>(),
Type.
INT, null, null, null, null));
1344 AuthzOk(
"drop function tpch.f()");
1346 sentryService.revokeRoleFromGroup(USER,
"admin", USER.getName());
1349 AuthzError(context,
"create function tpch.f() returns int location " +
1350 "'/test-warehouse/libTestUdfs.so' symbol='NoArgs'",
1351 "User '%s' does not have privileges to CREATE/DROP functions.", currentUser);
1354 AuthzOk(
"select tpch.f()");
1359 new ArrayList<Type>(),
Type.
INT, null, null, null, null));
1361 new ArrayList<Type>(),
Type.
INT, null, null, null, null));
1370 "differentServerName", AUTHZ_POLICY_FILE,
""),
1371 new User(System.getProperty(
"user.name")));
1384 AUTHZ_POLICY_FILE +
"_does_not_exist",
""),
1385 new User(System.getProperty(
"user.name")));
1390 String sentryConfig = authzConfig_.getSentryConfig().getConfigFile();
1393 "server1", AUTHZ_POLICY_FILE, sentryConfig);
1394 config.validateConfig();
1395 Assert.assertTrue(config.isEnabled());
1396 Assert.assertTrue(config.isFileBasedPolicy());
1398 config = AuthorizationConfig.createHadoopGroupAuthConfig(
"server1", null,
1400 config.validateConfig();
1401 Assert.assertTrue(config.isEnabled());
1402 Assert.assertTrue(!config.isFileBasedPolicy());
1406 config = AuthorizationConfig.createHadoopGroupAuthConfig(
1407 "server1", AUTHZ_POLICY_FILE, null);
1408 Assert.assertTrue(config.isEnabled());
1410 config.validateConfig();
1411 }
catch (Exception e) {
1412 Assert.assertEquals(e.getMessage(),
"A valid path to a sentry-site.xml config " +
1413 "file must be set using --sentry_config to enable authorization.");
1417 config = AuthorizationConfig.createHadoopGroupAuthConfig(
1418 "", AUTHZ_POLICY_FILE, sentryConfig);
1419 Assert.assertTrue(config.isEnabled());
1421 config.validateConfig();
1422 fail(
"Expected configuration to fail.");
1423 }
catch (IllegalArgumentException e) {
1424 Assert.assertEquals(e.getMessage(),
1425 "Authorization is enabled but the server name is null or empty. Set the " +
1426 "server name using the impalad --server_name flag.");
1428 config = AuthorizationConfig.createHadoopGroupAuthConfig(null, AUTHZ_POLICY_FILE,
1430 Assert.assertTrue(config.isEnabled());
1432 config.validateConfig();
1433 fail(
"Expected configuration to fail.");
1434 }
catch (IllegalArgumentException e) {
1435 Assert.assertEquals(e.getMessage(),
1436 "Authorization is enabled but the server name is null or empty. Set the " +
1437 "server name using the impalad --server_name flag.");
1441 config = AuthorizationConfig.createHadoopGroupAuthConfig(
"server1",
"",
1442 "/path/does/not/exist.xml");
1443 Assert.assertTrue(config.isEnabled());
1445 config.validateConfig();
1446 fail(
"Expected configuration to fail.");
1447 }
catch (Exception e) {
1448 Assert.assertEquals(e.getMessage(),
1449 "Sentry configuration file does not exist: /path/does/not/exist.xml");
1454 "ClassDoesNotExist");
1455 Assert.assertTrue(config.isEnabled());
1457 config.validateConfig();
1458 fail(
"Expected configuration to fail.");
1459 }
catch (IllegalArgumentException e) {
1460 Assert.assertEquals(e.getMessage(),
1461 "The authorization policy provider class 'ClassDoesNotExist' was not found.");
1466 this.getClass().getName());
1467 Assert.assertTrue(config.isEnabled());
1469 config.validateConfig();
1470 fail(
"Expected configuration to fail.");
1471 }
catch (IllegalArgumentException e) {
1472 Assert.assertEquals(e.getMessage(), String.format(
"The authorization policy " +
1473 "provider class '%s' must be a subclass of '%s'.",
this.getClass().getName(),
1474 ResourceAuthorizationProvider.class.getName()));
1479 Assert.assertFalse(config.isEnabled());
1481 Assert.assertFalse(config.isEnabled());
1483 Assert.assertFalse(config.isEnabled());
1485 Assert.assertFalse(config.isEnabled());
1495 AUTHZ_POLICY_FILE,
"",
1496 LocalGroupResourceAuthorizationProvider.class.getName());
1506 AuthzOk(fe, context,
"select * from functional.alltypesagg");
1508 AuthzError(fe, context,
"select * from functional.alltypes",
1509 "User '%s' does not have privileges to execute 'SELECT' on: functional.alltypes",
1513 user =
new User(
"admin_user");
1516 fe =
new Frontend(authzConfig, catalog);
1519 AuthzOk(fe, context,
"select * from functional.alltypesagg");
1520 AuthzOk(fe, context,
"select * from functional.alltypes");
1521 AuthzOk(fe, context,
"invalidate metadata");
1529 AuthzError(fe, ac,
"select * from functional.alltypesagg",
1530 "User '%s' does not have privileges to execute 'SELECT' on: " +
1531 "functional.alltypesagg", user);
1532 AuthzError(fe, ac,
"ALTER TABLE functional_seq_snap.alltypes ADD COLUMNS (c1 int)",
1533 "User '%s' does not have privileges to execute 'ALTER' on: " +
1534 "functional_seq_snap.alltypes", user);
1535 AuthzError(fe, ac,
"drop table tpch.lineitem",
1536 "User '%s' does not have privileges to execute 'DROP' on: tpch.lineitem",
1538 AuthzError(fe, ac,
"show tables in functional",
1539 "User '%s' does not have privileges to access: functional.*", user);
1544 AuthzOk(analysisContext_, stmt);
1549 AuthzOk(fe_, context, stmt);
1554 context.analyze(stmt);
1555 context.getAnalyzer().authorize(fe.getAuthzChecker());
1564 AuthzError(analysisContext_, stmt, expectedErrorString, USER);
1569 AuthzError(fe_, analysisContext, stmt, expectedErrorString, user);
1574 Preconditions.checkNotNull(expectedErrorString);
1577 analysisContext.analyze(stmt);
1579 analysisContext.getAnalyzer().authorize(fe.getAuthzChecker());
1581 }
catch (AuthorizationException e) {
1583 expectedErrorString = String.format(expectedErrorString, user.getName());
1584 String errorString = e.getMessage();
1586 "got error:\n" + errorString +
"\nexpected:\n" + expectedErrorString,
1587 errorString.startsWith(expectedErrorString));
1590 fail(
"Stmt didn't result in authorization error: " + stmt);
1594 return new TSessionState(null, null,
1595 defaultDb, user.
getName(),
new TNetworkAddress(
"", 0));
final ImpaladCatalog catalog_
SentryConfig getSentryConfig()
void TestShowPermissions()
void TestServerNameAuthorized()
void TestCreateDatabase()
static AuthorizationConfig createHadoopGroupAuthConfig(String serverName, String policyFile, String sentryConfigFile)
static TQueryCtx createQueryContext()
AuthorizationTest(String policyFile)
final AnalysisContext analysisContext_
static void AuthzError(Frontend fe, AnalysisContext analysisContext, String stmt, String expectedErrorString, User user)
void TestShowDbResultsFiltered()
void TestShowTableResultsFiltered()
static TSessionState createSessionState(String defaultDb, User user)
void TestShowCreateTable()
void TestComputeStatsTable()
static void AuthzOk(Frontend fe, AnalysisContext context, String stmt)
void AuthzOk(String stmt)
static final ScalarType INT
void TestNoPermissionsWhenPolicyFileDoesNotExist()
uint64_t Test(T *ht, const ProbeTuple *input, uint64_t num_tuples)
static Collection testVectors()
void AuthzError(AnalysisContext analysisContext, String stmt, String expectedErrorString, User user)
final TQueryCtx queryCtx_
void TestConfigValidation()
SentryPolicyService createSentryService()
void TestLocalGroupPolicyProvider()
void AuthzOk(AnalysisContext context, String stmt)
void TestShortUsernameUsed()
final AuthorizationConfig authzConfig_
static final String ANY_TABLE_NAME
static final String DEFAULT_DB
void TestWithIncorrectConfig(AuthorizationConfig authzConfig, User user)
void AuthzError(String stmt, String expectedErrorString)
boolean isFileBasedPolicy()