isaric commented on code in PR #5320:
URL: https://github.com/apache/solr/pull/5320#discussion_r4710408143
##########
solr/solr-ref-guide/modules/upgrade-notes/pages/major-changes-in-solr-10.adoc:
##########
@@ -91,6 +91,12 @@ A request with no other parameters returns every collection.
The v1 `CLUSTERSTATUS` command is unchanged, and `includeAll` still defaults
to true.
+=== Permissions have a stable `id`
Review Comment:
Is this intended for `branch_10x`? The entries in the Solr 10.2 section of
this page on `main` are the ones that were also backported to `branch_10x`, and
SOLR-18639 has no fix version yet. If this lands on `main` only, the note
belongs in `major-changes-in-solr-11.adoc` instead.
##########
solr/core/src/java/org/apache/solr/security/AutorizationEditOperation.java:
##########
@@ -121,49 +139,64 @@ public Map<String, Object> edit(Map<String, Object>
latestConf, CommandOperation
UPDATE_PERMISSION("update-permission") {
@Override
public Map<String, Object> edit(Map<String, Object> latestConf,
CommandOperation op) {
- Integer index = op.getInt(INDEX);
+ Integer index = op.getInt(INDEX, null);
+ String id = op.getStr(ID, null);
if (op.hasError()) return null;
+ if (index == null && id == null) {
+ op.addError("Use 'index' or 'id'");
+ return null;
+ }
List<Map<String, Object>> permissions =
AutorizationEditOperation.ensureIndexOnPermissions(latestConf);
for (Map<String, Object> permission : permissions) {
- if (index.equals(getIndex(permission))) {
+ if (id == null ? index.equals(getIndex(permission)) :
id.equals(permission.get(ID))) {
+ if (index != null && !index.equals(getIndex(permission))) {
+ op.addError(ID_INDEX_MISMATCH);
+ return null;
+ }
LinkedHashMap<String, Object> copy = new LinkedHashMap<>(permission);
copy.putAll(op.getDataMap());
+ copy.remove(ID);
op.setCommandData(copy);
latestConf.put(PERMISSIONS, permissions);
return SET_PERMISSION.edit(latestConf, op);
}
}
- op.addError("No such permission " + name);
+ op.addError(id == null ? "No such permission " + name : "No such
permission id: " + id);
return null;
}
},
DELETE_PERMISSION("delete-permission") {
@Override
public Map<String, Object> edit(Map<String, Object> latestConf,
CommandOperation op) {
- Integer id = op.getInt("");
+ boolean byId = op.getCommandData() instanceof Map;
+ Object key = byId ? op.getStr(ID) : op.getInt("");
Review Comment:
Nit: `delete-permission` in object form accepts only `id`, so
`{"delete-permission": {"index": 2}}` fails with `'id' is a required field`,
while `update-permission` takes either key. Either accepting `index` here too
or stating in the ref guide that the object form is id-only would avoid the
surprise.
##########
solr/core/src/java/org/apache/solr/security/AutorizationEditOperation.java:
##########
@@ -191,14 +224,32 @@ private static List<Map<String, Object>>
ensureIndexOnPermissions(
Map<String, Object> latestConf) {
List<Map<String, Object>> permissions =
(List<Map<String, Object>>) getListValue(latestConf, PERMISSIONS);
- // see if any permissions have "index" set ...
- if (permissions.stream().noneMatch(map -> map.containsKey(INDEX))) {
- // "index" not set on the list of permissions, add it now ...
+ Set<Integer> indexes = new HashSet<>();
+ if (!permissions.stream()
+ .allMatch(map -> map.get(INDEX) instanceof Number &&
indexes.add(getIndex(map)))) {
setIndex(permissions);
}
+ ensureIds(permissions);
return permissions;
}
+ // Derived from position and content, so every node backfills the same ids
for one config.
Review Comment:
Within this PR the determinism is not observable: backfill only happens
inside an edit, and the result is persisted before any client can read an id,
so a random UUID (as `set-permission` uses below) would behave the same and let
`ensureIds` and its test shrink. If the deterministic seed is there for #4916,
where a v2 read path would need ids without an edit, it is worth saying so in
this comment so the next reader does not simplify it away.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]