3838import org .elasticsearch .action .get .MultiGetRequest ;
3939import org .elasticsearch .action .termvectors .MultiTermVectorsRequest ;
4040import org .elasticsearch .action .index .IndexRequest ;
41+ import org .elasticsearch .action .main .MainRequest ;
4142import org .elasticsearch .action .search .MultiSearchRequest ;
4243import org .elasticsearch .action .search .SearchRequest ;
4344import org .elasticsearch .action .admin .indices .stats .IndicesStatsRequest ;
@@ -64,6 +65,27 @@ public class ActionIndicesAdaptor {
6465
6566 private HashMap <Class <?>, PermissionExtractor > methods ;
6667
68+ private String formatArn () {
69+ return String .join (":" ,
70+ "arn" ,
71+ partition ,
72+ service ,
73+ region ,
74+ ""
75+ );
76+ }
77+
78+ private String formatArn (String resourceType , String resource ) {
79+ return String .join (":" ,
80+ formatArn (),
81+ resourceType + "/" + resource
82+ );
83+ }
84+
85+ private String formatArn (String resourceType ) {
86+ return formatArn (resourceType , "" );
87+ }
88+
6789 public ActionIndicesAdaptor (String partition , String service , String region ) {
6890 this .partition = partition ;
6991 this .service = service ;
@@ -121,23 +143,16 @@ public ActionIndicesAdaptor(String partition, String service, String region) {
121143 Set <String > permission = permissions .get ("IndicesDataReadSearch" );
122144 Stream .of (req .indices ()).map (idx -> formatArn ("index" , idx )).forEach (permission ::add );
123145 });
124- }
125-
126- private String formatArn (String resourceType , String resource ) {
127- return String .join (":" ,
128- "arn" ,
129- partition ,
130- service ,
131- region ,
132- "" ,
133- resourceType + "/" + resource
134- );
146+
147+ this .methods .put (MainRequest .class , (permissions , request ) -> {
148+ permissions .get ("ClusterMonitorMain" ).add (formatArn ());
149+ });
135150 }
136151
137152 private void getIndices (Map <String , Set <String >>permissions , ActionRequest req ) {
138153 PermissionExtractor extractor = methods .get (req .getClass ());
139154 if (extractor == null ) {
140- logger .error ("Unable to find adaptor for request. This is a bug!" );
155+ logger .error ("Unable to find adaptor for request " + req . getClass () + " . This is a bug!" );
141156 return ;
142157 }
143158 extractor .extract (permissions , req );
0 commit comments