-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use same system index pattern in restricted names (#84180)
The index pattern that was used for the ".security" system index was not identical to the pattern used in RestrictedIndices. The consequence was that it would be possible for a user without restricted indices access to create an index that would get caught by the system indices pattern, which could lead to confusion. In 8.0 all system indices are automatically restricted, using the index name pattern from the system index descriptor, so in 7.17 we are changing the restricted index name to cover the same set of names as the system index descriptor
- Loading branch information
Showing
4 changed files
with
132 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pr: 84180 | ||
summary: Unify index name pattern between security system-index and RBAC restricted names | ||
area: Authorization | ||
type: enhancement | ||
issues: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...rc/test/java/org/elasticsearch/xpack/core/security/index/RestrictedIndicesNamesTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.core.security.index; | ||
|
||
import org.apache.lucene.util.automaton.CharacterRunAutomaton; | ||
import org.elasticsearch.test.ESTestCase; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
|
||
public class RestrictedIndicesNamesTests extends ESTestCase { | ||
|
||
private final CharacterRunAutomaton RUN_AUTOMATON = new CharacterRunAutomaton(RestrictedIndicesNames.NAMES_AUTOMATON); | ||
|
||
public void testAsyncSearchNames() { | ||
testIndex(".async-search", true); | ||
testIndex(".async-search" + (randomBoolean() ? "-" : "") + randomAlphaOfLengthBetween(1, 8), true); | ||
testIndex(".async-search" + (randomBoolean() ? "-" : "") + randomInt(), true); | ||
testIndex("async-search" + (randomBoolean() ? "-" : "") + randomInt(), false); | ||
testIndex(".asynchronous-search" + (randomBoolean() ? "-" : "") + randomInt(), false); | ||
testIndex(".not-async-search" + (randomBoolean() ? "-" : "") + randomAlphaOfLengthBetween(1, 8), false); | ||
} | ||
|
||
public void testSecurityNames() { | ||
testIndex(".security", true); | ||
testIndex(".security-6", true); | ||
testIndex(".security-7", true); | ||
testIndex(".security-" + randomIntBetween(0, 999_999), true); | ||
testIndex(".security-" + randomIntBetween(0, 99) + (randomBoolean() ? "-" : "") + randomAlphaOfLengthBetween(1, 20), true); | ||
|
||
testIndex(".security-tokens-7", true); | ||
testIndex(".security-tokens-" + randomIntBetween(0, 99) + (randomBoolean() ? "-" : "") + randomAlphaOfLengthBetween(1, 20), true); | ||
|
||
testIndex("security", false); | ||
testIndex(randomAlphaOfLength(1) + "security", false); | ||
testIndex("security-6", false); | ||
testIndex("@security-6", false); | ||
testIndex(".not-security-7", false); | ||
testIndex(".security-", false); | ||
testIndex("security-tokens", false); | ||
testIndex("security-tokens-7", false); | ||
testIndex("_security-tokens", false); | ||
testIndex(".security-" + randomAlphaOfLengthBetween(1, 3), false); | ||
testIndex(".security-tokens-" + randomAlphaOfLengthBetween(1, 3), false); | ||
testIndex(".security" + randomAlphaOfLengthBetween(1, 10), false); | ||
testIndex(".security-tokens" + randomAlphaOfLengthBetween(1, 10), false); | ||
testIndex(".security" + randomIntBetween(1, 9), false); | ||
testIndex(".security-" + randomAlphaOfLength(1) + randomIntBetween(1, 9), false); | ||
testIndex(".security" + randomAlphaOfLength(1) + randomIntBetween(1, 9), false); | ||
} | ||
|
||
private void testIndex(String name, boolean expected) { | ||
assertThat("For index [" + name + "]", RestrictedIndicesNames.isRestricted(name), is(expected)); | ||
assertThat("For index [" + name + "]", RUN_AUTOMATON.run(name), is(expected)); | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
...gin/security/src/test/java/org/elasticsearch/xpack/security/SecuritySystemIndexTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.security; | ||
|
||
import org.elasticsearch.test.ESTestCase; | ||
import org.elasticsearch.xpack.core.security.index.RestrictedIndicesNames; | ||
|
||
import java.util.function.Consumer; | ||
|
||
import static org.hamcrest.Matchers.is; | ||
|
||
public class SecuritySystemIndexTests extends ESTestCase { | ||
|
||
public void testSystemIndexNameIsRestricted() { | ||
Consumer<String> check = idx -> assertThat( | ||
"For index [" + idx + "]", | ||
Security.SECURITY_MAIN_INDEX_DESCRIPTOR.matchesIndexPattern(idx) | ||
|| Security.SECURITY_TOKEN_INDEX_DESCRIPTOR.matchesIndexPattern(idx), | ||
is(RestrictedIndicesNames.isRestricted(idx)) | ||
); | ||
|
||
check.accept(".security-" + randomIntBetween(0, 99)); | ||
check.accept(".security" + randomIntBetween(0, 99)); | ||
|
||
check.accept(".security-" + randomAlphaOfLengthBetween(1, 12)); | ||
check.accept(".security" + randomAlphaOfLengthBetween(1, 12)); | ||
|
||
check.accept(".security-" + randomIntBetween(0, 99) + (randomBoolean() ? "-" : "") + randomAlphaOfLengthBetween(1, 12)); | ||
check.accept(".security-" + randomAlphaOfLengthBetween(1, 12) + (randomBoolean() ? "-" : "") + randomIntBetween(0, 99)); | ||
|
||
check.accept(".security-tokens-" + randomAlphaOfLengthBetween(1, 12)); | ||
check.accept(".security-tokens-" + randomIntBetween(1, 99)); | ||
check.accept(".security-tokens-" + randomIntBetween(1, 99) + (randomBoolean() ? "-" : "") + randomAlphaOfLengthBetween(1, 12)); | ||
|
||
check.accept("." + randomAlphaOfLengthBetween(1, 12) + "-security"); | ||
|
||
check.accept(randomAlphaOfLengthBetween(1, 3) + "security"); | ||
check.accept(randomAlphaOfLengthBetween(1, 3) + ".security"); | ||
check.accept(randomAlphaOfLengthBetween(1, 3) + ".security-6"); | ||
check.accept(randomAlphaOfLengthBetween(1, 3) + "security-tokens-7"); | ||
} | ||
} |