79
79
import org .elasticsearch .xpack .core .security .user .AsyncSearchUser ;
80
80
import org .elasticsearch .xpack .core .security .user .SystemUser ;
81
81
import org .elasticsearch .xpack .core .security .user .User ;
82
+ import org .elasticsearch .xpack .core .security .user .XPackSecurityUser ;
82
83
import org .elasticsearch .xpack .core .security .user .XPackUser ;
83
84
import org .elasticsearch .xpack .core .watcher .transport .actions .get .GetWatchAction ;
84
85
import org .elasticsearch .xpack .security .Security ;
127
128
import static org .hamcrest .Matchers .hasItem ;
128
129
import static org .hamcrest .Matchers .hasSize ;
129
130
import static org .hamcrest .Matchers .is ;
131
+ import static org .hamcrest .Matchers .notNullValue ;
130
132
import static org .hamcrest .Matchers .nullValue ;
131
133
import static org .mockito .ArgumentMatchers .any ;
132
134
import static org .mockito .ArgumentMatchers .anyCollection ;
@@ -1697,6 +1699,21 @@ private Authentication createAuthentication() {
1697
1699
);
1698
1700
}
1699
1701
1702
+ public void testXPackSecurityUserCanAccessAnyIndex () {
1703
+ for (String action : Arrays .asList (GetAction .NAME , DeleteAction .NAME , SearchAction .NAME , IndexAction .NAME )) {
1704
+ Predicate <IndexAbstraction > predicate = getXPackSecurityRole ().indices ().allowedIndicesMatcher (action );
1705
+
1706
+ IndexAbstraction index = mockIndexAbstraction (randomAlphaOfLengthBetween (3 , 12 ));
1707
+ assertThat (predicate .test (index ), Matchers .is (true ));
1708
+
1709
+ index = mockIndexAbstraction ("." + randomAlphaOfLengthBetween (3 , 12 ));
1710
+ assertThat (predicate .test (index ), Matchers .is (true ));
1711
+
1712
+ index = mockIndexAbstraction (".security-" + randomIntBetween (1 , 16 ));
1713
+ assertThat (predicate .test (index ), Matchers .is (true ));
1714
+ }
1715
+ }
1716
+
1700
1717
public void testXPackUserCanAccessNonRestrictedIndices () {
1701
1718
CharacterRunAutomaton restrictedAutomaton = new CharacterRunAutomaton (TestRestrictedIndices .RESTRICTED_INDICES_AUTOMATON );
1702
1719
for (String action : Arrays .asList (GetAction .NAME , DeleteAction .NAME , SearchAction .NAME , IndexAction .NAME )) {
@@ -1802,23 +1819,19 @@ private void getRoleForRoleNames(CompositeRolesStore rolesStore, Collection<Stri
1802
1819
rolesStore .getRole (subject , listener );
1803
1820
}
1804
1821
1822
+ private Role getXPackSecurityRole () {
1823
+ return getInternalUserRole (XPackSecurityUser .INSTANCE );
1824
+ }
1825
+
1805
1826
private Role getXPackUserRole () {
1806
- CompositeRolesStore compositeRolesStore = buildCompositeRolesStore (
1807
- SECURITY_ENABLED_SETTINGS ,
1808
- null ,
1809
- null ,
1810
- null ,
1811
- null ,
1812
- null ,
1813
- null ,
1814
- null ,
1815
- null ,
1816
- null
1817
- );
1818
- return compositeRolesStore .getXpackUserRole ();
1827
+ return getInternalUserRole (XPackUser .INSTANCE );
1819
1828
}
1820
1829
1821
1830
private Role getAsyncSearchUserRole () {
1831
+ return getInternalUserRole (AsyncSearchUser .INSTANCE );
1832
+ }
1833
+
1834
+ private Role getInternalUserRole (User internalUser ) {
1822
1835
CompositeRolesStore compositeRolesStore = buildCompositeRolesStore (
1823
1836
SECURITY_ENABLED_SETTINGS ,
1824
1837
null ,
@@ -1831,7 +1844,10 @@ private Role getAsyncSearchUserRole() {
1831
1844
null ,
1832
1845
null
1833
1846
);
1834
- return compositeRolesStore .getAsyncSearchUserRole ();
1847
+ final Subject subject = new Subject (internalUser , new RealmRef ("__attach" , "__attach" , randomAlphaOfLength (8 )));
1848
+ final Role role = compositeRolesStore .tryGetRoleForInternalUser (subject );
1849
+ assertThat ("Role for " + subject , role , notNullValue ());
1850
+ return role ;
1835
1851
}
1836
1852
1837
1853
private CompositeRolesStore buildCompositeRolesStore (
0 commit comments