Skip to content

Commit e49bacb

Browse files
committed
enhance nested field authz handling in Elasticsearch filters
1 parent 6047217 commit e49bacb

2 files changed

Lines changed: 72 additions & 7 deletions

File tree

package-lock.json

Lines changed: 46 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/server/auth/utils.js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,35 @@ export const getRequestResourceListFromFilter = async (
104104
esType,
105105
filter,
106106
filterSelf,
107-
) => textAggregation(
108-
{ esInstance, esIndex, esType },
109-
{ field: config.esConfig.authFilterField, filter, filterSelf },
110-
).then((res) => (res.map((item) => item.key)));
107+
) => {
108+
const authField = config.esConfig.authFilterField;
109+
const dotIdx = authField.lastIndexOf('.');
110+
const field = dotIdx >= 0 ? authField.slice(dotIdx + 1) : authField;
111+
const nestedPath = dotIdx >= 0 ? authField.slice(0, dotIdx) : undefined;
112+
113+
return textAggregation(
114+
{ esInstance, esIndex, esType },
115+
{ field, filter, filterSelf, nestedPath },
116+
).then((res) => res.map((item) => item.key));
117+
};
111118

112119
export const buildFilterWithResourceList = (resourceList = []) => {
113-
const filter = {
120+
const authField = config.esConfig.authFilterField;
121+
const dotIdx = authField.lastIndexOf('.');
122+
if (dotIdx >= 0) {
123+
const nestedPath = authField.slice(0, dotIdx);
124+
return {
125+
nested: {
126+
path: nestedPath,
127+
IN: {
128+
[authField]: [...resourceList],
129+
},
130+
},
131+
};
132+
}
133+
return {
114134
IN: {
115-
[config.esConfig.authFilterField]: [...resourceList],
135+
[authField]: [...resourceList],
116136
},
117137
};
118-
return filter;
119138
};

0 commit comments

Comments
 (0)