@@ -92,6 +92,7 @@ DECLARE_bool(tera_ins_enabled);
9292DECLARE_int64 (tera_sdk_perf_counter_log_interval);
9393
9494DECLARE_bool (tera_acl_enabled);
95+ DECLARE_bool (tera_only_root_create_table);
9596DECLARE_string (tera_master_gc_strategy);
9697
9798namespace tera {
@@ -155,6 +156,7 @@ bool MasterImpl::Init() {
155156 m_zk_adapter.reset (new FakeMasterZkAdapter (this , m_local_addr));
156157 }
157158
159+ LOG (INFO ) << " [acl] " << (FLAGS_tera_acl_enabled ? " enabled" : " disabled" );
158160 SetMasterStatus (kIsSecondary );
159161 m_thread_pool->AddTask (boost::bind (&MasterImpl::InitAsync, this ));
160162 return true ;
@@ -462,16 +464,37 @@ bool MasterImpl::IsRootUser(const std::string& token) {
462464 return m_user_manager->UserNameToToken (" root" ) == token;
463465}
464466
467+ // user is admin or user is in admin_group
468+ bool MasterImpl::CheckUserPermissionOnTable (const std::string& token, TablePtr table) {
469+ std::string group_name = table->GetSchema ().admin_group ();
470+ std::string user_name = m_user_manager->TokenToUserName (token);
471+ return (m_user_manager->IsUserInGroup (user_name, group_name)
472+ || (table->GetSchema ().admin () == m_user_manager->TokenToUserName (token)));
473+ }
474+
475+ template <typename Request>
476+ bool MasterImpl::HasPermissionOnTable (const Request* request, TablePtr table) {
477+ if (!FLAGS_tera_acl_enabled
478+ || IsRootUser (request->user_token ())
479+ || ((table->GetSchema ().admin_group () == " " ) && (table->GetSchema ().admin () == " " ))
480+ || (request->has_user_token ()
481+ && CheckUserPermissionOnTable (request->user_token (), table))) {
482+ return true ;
483+
484+ }
485+ return false ;
486+ }
487+
465488template <typename Request, typename Response, typename Callback>
466- bool MasterImpl::HasTablePermission (const Request* request, Response* response,
467- Callback* done, TablePtr table, const char * operate) {
489+ bool MasterImpl::HasPermissionOrReturn (const Request* request, Response* response,
490+ Callback* done, TablePtr table, const char * operate) {
468491 // check permission
469- if (!FLAGS_tera_acl_enabled
470- || IsRootUser (request->user_token ())) {
471- LOG (INFO ) << " [acl] is acl enabled: " << FLAGS_tera_acl_enabled;
492+ if (HasPermissionOnTable (request, table)) {
472493 return true ;
473494 } else {
474- LOG (INFO ) << " [acl] fail to " << operate;
495+ std::string token = request->has_user_token () ? request->user_token () : " " ;
496+ LOG (INFO ) << " [acl] " << m_user_manager->TokenToUserName (token)
497+ << " :" << token << " fail to " << operate;
475498 response->set_sequence_id (request->sequence_id ());
476499 response->set_status (kNotPermission );
477500 done->Run ();
@@ -661,11 +684,13 @@ void MasterImpl::CreateTable(const CreateTableRequest* request,
661684 done->Run ();
662685 return ;
663686 }
664- if (FLAGS_tera_acl_enabled && !IsRootUser (request->user_token ())) {
665- response->set_sequence_id (request->sequence_id ());
666- response->set_status (kNotPermission );
667- done->Run ();
668- return ;
687+ if (FLAGS_tera_acl_enabled
688+ && !IsRootUser (request->user_token ())
689+ && FLAGS_tera_only_root_create_table) {
690+ response->set_sequence_id (request->sequence_id ());
691+ response->set_status (kNotPermission );
692+ done->Run ();
693+ return ;
669694 }
670695 if (!request->schema ().alias ().empty ()) {
671696 bool alias_exist = false ;
@@ -786,7 +811,7 @@ void MasterImpl::DeleteTable(const DeleteTableRequest* request,
786811 done->Run ();
787812 return ;
788813 }
789- if (!HasTablePermission (request, response, done, table, " delete table" )) {
814+ if (!HasPermissionOrReturn (request, response, done, table, " delete table" )) {
790815 return ;
791816 }
792817
@@ -842,7 +867,7 @@ void MasterImpl::DisableTable(const DisableTableRequest* request,
842867 done->Run ();
843868 return ;
844869 }
845- if (!HasTablePermission (request, response, done, table, " disable table" )) {
870+ if (!HasPermissionOrReturn (request, response, done, table, " disable table" )) {
846871 return ;
847872 }
848873
@@ -901,7 +926,7 @@ void MasterImpl::EnableTable(const EnableTableRequest* request,
901926 done->Run ();
902927 return ;
903928 }
904- if (!HasTablePermission (request, response, done, table, " enable table" )) {
929+ if (!HasPermissionOrReturn (request, response, done, table, " enable table" )) {
905930 return ;
906931 }
907932
@@ -952,7 +977,7 @@ void MasterImpl::UpdateTable(const UpdateTableRequest* request,
952977 done->Run ();
953978 return ;
954979 }
955- if (!HasTablePermission (request, response, done, table, " update table" )) {
980+ if (!HasPermissionOrReturn (request, response, done, table, " update table" )) {
956981 return ;
957982 }
958983
@@ -1074,11 +1099,19 @@ void MasterImpl::ShowTables(const ShowTablesRequest* request,
10741099 TableMetaList* table_meta_list = response->mutable_table_meta_list ();
10751100 for (uint32_t i = 0 ; i < table_list.size (); ++i) {
10761101 TablePtr table = table_list[i];
1102+ // if a user has NO permission on a table,
1103+ // he/she should not notice this table
1104+ if (!HasPermissionOnTable (request, table)) {
1105+ continue ;
1106+ }
10771107 table->ToMeta (table_meta_list->add_meta ());
10781108 }
10791109 TabletMetaList* tablet_meta_list = response->mutable_tablet_meta_list ();
10801110 for (uint32_t i = 0 ; i < tablet_list.size (); ++i) {
10811111 TabletPtr tablet = tablet_list[i];
1112+ if (!HasPermissionOnTable (request, tablet->GetTable ())) {
1113+ continue ;
1114+ }
10821115 TabletMeta meta;
10831116 tablet->ToMeta (&meta);
10841117 tablet_meta_list->add_meta ()->CopyFrom (meta);
@@ -1128,6 +1161,9 @@ void MasterImpl::ShowTabletNodes(const ShowTabletNodesRequest* request,
11281161 std::vector<TabletPtr> tablet_list;
11291162 m_tablet_manager->FindTablet (request->addr (), &tablet_list);
11301163 for (size_t i = 0 ; i < tablet_list.size (); ++i) {
1164+ if (!HasPermissionOnTable (request, tablet_list[i]->GetTable ())) {
1165+ continue ;
1166+ }
11311167 TabletMeta* meta = response->mutable_tabletmeta_list ()->add_meta ();
11321168 TabletCounter* counter = response->mutable_tabletmeta_list ()->add_counter ();
11331169 tablet_list[i]->ToMeta (meta);
@@ -3460,12 +3496,13 @@ void MasterImpl::QueryTabletNodeCallback(std::string addr, QueryRequest* request
34603496 ClearUnusedSnapshots (tablet, meta);
34613497 VLOG (30 ) << " [query] " << tablet;
34623498 } else {
3463- VLOG ( 30 ) << " fail to match tablet: " << meta.table_name ()
3499+ LOG ( WARNING ) << " fail to match tablet: " << meta.table_name ()
34643500 << " , path: " << meta.path ()
34653501 << " , range: [" << DebugString (key_start)
34663502 << " , " << DebugString (key_end)
34673503 << " ], size: " << meta.size ()
3468- << " , addr: " << meta.server_addr ();
3504+ << " , addr: " << meta.server_addr ()
3505+ << " , tablet: " << tablet;
34693506 }
34703507 }
34713508
0 commit comments