29
29
import org .elasticsearch .action .admin .indices .delete .DeleteIndexRequest ;
30
30
import org .elasticsearch .action .admin .indices .get .GetIndexAction ;
31
31
import org .elasticsearch .action .admin .indices .get .GetIndexRequest ;
32
+ import org .elasticsearch .action .admin .indices .mapping .put .PutMappingAction ;
33
+ import org .elasticsearch .action .admin .indices .mapping .put .PutMappingRequest ;
32
34
import org .elasticsearch .action .admin .indices .recovery .RecoveryAction ;
33
35
import org .elasticsearch .action .admin .indices .recovery .RecoveryRequest ;
34
36
import org .elasticsearch .action .admin .indices .segments .IndicesSegmentsAction ;
@@ -2042,10 +2044,10 @@ public void testMonitoringOperationsAgainstSecurityIndexRequireAllowRestricted()
2042
2044
}
2043
2045
}
2044
2046
2045
- public void testSuperusersCanExecuteOperationAgainstSecurityIndex () throws IOException {
2047
+ public void testSuperusersCanExecuteReadOperationAgainstSecurityIndex () throws IOException {
2046
2048
final User superuser = new User ("custom_admin" , ReservedRolesStore .SUPERUSER_ROLE_DESCRIPTOR .getName ());
2047
2049
roleMap .put (ReservedRolesStore .SUPERUSER_ROLE_DESCRIPTOR .getName (), ReservedRolesStore .SUPERUSER_ROLE_DESCRIPTOR );
2048
- ClusterState state = mockClusterState (
2050
+ mockClusterState (
2049
2051
Metadata .builder ()
2050
2052
.put (
2051
2053
new IndexMetadata .Builder (INTERNAL_SECURITY_MAIN_INDEX_7 ).putAlias (
@@ -2062,40 +2064,80 @@ public void testSuperusersCanExecuteOperationAgainstSecurityIndex() throws IOExc
2062
2064
final String requestId = AuditUtil .getOrGenerateRequestId (threadContext );
2063
2065
2064
2066
List <Tuple <String , TransportRequest >> requests = new ArrayList <>();
2067
+ requests .add (new Tuple <>(SearchAction .NAME , new SearchRequest (randomFrom (SECURITY_MAIN_ALIAS , INTERNAL_SECURITY_MAIN_INDEX_7 ))));
2068
+ requests .add (
2069
+ new Tuple <>(
2070
+ TermVectorsAction .NAME ,
2071
+ new TermVectorsRequest (randomFrom (SECURITY_MAIN_ALIAS , INTERNAL_SECURITY_MAIN_INDEX_7 ), "id" )
2072
+ )
2073
+ );
2074
+ requests .add (new Tuple <>(GetAction .NAME , new GetRequest (randomFrom (SECURITY_MAIN_ALIAS , INTERNAL_SECURITY_MAIN_INDEX_7 ), "id" )));
2065
2075
requests .add (
2066
- new Tuple <>(DeleteAction .NAME , new DeleteRequest (randomFrom (SECURITY_MAIN_ALIAS , INTERNAL_SECURITY_MAIN_INDEX_7 ), "id" ))
2076
+ new Tuple <>(ClusterHealthAction .NAME , new ClusterHealthRequest (randomFrom (SECURITY_MAIN_ALIAS , INTERNAL_SECURITY_MAIN_INDEX_7 )))
2067
2077
);
2068
2078
requests .add (
2069
2079
new Tuple <>(
2070
- BulkAction .NAME + "[s]" ,
2071
- createBulkShardRequest (randomFrom (SECURITY_MAIN_ALIAS , INTERNAL_SECURITY_MAIN_INDEX_7 ), DeleteRequest :: new )
2080
+ ClusterHealthAction .NAME ,
2081
+ new ClusterHealthRequest (randomFrom (SECURITY_MAIN_ALIAS , INTERNAL_SECURITY_MAIN_INDEX_7 ), "foo" , "bar" )
2072
2082
)
2073
2083
);
2074
- requests .add (
2075
- new Tuple <>(UpdateAction .NAME , new UpdateRequest (randomFrom (SECURITY_MAIN_ALIAS , INTERNAL_SECURITY_MAIN_INDEX_7 ), "id" ))
2084
+
2085
+ for (final Tuple <String , TransportRequest > requestTuple : requests ) {
2086
+ final String action = requestTuple .v1 ();
2087
+ final TransportRequest request = requestTuple .v2 ();
2088
+ try (ThreadContext .StoredContext ignore = threadContext .newStoredContext (false )) {
2089
+ final Authentication authentication = createAuthentication (superuser );
2090
+ authorize (authentication , action , request );
2091
+ verify (auditTrail ).accessGranted (
2092
+ eq (requestId ),
2093
+ eq (authentication ),
2094
+ eq (action ),
2095
+ eq (request ),
2096
+ authzInfoRoles (superuser .roles ())
2097
+ );
2098
+ }
2099
+ }
2100
+ }
2101
+
2102
+ public void testSuperusersCannotExecuteWriteOperationAgainstSecurityIndex () throws IOException {
2103
+ final User superuser = new User ("custom_admin" , ReservedRolesStore .SUPERUSER_ROLE_DESCRIPTOR .getName ());
2104
+ roleMap .put (ReservedRolesStore .SUPERUSER_ROLE_DESCRIPTOR .getName (), ReservedRolesStore .SUPERUSER_ROLE_DESCRIPTOR );
2105
+ mockClusterState (
2106
+ Metadata .builder ()
2107
+ .put (
2108
+ new IndexMetadata .Builder (INTERNAL_SECURITY_MAIN_INDEX_7 ).putAlias (
2109
+ new AliasMetadata .Builder (SECURITY_MAIN_ALIAS ).build ()
2110
+ )
2111
+ .settings (Settings .builder ().put ("index.version.created" , Version .CURRENT ).build ())
2112
+ .numberOfShards (1 )
2113
+ .numberOfReplicas (0 )
2114
+ .build (),
2115
+ true
2116
+ )
2117
+ .build ()
2076
2118
);
2077
- requests .add (new Tuple <>(IndexAction .NAME , new IndexRequest (randomFrom (SECURITY_MAIN_ALIAS , INTERNAL_SECURITY_MAIN_INDEX_7 ))));
2119
+ final String requestId = AuditUtil .getOrGenerateRequestId (threadContext );
2120
+
2121
+ List <Tuple <String , TransportRequest >> requests = new ArrayList <>();
2078
2122
requests .add (
2079
2123
new Tuple <>(
2080
2124
BulkAction .NAME + "[s]" ,
2081
- createBulkShardRequest (
2082
- randomFrom (SECURITY_MAIN_ALIAS , INTERNAL_SECURITY_MAIN_INDEX_7 ),
2083
- (index , id ) -> new IndexRequest (index ).id (id )
2084
- )
2125
+ createBulkShardRequest (randomFrom (SECURITY_MAIN_ALIAS , INTERNAL_SECURITY_MAIN_INDEX_7 ), DeleteRequest ::new )
2085
2126
)
2086
2127
);
2087
- requests .add (new Tuple <>(SearchAction .NAME , new SearchRequest (randomFrom (SECURITY_MAIN_ALIAS , INTERNAL_SECURITY_MAIN_INDEX_7 ))));
2088
2128
requests .add (
2089
2129
new Tuple <>(
2090
- TermVectorsAction .NAME ,
2091
- new TermVectorsRequest (randomFrom (SECURITY_MAIN_ALIAS , INTERNAL_SECURITY_MAIN_INDEX_7 ), "id" )
2130
+ BulkAction .NAME + "[s]" ,
2131
+ createBulkShardRequest (randomFrom (SECURITY_MAIN_ALIAS , INTERNAL_SECURITY_MAIN_INDEX_7 ), UpdateRequest :: new )
2092
2132
)
2093
2133
);
2094
- requests .add (new Tuple <>(GetAction .NAME , new GetRequest (randomFrom (SECURITY_MAIN_ALIAS , INTERNAL_SECURITY_MAIN_INDEX_7 ), "id" )));
2095
2134
requests .add (
2096
2135
new Tuple <>(
2097
- TermVectorsAction .NAME ,
2098
- new TermVectorsRequest (randomFrom (SECURITY_MAIN_ALIAS , INTERNAL_SECURITY_MAIN_INDEX_7 ), "id" )
2136
+ BulkAction .NAME + "[s]" ,
2137
+ createBulkShardRequest (
2138
+ randomFrom (SECURITY_MAIN_ALIAS , INTERNAL_SECURITY_MAIN_INDEX_7 ),
2139
+ (index , id ) -> new IndexRequest (index ).id (id )
2140
+ )
2099
2141
)
2100
2142
);
2101
2143
requests .add (
@@ -2105,22 +2147,23 @@ public void testSuperusersCanExecuteOperationAgainstSecurityIndex() throws IOExc
2105
2147
)
2106
2148
);
2107
2149
requests .add (
2108
- new Tuple <>(ClusterHealthAction .NAME , new ClusterHealthRequest (randomFrom (SECURITY_MAIN_ALIAS , INTERNAL_SECURITY_MAIN_INDEX_7 )))
2150
+ new Tuple <>(PutMappingAction .NAME , new PutMappingRequest (randomFrom (SECURITY_MAIN_ALIAS , INTERNAL_SECURITY_MAIN_INDEX_7 )))
2109
2151
);
2110
2152
requests .add (
2111
- new Tuple <>(
2112
- ClusterHealthAction .NAME ,
2113
- new ClusterHealthRequest (randomFrom (SECURITY_MAIN_ALIAS , INTERNAL_SECURITY_MAIN_INDEX_7 ), "foo" , "bar" )
2114
- )
2153
+ new Tuple <>(DeleteIndexAction .NAME , new DeleteIndexRequest (randomFrom (SECURITY_MAIN_ALIAS , INTERNAL_SECURITY_MAIN_INDEX_7 )))
2115
2154
);
2116
-
2117
2155
for (final Tuple <String , TransportRequest > requestTuple : requests ) {
2118
2156
final String action = requestTuple .v1 ();
2119
2157
final TransportRequest request = requestTuple .v2 ();
2120
2158
try (ThreadContext .StoredContext ignore = threadContext .newStoredContext (false )) {
2121
2159
final Authentication authentication = createAuthentication (superuser );
2122
- authorize (authentication , action , request );
2123
- verify (auditTrail ).accessGranted (
2160
+ assertThrowsAuthorizationException (
2161
+ "authentication=[" + authentication + "], action=[" + action + "], request=[" + request + "]" ,
2162
+ () -> authorize (authentication , action , request ),
2163
+ action ,
2164
+ superuser .principal ()
2165
+ );
2166
+ verify (auditTrail ).accessDenied (
2124
2167
eq (requestId ),
2125
2168
eq (authentication ),
2126
2169
eq (action ),
@@ -2131,11 +2174,11 @@ public void testSuperusersCanExecuteOperationAgainstSecurityIndex() throws IOExc
2131
2174
}
2132
2175
}
2133
2176
2134
- public void testSuperusersCanExecuteOperationAgainstSecurityIndexWithWildcard () throws IOException {
2177
+ public void testSuperusersCanExecuteReadOperationAgainstSecurityIndexWithWildcard () throws IOException {
2135
2178
final User superuser = new User ("custom_admin" , ReservedRolesStore .SUPERUSER_ROLE_DESCRIPTOR .getName ());
2136
2179
final Authentication authentication = createAuthentication (superuser );
2137
2180
roleMap .put (ReservedRolesStore .SUPERUSER_ROLE_DESCRIPTOR .getName (), ReservedRolesStore .SUPERUSER_ROLE_DESCRIPTOR );
2138
- ClusterState state = mockClusterState (
2181
+ mockClusterState (
2139
2182
Metadata .builder ()
2140
2183
.put (
2141
2184
new IndexMetadata .Builder (INTERNAL_SECURITY_MAIN_INDEX_7 ).putAlias (
0 commit comments