Skip to content

Commit cbabdff

Browse files
cbuescherjfreden
authored andcommitted
Rename methods in o.e.x.c.security.support.Automatons (elastic#114594)
Lucene 10 stopped relying in on automaton minimization and moved the underlying Hopcroft algorithm to test code (for reasoning see apache/lucene#528). With the upgrade to Lucene 10 we currently also only determinize automata. The security Automatons utility class currently contains several methods that sound like they would minimize the automaton, but this has changed so this PR also changes the method names accordingly.
1 parent 1e4bac3 commit cbabdff

File tree

8 files changed

+31
-28
lines changed

8 files changed

+31
-28
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/permission/ApplicationPermission.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public final class ApplicationPermission {
5353
return new PermissionEntry(
5454
appPriv,
5555
Sets.union(existing.resourceNames, resourceNames),
56-
Automatons.unionAndMinimize(Arrays.asList(existing.resourceAutomaton, patterns))
56+
Automatons.unionAndDeterminize(Arrays.asList(existing.resourceAutomaton, patterns))
5757
);
5858
}
5959
}));

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/permission/ClusterPermission.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public ClusterPermission build() {
137137
}
138138
List<PermissionCheck> checks = this.permissionChecks;
139139
if (false == actionAutomatons.isEmpty()) {
140-
final Automaton mergedAutomaton = Automatons.unionAndMinimize(this.actionAutomatons);
140+
final Automaton mergedAutomaton = Automatons.unionAndDeterminize(this.actionAutomatons);
141141
checks = new ArrayList<>(this.permissionChecks.size() + 1);
142142
checks.add(new AutomatonPermissionCheck(mergedAutomaton));
143143
checks.addAll(this.permissionChecks);
@@ -156,7 +156,7 @@ private static Automaton createAutomaton(Set<String> allowedActionPatterns, Set<
156156
} else {
157157
final Automaton allowedAutomaton = Automatons.patterns(allowedActionPatterns);
158158
final Automaton excludedAutomaton = Automatons.patterns(excludeActionPatterns);
159-
return Automatons.minusAndMinimize(allowedAutomaton, excludedAutomaton);
159+
return Automatons.minusAndDeterminize(allowedAutomaton, excludedAutomaton);
160160
}
161161
}
162162
}

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/permission/FieldPermissions.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public static Automaton initializePermittedFieldsAutomaton(FieldPermissionsDefin
147147
List<Automaton> automatonList = groups.stream()
148148
.map(g -> FieldPermissions.buildPermittedFieldsAutomaton(g.getGrantedFields(), g.getExcludedFields()))
149149
.collect(Collectors.toList());
150-
return Automatons.unionAndMinimize(automatonList);
150+
return Automatons.unionAndDeterminize(automatonList);
151151
}
152152

153153
/**
@@ -189,7 +189,7 @@ public static Automaton buildPermittedFieldsAutomaton(final String[] grantedFiel
189189
);
190190
}
191191

192-
grantedFieldsAutomaton = Automatons.minusAndMinimize(grantedFieldsAutomaton, deniedFieldsAutomaton);
192+
grantedFieldsAutomaton = Automatons.minusAndDeterminize(grantedFieldsAutomaton, deniedFieldsAutomaton);
193193
return grantedFieldsAutomaton;
194194
}
195195

@@ -206,7 +206,10 @@ public static Automaton buildPermittedFieldsAutomaton(final String[] grantedFiel
206206
public FieldPermissions limitFieldPermissions(FieldPermissions limitedBy) {
207207
if (hasFieldLevelSecurity() && limitedBy != null && limitedBy.hasFieldLevelSecurity()) {
208208
// TODO: cache the automaton computation with FieldPermissionsCache
209-
Automaton _permittedFieldsAutomaton = Automatons.intersectAndMinimize(getIncludeAutomaton(), limitedBy.getIncludeAutomaton());
209+
Automaton _permittedFieldsAutomaton = Automatons.intersectAndDeterminize(
210+
getIncludeAutomaton(),
211+
limitedBy.getIncludeAutomaton()
212+
);
210213
return new FieldPermissions(
211214
CollectionUtils.concatLists(fieldPermissionsDefinitions, limitedBy.fieldPermissionsDefinitions),
212215
_permittedFieldsAutomaton

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/permission/FieldPermissionsCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ FieldPermissions union(Collection<FieldPermissions> fieldPermissionsCollection)
107107
List<Automaton> automatonList = fieldPermissionsCollection.stream()
108108
.map(FieldPermissions::getIncludeAutomaton)
109109
.collect(Collectors.toList());
110-
return new FieldPermissions(key, Automatons.unionAndMinimize(automatonList));
110+
return new FieldPermissions(key, Automatons.unionAndDeterminize(automatonList));
111111
});
112112
} catch (ExecutionException e) {
113113
throw new ElasticsearchException("unable to compute field permissions", e);

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/permission/IndicesPermission.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -283,14 +283,14 @@ public boolean checkResourcePrivileges(
283283
for (String forIndexPattern : checkForIndexPatterns) {
284284
Automaton checkIndexAutomaton = Automatons.patterns(forIndexPattern);
285285
if (false == allowRestrictedIndices && false == isConcreteRestrictedIndex(forIndexPattern)) {
286-
checkIndexAutomaton = Automatons.minusAndMinimize(checkIndexAutomaton, restrictedIndices.getAutomaton());
286+
checkIndexAutomaton = Automatons.minusAndDeterminize(checkIndexAutomaton, restrictedIndices.getAutomaton());
287287
}
288288
if (false == Operations.isEmpty(checkIndexAutomaton)) {
289289
Automaton allowedIndexPrivilegesAutomaton = null;
290290
for (var indexAndPrivilegeAutomaton : indexGroupAutomatons.entrySet()) {
291291
if (Automatons.subsetOf(checkIndexAutomaton, indexAndPrivilegeAutomaton.getValue())) {
292292
if (allowedIndexPrivilegesAutomaton != null) {
293-
allowedIndexPrivilegesAutomaton = Automatons.unionAndMinimize(
293+
allowedIndexPrivilegesAutomaton = Automatons.unionAndDeterminize(
294294
Arrays.asList(allowedIndexPrivilegesAutomaton, indexAndPrivilegeAutomaton.getKey())
295295
);
296296
} else {
@@ -342,7 +342,7 @@ public Automaton allowedActionsMatcher(String index) {
342342
automatonList.add(group.privilege.getAutomaton());
343343
}
344344
}
345-
return automatonList.isEmpty() ? Automatons.EMPTY : Automatons.unionAndMinimize(automatonList);
345+
return automatonList.isEmpty() ? Automatons.EMPTY : Automatons.unionAndDeterminize(automatonList);
346346
}
347347

348348
/**
@@ -704,7 +704,7 @@ private Map<Automaton, Automaton> indexGroupAutomatons(boolean combine) {
704704
Automaton indexAutomaton = group.getIndexMatcherAutomaton();
705705
allAutomatons.compute(
706706
group.privilege().getAutomaton(),
707-
(key, value) -> value == null ? indexAutomaton : Automatons.unionAndMinimize(List.of(value, indexAutomaton))
707+
(key, value) -> value == null ? indexAutomaton : Automatons.unionAndDeterminize(List.of(value, indexAutomaton))
708708
);
709709
if (combine) {
710710
List<Tuple<Automaton, Automaton>> combinedAutomatons = new ArrayList<>();
@@ -714,7 +714,7 @@ private Map<Automaton, Automaton> indexGroupAutomatons(boolean combine) {
714714
group.privilege().getAutomaton()
715715
);
716716
if (Operations.isEmpty(intersectingPrivileges) == false) {
717-
Automaton indexPatternAutomaton = Automatons.unionAndMinimize(
717+
Automaton indexPatternAutomaton = Automatons.unionAndDeterminize(
718718
List.of(indexAndPrivilegeAutomatons.getValue(), indexAutomaton)
719719
);
720720
combinedAutomatons.add(new Tuple<>(intersectingPrivileges, indexPatternAutomaton));
@@ -723,7 +723,7 @@ private Map<Automaton, Automaton> indexGroupAutomatons(boolean combine) {
723723
combinedAutomatons.forEach(
724724
automatons -> allAutomatons.compute(
725725
automatons.v1(),
726-
(key, value) -> value == null ? automatons.v2() : Automatons.unionAndMinimize(List.of(value, automatons.v2()))
726+
(key, value) -> value == null ? automatons.v2() : Automatons.unionAndDeterminize(List.of(value, automatons.v2()))
727727
)
728728
);
729729
}
@@ -768,7 +768,7 @@ public Group(
768768
this.indexNameMatcher = StringMatcher.of(indices).and(name -> restrictedIndices.isRestricted(name) == false);
769769
this.indexNameAutomaton = () -> indexNameAutomatonMemo.computeIfAbsent(
770770
indices,
771-
k -> Automatons.minusAndMinimize(Automatons.patterns(indices), restrictedIndices.getAutomaton())
771+
k -> Automatons.minusAndDeterminize(Automatons.patterns(indices), restrictedIndices.getAutomaton())
772772
);
773773
}
774774
this.fieldPermissions = Objects.requireNonNull(fieldPermissions);

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/permission/LimitedRole.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public IsResourceAuthorizedPredicate allowedIndicesMatcher(String action) {
212212
public Automaton allowedActionsMatcher(String index) {
213213
final Automaton allowedMatcher = baseRole.allowedActionsMatcher(index);
214214
final Automaton limitedByMatcher = limitedByRole.allowedActionsMatcher(index);
215-
return Automatons.intersectAndMinimize(allowedMatcher, limitedByMatcher);
215+
return Automatons.intersectAndDeterminize(allowedMatcher, limitedByMatcher);
216216
}
217217

218218
/**

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/IndexPrivilege.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757

5858
import static java.util.Map.entry;
5959
import static org.elasticsearch.xpack.core.security.support.Automatons.patterns;
60-
import static org.elasticsearch.xpack.core.security.support.Automatons.unionAndMinimize;
60+
import static org.elasticsearch.xpack.core.security.support.Automatons.unionAndDeterminize;
6161

6262
/**
6363
* The name of an index related action always being with `indices:` followed by a sequence of slash-separated terms
@@ -110,7 +110,7 @@ public final class IndexPrivilege extends Privilege {
110110
private static final Automaton DELETE_AUTOMATON = patterns("indices:data/write/delete*", "indices:data/write/bulk*");
111111
private static final Automaton WRITE_AUTOMATON = patterns("indices:data/write/*", TransportAutoPutMappingAction.TYPE.name());
112112
private static final Automaton MONITOR_AUTOMATON = patterns("indices:monitor/*");
113-
private static final Automaton MANAGE_AUTOMATON = unionAndMinimize(
113+
private static final Automaton MANAGE_AUTOMATON = unionAndDeterminize(
114114
Arrays.asList(
115115
MONITOR_AUTOMATON,
116116
patterns("indices:admin/*", TransportFieldCapabilitiesAction.NAME + "*", GetRollupIndexCapsAction.NAME + "*")
@@ -303,7 +303,7 @@ private static IndexPrivilege resolve(Set<String> name) {
303303
if (actions.isEmpty() == false) {
304304
automata.add(patterns(actions));
305305
}
306-
return new IndexPrivilege(name, unionAndMinimize(automata));
306+
return new IndexPrivilege(name, unionAndDeterminize(automata));
307307
}
308308

309309
static Map<String, IndexPrivilege> values() {

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/support/Automatons.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public static Automaton patterns(Collection<String> patterns) {
112112

113113
private static Automaton buildAutomaton(Collection<String> patterns) {
114114
if (patterns.size() == 1) {
115-
return minimize(pattern(patterns.iterator().next()));
115+
return determinize(pattern(patterns.iterator().next()));
116116
}
117117

118118
final Function<Collection<String>, Automaton> build = strings -> {
@@ -121,7 +121,7 @@ private static Automaton buildAutomaton(Collection<String> patterns) {
121121
final Automaton patternAutomaton = pattern(pattern);
122122
automata.add(patternAutomaton);
123123
}
124-
return unionAndMinimize(automata);
124+
return unionAndDeterminize(automata);
125125
};
126126

127127
// We originally just compiled each automaton separately and then unioned them all.
@@ -188,7 +188,7 @@ private static Automaton buildAutomaton(Collection<String> patterns) {
188188
if (misc.isEmpty() == false) {
189189
automata.add(build.apply(misc));
190190
}
191-
return unionAndMinimize(automata);
191+
return unionAndDeterminize(automata);
192192
}
193193

194194
/**
@@ -277,22 +277,22 @@ static Automaton wildcard(String text) {
277277
return Operations.determinize(concatenate(automata), Operations.DEFAULT_DETERMINIZE_WORK_LIMIT);
278278
}
279279

280-
public static Automaton unionAndMinimize(Collection<Automaton> automata) {
280+
public static Automaton unionAndDeterminize(Collection<Automaton> automata) {
281281
Automaton res = automata.size() == 1 ? automata.iterator().next() : union(automata);
282-
return minimize(res);
282+
return determinize(res);
283283
}
284284

285-
public static Automaton minusAndMinimize(Automaton a1, Automaton a2) {
285+
public static Automaton minusAndDeterminize(Automaton a1, Automaton a2) {
286286
Automaton res = minus(a1, a2, maxDeterminizedStates);
287-
return minimize(res);
287+
return determinize(res);
288288
}
289289

290-
public static Automaton intersectAndMinimize(Automaton a1, Automaton a2) {
290+
public static Automaton intersectAndDeterminize(Automaton a1, Automaton a2) {
291291
Automaton res = intersection(a1, a2);
292-
return minimize(res);
292+
return determinize(res);
293293
}
294294

295-
private static Automaton minimize(Automaton automaton) {
295+
private static Automaton determinize(Automaton automaton) {
296296
return Operations.determinize(automaton, maxDeterminizedStates);
297297
}
298298

0 commit comments

Comments
 (0)