Skip to content

Commit 0fb300f

Browse files
opensearch-trigger-bot[bot]github-actions[bot]cwperks
authored
[Backport 3.0] Corrections in DlsFlsFilterLeafReader regarding PointVales and object valued attributes (#5304)
Signed-off-by: Nils Bandener <[email protected]> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Craig Perkins <[email protected]>
1 parent 1f9f098 commit 0fb300f

File tree

10 files changed

+717
-360
lines changed

10 files changed

+717
-360
lines changed

src/integrationTest/java/org/opensearch/security/privileges/dlsfls/FieldPrivilegesTest.java

+73-35
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ public void indexPattern_simple_inclusive() throws Exception {
5959
FieldPrivileges subject = createSubject(roleConfig);
6060

6161
FieldPrivileges.FlsRule rule = subject.getRestriction(ctx("fls_role_1"), "index_a1");
62-
assertTrue("included_field_a should be allowed", rule.isAllowed("included_field_a"));
63-
assertFalse("Fields other than included_field_a should be not allowed", rule.isAllowed("other_field"));
62+
assertTrue("included_field_a should be allowed", rule.isAllowedAssumingParentsAreAllowed("included_field_a"));
63+
assertFalse("Fields other than included_field_a should be not allowed", rule.isAllowedAssumingParentsAreAllowed("other_field"));
6464
}
6565

6666
@Test
@@ -72,8 +72,8 @@ public void indexPattern_simple_exclusive() throws Exception {
7272
FieldPrivileges subject = createSubject(roleConfig);
7373

7474
FieldPrivileges.FlsRule rule = subject.getRestriction(ctx("fls_role_1"), "index_a1");
75-
assertFalse("excluded_field_a should be not allowed", rule.isAllowed("excluded_field_a"));
76-
assertTrue("Fields other than included_field_a should be allowed", rule.isAllowed("other_field"));
75+
assertFalse("excluded_field_a should be not allowed", rule.isAllowedAssumingParentsAreAllowed("excluded_field_a"));
76+
assertTrue("Fields other than included_field_a should be allowed", rule.isAllowedAssumingParentsAreAllowed("other_field"));
7777
}
7878

7979
@Test
@@ -86,11 +86,11 @@ public void indexPattern_joined_inclusive() throws Exception {
8686
FieldPrivileges subject = createSubject(roleConfig);
8787

8888
FieldPrivileges.FlsRule rule = subject.getRestriction(ctx("fls_role_1", "fls_role_2"), "index_a1");
89-
assertTrue("included_field_a should be allowed", rule.isAllowed("included_field_a"));
90-
assertTrue("included_field_a1_foo should be allowed", rule.isAllowed("included_field_a1_foo"));
89+
assertTrue("included_field_a should be allowed", rule.isAllowedAssumingParentsAreAllowed("included_field_a"));
90+
assertTrue("included_field_a1_foo should be allowed", rule.isAllowedAssumingParentsAreAllowed("included_field_a1_foo"));
9191
assertFalse(
9292
"Fields other than included_field_a and included_field_a1_foo should be not allowed",
93-
rule.isAllowed("other_field")
93+
rule.isAllowedAssumingParentsAreAllowed("other_field")
9494
);
9595
}
9696

@@ -104,9 +104,12 @@ public void indexPattern_joined_exclusive() throws Exception {
104104
FieldPrivileges subject = createSubject(roleConfig);
105105

106106
FieldPrivileges.FlsRule rule = subject.getRestriction(ctx("fls_role_1", "fls_role_2"), "index_a1");
107-
assertFalse("excluded_field_a should be not allowed", rule.isAllowed("excluded_field_a"));
108-
assertFalse("excluded_field_a1_foo should be not allowed", rule.isAllowed("excluded_field_a1_foo"));
109-
assertTrue("Fields other than included_field_a and included_field_a1_foo should be allowed", rule.isAllowed("other_field"));
107+
assertFalse("excluded_field_a should be not allowed", rule.isAllowedAssumingParentsAreAllowed("excluded_field_a"));
108+
assertFalse("excluded_field_a1_foo should be not allowed", rule.isAllowedAssumingParentsAreAllowed("excluded_field_a1_foo"));
109+
assertTrue(
110+
"Fields other than included_field_a and included_field_a1_foo should be allowed",
111+
rule.isAllowedAssumingParentsAreAllowed("other_field")
112+
);
110113
}
111114

112115
@Test
@@ -119,8 +122,8 @@ public void indexPattern_unrestricted_inclusive() throws Exception {
119122
FieldPrivileges subject = createSubject(roleConfig);
120123

121124
FieldPrivileges.FlsRule rule = subject.getRestriction(ctx("fls_role_1", "non_fls_role"), "index_a1");
122-
assertTrue("included_field_a should be allowed", rule.isAllowed("included_field_a"));
123-
assertTrue("other_field should be allowed", rule.isAllowed("other_field"));
125+
assertTrue("included_field_a should be allowed", rule.isAllowedAssumingParentsAreAllowed("included_field_a"));
126+
assertTrue("other_field should be allowed", rule.isAllowedAssumingParentsAreAllowed("other_field"));
124127
}
125128

126129
@Test
@@ -133,8 +136,8 @@ public void indexPattern_unrestricted_exclusive() throws Exception {
133136
FieldPrivileges subject = createSubject(roleConfig);
134137

135138
FieldPrivileges.FlsRule rule = subject.getRestriction(ctx("fls_role_1", "non_fls_role"), "index_a1");
136-
assertTrue("excluded_field_a should be allowed", rule.isAllowed("excluded_field_a"));
137-
assertTrue("other_field should be allowed", rule.isAllowed("other_field"));
139+
assertTrue("excluded_field_a should be allowed", rule.isAllowedAssumingParentsAreAllowed("excluded_field_a"));
140+
assertTrue("other_field should be allowed", rule.isAllowedAssumingParentsAreAllowed("other_field"));
138141
}
139142

140143
static SecurityDynamicConfiguration<RoleV7> roleConfig(TestSecurityConfig.Role... roles) {
@@ -168,8 +171,13 @@ public static class FlsRule {
168171
public void simple_inclusive() throws Exception {
169172
FieldPrivileges.FlsRule flsRule = FieldPrivileges.FlsRule.of("field_inclusive");
170173
assertFalse("FLS rule field_inclusive should be restricted", flsRule.isUnrestricted());
171-
assertTrue("field_inclusive is allowed", flsRule.isAllowed("field_inclusive"));
172-
assertFalse("other_field is not allowed", flsRule.isAllowed("other_field"));
174+
175+
assertTrue("field_inclusive is allowed", flsRule.isAllowedAssumingParentsAreAllowed("field_inclusive"));
176+
assertTrue("field_inclusive is allowed", flsRule.isAllowedRecursive("field_inclusive"));
177+
178+
assertFalse("other_field is not allowed", flsRule.isAllowedAssumingParentsAreAllowed("other_field"));
179+
assertFalse("other_field is not allowed", flsRule.isAllowedRecursive("other_field"));
180+
173181
assertEquals("FLS:[field_inclusive]", flsRule.toString());
174182
assertEquals(Arrays.asList("field_inclusive"), flsRule.getSource());
175183
}
@@ -178,26 +186,40 @@ public void simple_inclusive() throws Exception {
178186
public void simple_exclusive() throws Exception {
179187
FieldPrivileges.FlsRule flsRule = FieldPrivileges.FlsRule.of("~field_exclusive");
180188
assertFalse("FLS rule field_exclusive should be restricted", flsRule.isUnrestricted());
181-
assertFalse("field_exclusive is not allowed", flsRule.isAllowed("field_exclusive"));
182-
assertTrue("other_field is allowed", flsRule.isAllowed("other_field"));
189+
190+
assertFalse("field_exclusive is not allowed", flsRule.isAllowedAssumingParentsAreAllowed("field_exclusive"));
191+
assertFalse("field_exclusive is not allowed", flsRule.isAllowedRecursive("field_exclusive"));
192+
193+
assertTrue("other_field is allowed", flsRule.isAllowedAssumingParentsAreAllowed("other_field"));
194+
assertTrue("other_field is allowed", flsRule.isAllowedRecursive("other_field"));
183195
}
184196

185197
@Test
186198
public void multi_inclusive() throws Exception {
187199
FieldPrivileges.FlsRule flsRule = FieldPrivileges.FlsRule.of("field_inclusive_1", "field_inclusive_2");
188200
assertFalse("FLS rule should be restricted", flsRule.isUnrestricted());
189-
assertTrue("field_inclusive_1 is allowed", flsRule.isAllowed("field_inclusive_1"));
190-
assertTrue("field_inclusive_2 is allowed", flsRule.isAllowed("field_inclusive_2"));
191-
assertFalse("other_field is not allowed", flsRule.isAllowed("other_field"));
201+
202+
assertTrue("field_inclusive_1 is allowed", flsRule.isAllowedAssumingParentsAreAllowed("field_inclusive_1"));
203+
assertTrue("field_inclusive_2 is allowed", flsRule.isAllowedAssumingParentsAreAllowed("field_inclusive_2"));
204+
assertTrue("field_inclusive_1 is allowed", flsRule.isAllowedRecursive("field_inclusive_1"));
205+
assertTrue("field_inclusive_2 is allowed", flsRule.isAllowedRecursive("field_inclusive_2"));
206+
207+
assertFalse("other_field is not allowed", flsRule.isAllowedAssumingParentsAreAllowed("other_field"));
208+
assertFalse("other_field is not allowed", flsRule.isAllowedRecursive("other_field"));
192209
}
193210

194211
@Test
195212
public void multi_exclusive() throws Exception {
196213
FieldPrivileges.FlsRule flsRule = FieldPrivileges.FlsRule.of("~field_exclusive_1", "~field_exclusive_2");
197214
assertFalse("FLS rule should be restricted", flsRule.isUnrestricted());
198-
assertFalse("field_exclusive_1 is not allowed", flsRule.isAllowed("field_exclusive_1"));
199-
assertFalse("field_exclusive_1 is not allowed", flsRule.isAllowed("field_exclusive_2"));
200-
assertTrue("other_field is allowed", flsRule.isAllowed("other_field"));
215+
216+
assertFalse("field_exclusive_1 is not allowed", flsRule.isAllowedAssumingParentsAreAllowed("field_exclusive_1"));
217+
assertFalse("field_exclusive_2 is not allowed", flsRule.isAllowedAssumingParentsAreAllowed("field_exclusive_2"));
218+
assertFalse("field_exclusive_1 is not allowed", flsRule.isAllowedRecursive("field_exclusive_1"));
219+
assertFalse("field_exclusive_2 is not allowed", flsRule.isAllowedRecursive("field_exclusive_2"));
220+
221+
assertTrue("other_field is allowed", flsRule.isAllowedAssumingParentsAreAllowed("other_field"));
222+
assertTrue("other_field is allowed", flsRule.isAllowedRecursive("other_field"));
201223
}
202224

203225
@Test
@@ -207,35 +229,51 @@ public void multi_mixed() throws Exception {
207229
// The behavior is undocumented - if there are exclusions and inclusions, only exclusions are regarded.
208230
// It might make sense to re-think this behavior.
209231
assertFalse("FLS rule should be restricted", flsRule.isUnrestricted());
210-
assertFalse("field_exclusive_1 is not allowed", flsRule.isAllowed("field_exclusive_1"));
211-
assertTrue("other_field is allowed", flsRule.isAllowed("other_field"));
232+
assertFalse("field_exclusive_1 is not allowed", flsRule.isAllowedAssumingParentsAreAllowed("field_exclusive_1"));
233+
assertTrue("other_field is allowed", flsRule.isAllowedAssumingParentsAreAllowed("other_field"));
212234
}
213235

214236
@Test
215237
public void nested_inclusive() throws Exception {
216238
FieldPrivileges.FlsRule flsRule = FieldPrivileges.FlsRule.of("a.b.c");
217239
assertFalse("FLS rule should be restricted", flsRule.isUnrestricted());
218-
assertTrue("a.b.c is allowed", flsRule.isAllowed("a.b.c"));
219-
assertFalse("a.b is not allowed for non-objects", flsRule.isAllowed("a.b"));
220-
assertTrue("a.b is not allowed for objects", flsRule.isObjectAllowed("a.b"));
221-
assertFalse("other_field is not allowed", flsRule.isAllowed("other_field"));
222-
assertFalse("a.b.other_field is not allowed", flsRule.isAllowed("a.b.other_field"));
240+
241+
assertTrue("a.b.c is allowed", flsRule.isAllowedAssumingParentsAreAllowed("a.b.c"));
242+
assertTrue("a.b.c is allowed", flsRule.isAllowedRecursive("a.b.c"));
243+
244+
assertFalse("a.b is not allowed for non-objects", flsRule.isAllowedAssumingParentsAreAllowed("a.b"));
245+
assertTrue("a.b is not allowed for objects", flsRule.isObjectAllowedAssumingParentsAreAllowed("a.b"));
246+
assertFalse("a.b is not allowed recursively", flsRule.isAllowedRecursive("a.b"));
247+
248+
assertFalse("other_field is not allowed", flsRule.isAllowedAssumingParentsAreAllowed("other_field"));
249+
assertFalse("other_field is not allowed", flsRule.isAllowedRecursive("other_field"));
250+
251+
assertFalse("a.b.other_field is not allowed", flsRule.isAllowedAssumingParentsAreAllowed("a.b.other_field"));
252+
assertFalse("a.b.other_field is not allowed", flsRule.isAllowedRecursive("a.b.other_field"));
253+
254+
assertTrue("a.b.c.d is allowed", flsRule.isAllowedRecursive("a.b.c.d"));
223255
}
224256

225257
@Test
226258
public void nested_exclusive() throws Exception {
227259
FieldPrivileges.FlsRule flsRule = FieldPrivileges.FlsRule.of("~a.b.c");
228260
assertFalse("FLS rule should be restricted", flsRule.isUnrestricted());
229-
assertFalse("a.b.c is not allowed", flsRule.isAllowed("a.b.c"));
230-
assertTrue("a.b is allowed", flsRule.isAllowed("a.b"));
231-
assertTrue("a.b is allowed for objects", flsRule.isObjectAllowed("a.b"));
261+
262+
assertFalse("a.b.c is not allowed", flsRule.isAllowedAssumingParentsAreAllowed("a.b.c"));
263+
assertFalse("a.b.c is not allowed", flsRule.isAllowedRecursive("a.b.c"));
264+
265+
assertTrue("a.b is allowed", flsRule.isAllowedAssumingParentsAreAllowed("a.b"));
266+
assertTrue("a.b is allowed for objects", flsRule.isObjectAllowedAssumingParentsAreAllowed("a.b"));
267+
assertTrue("a.b is allowed recursively", flsRule.isAllowedAssumingParentsAreAllowed("a.b"));
268+
269+
assertFalse("a.b.c.d is not allowed", flsRule.isAllowedRecursive("a.b.c.d"));
232270
}
233271

234272
@Test
235273
public void wildcard_inclusive() throws Exception {
236274
FieldPrivileges.FlsRule flsRule = FieldPrivileges.FlsRule.of("*");
237275
assertTrue("FLS rule * is unrestricted", flsRule.isUnrestricted());
238-
assertTrue("anything is allowed", flsRule.isAllowed("anything"));
276+
assertTrue("anything is allowed", flsRule.isAllowedAssumingParentsAreAllowed("anything"));
239277
assertEquals("FLS:*", flsRule.toString());
240278
}
241279

0 commit comments

Comments
 (0)