1
- /*
2
- * Copyright 2015-2018 _floragunn_ GmbH
3
- * Licensed under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License.
5
- * You may obtain a copy of the License at
6
- *
7
- * http://www.apache.org/licenses/LICENSE-2.0
8
- *
9
- * Unless required by applicable law or agreed to in writing, software
10
- * distributed under the License is distributed on an "AS IS" BASIS,
11
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- * See the License for the specific language governing permissions and
13
- * limitations under the License.
14
- */
15
-
16
1
/*
17
2
* SPDX-License-Identifier: Apache-2.0
18
3
*
32
17
import java .util .List ;
33
18
import java .util .Map ;
34
19
import java .util .Set ;
35
- import java .util .concurrent .CountDownLatch ;
36
- import java .util .concurrent .TimeUnit ;
37
20
import java .util .stream .Collectors ;
38
21
39
22
import com .google .common .collect .ImmutableSet ;
40
23
import org .apache .logging .log4j .LogManager ;
41
24
import org .apache .logging .log4j .Logger ;
42
25
43
- import org .opensearch .OpenSearchException ;
44
- import org .opensearch .action .ActionListener ;
45
26
import org .opensearch .action .ActionRequest ;
46
- import org .opensearch .action .LatchedActionListener ;
47
27
import org .opensearch .action .admin .indices .segments .PitSegmentsRequest ;
48
28
import org .opensearch .action .search .DeletePitRequest ;
49
29
import org .opensearch .action .search .GetAllPitNodesRequest ;
52
32
import org .opensearch .action .search .SearchRequest ;
53
33
import org .opensearch .cluster .metadata .IndexNameExpressionResolver ;
54
34
import org .opensearch .cluster .service .ClusterService ;
55
- import org .opensearch .common .unit .TimeValue ;
56
35
import org .opensearch .security .OpenSearchSecurityPlugin ;
57
36
import org .opensearch .security .resolver .IndexResolverReplacer ;
58
37
import org .opensearch .security .securityconf .SecurityRoles ;
@@ -71,27 +50,22 @@ public PrivilegesEvaluatorResponse evaluate(final ActionRequest request, final C
71
50
final IndexNameExpressionResolver resolver ,
72
51
boolean dnfOfEmptyResultsEnabled , final PrivilegesEvaluatorResponse presponse ) {
73
52
74
- // Skip pit evaluation for "NodesGetAllPITs" action, since it fetches all PITs across the cluster
75
- // for privilege evaluation
76
- if (action .startsWith ("cluster:admin" )) {
53
+ // Skip custom evaluation for "NodesGetAllPITs" action, since it fetches all PITs across the cluster
54
+ // for privilege evaluation - still this action will be evaluated in the generic PrivilegesEvaluator flow
55
+ if (action .startsWith ("cluster:admin/point_in_time " )) {
77
56
return presponse ;
78
57
}
79
- try {
80
- if (request instanceof GetAllPitNodesRequest ) {
81
- return handleGetAllPitsAccess (request , clusterService , user , securityRoles ,
82
- action , resolver , dnfOfEmptyResultsEnabled , presponse );
83
- } else if (request instanceof DeletePitRequest ) {
84
- DeletePitRequest deletePitRequest = (DeletePitRequest ) request ;
85
- return handleExplicitPitsAccess (deletePitRequest .getPitIds (), clusterService , user , securityRoles ,
86
- action , resolver , dnfOfEmptyResultsEnabled , presponse );
87
- } else if (request instanceof PitSegmentsRequest ) {
88
- PitSegmentsRequest pitSegmentsRequest = (PitSegmentsRequest ) request ;
89
- return handleExplicitPitsAccess (pitSegmentsRequest .getPitIds (), clusterService , user , securityRoles ,
90
- action , resolver , dnfOfEmptyResultsEnabled , presponse );
91
- }
92
- } catch (InterruptedException e ) {
93
- Thread .currentThread ().interrupt ();
94
- log .error (e .toString ());
58
+ if (request instanceof GetAllPitNodesRequest ) {
59
+ return handleGetAllPitsAccess (request , clusterService , user , securityRoles ,
60
+ action , resolver , dnfOfEmptyResultsEnabled , presponse );
61
+ } else if (request instanceof DeletePitRequest ) {
62
+ DeletePitRequest deletePitRequest = (DeletePitRequest ) request ;
63
+ return handleExplicitPitsAccess (deletePitRequest .getPitIds (), clusterService , user , securityRoles ,
64
+ action , resolver , presponse );
65
+ } else if (request instanceof PitSegmentsRequest ) {
66
+ PitSegmentsRequest pitSegmentsRequest = (PitSegmentsRequest ) request ;
67
+ return handleExplicitPitsAccess (pitSegmentsRequest .getPitIds (), clusterService , user , securityRoles ,
68
+ action , resolver , presponse );
95
69
}
96
70
return presponse ;
97
71
}
@@ -102,7 +76,7 @@ public PrivilegesEvaluatorResponse evaluate(final ActionRequest request, final C
102
76
private PrivilegesEvaluatorResponse handleGetAllPitsAccess (final ActionRequest request , final ClusterService clusterService ,
103
77
final User user , SecurityRoles securityRoles , final String action ,
104
78
IndexNameExpressionResolver resolver ,
105
- boolean dnfOfEmptyResultsEnabled , PrivilegesEvaluatorResponse presponse ) throws InterruptedException {
79
+ boolean dnfOfEmptyResultsEnabled , PrivilegesEvaluatorResponse presponse ) {
106
80
List <ListPitInfo > pitInfos = ((GetAllPitNodesRequest ) request ).getGetAllPitNodesResponse ().getPitInfos ();
107
81
// if cluster has no PITs, then allow the operation to pass with empty response if dnfOfEmptyResultsEnabled
108
82
// config property is true, otherwise fail the operation
@@ -126,17 +100,12 @@ private PrivilegesEvaluatorResponse handleGetAllPitsAccess(final ActionRequest r
126
100
String [] indices = pitToIndicesMap .get (pitId );
127
101
HashSet <String > indicesSet = new HashSet <>(Arrays .asList (indices ));
128
102
129
- final ImmutableSet <String > INDICES_SET = ImmutableSet .copyOf (indicesSet );
130
- final IndexResolverReplacer .Resolved pitResolved =
131
- new IndexResolverReplacer .Resolved (INDICES_SET , INDICES_SET , INDICES_SET ,
132
- ImmutableSet .of (), SearchRequest .DEFAULT_INDICES_OPTIONS );
133
-
134
- final Set <String > allPermittedIndices = securityRoles .reduce (pitResolved ,
135
- user , new String []{action }, resolver , clusterService );
103
+ final Set <String > allPermittedIndices = getPermittedIndices (indicesSet , clusterService , user ,
104
+ securityRoles , action , resolver );
136
105
if (isDebugEnabled ) {
137
106
log .debug ("Evaluating PIT ID : " + pitId );
138
107
}
139
- if (allPermittedIndices .size () == INDICES_SET .size ()) {
108
+ if (allPermittedIndices .size () == indicesSet .size ()) {
140
109
if (isDebugEnabled ) {
141
110
log .debug (" Permitting PIT ID : " + pitId );
142
111
}
@@ -157,8 +126,7 @@ private PrivilegesEvaluatorResponse handleGetAllPitsAccess(final ActionRequest r
157
126
*/
158
127
private PrivilegesEvaluatorResponse handleExplicitPitsAccess (List <String > pitIds , ClusterService clusterService ,
159
128
User user , SecurityRoles securityRoles , final String action ,
160
- IndexNameExpressionResolver resolver ,
161
- boolean dnfOfEmptyResultsEnabled , PrivilegesEvaluatorResponse presponse ) {
129
+ IndexNameExpressionResolver resolver , PrivilegesEvaluatorResponse presponse ) {
162
130
Map <String , String []> pitToIndicesMap = OpenSearchSecurityPlugin .
163
131
GuiceHolder .getPitService ().getIndicesForPits (pitIds );
164
132
Set <String > pitIndices = new HashSet <>();
@@ -183,9 +151,9 @@ private PrivilegesEvaluatorResponse handleExplicitPitsAccess(List<String> pitIds
183
151
private Set <String > getPermittedIndices (Set <String > pitIndices , ClusterService clusterService ,
184
152
User user , SecurityRoles securityRoles , final String action ,
185
153
IndexNameExpressionResolver resolver ) {
186
- final ImmutableSet <String > INDICES_SET = ImmutableSet .copyOf (pitIndices );
154
+ final ImmutableSet <String > pitImmutableIndices = ImmutableSet .copyOf (pitIndices );
187
155
final IndexResolverReplacer .Resolved pitResolved =
188
- new IndexResolverReplacer .Resolved (INDICES_SET , INDICES_SET , INDICES_SET ,
156
+ new IndexResolverReplacer .Resolved (pitImmutableIndices , pitImmutableIndices , pitImmutableIndices ,
189
157
ImmutableSet .of (), SearchRequest .DEFAULT_INDICES_OPTIONS );
190
158
return securityRoles .reduce (pitResolved ,
191
159
user , new String []{action }, resolver , clusterService );
0 commit comments