|
31 | 31 | import org.elasticsearch.xpack.core.XPackClientPlugin;
|
32 | 32 | import org.elasticsearch.xpack.core.security.authz.RoleDescriptor.ApplicationResourcePrivileges;
|
33 | 33 | import org.elasticsearch.xpack.core.security.authz.permission.FieldPermissionsCache;
|
| 34 | +import org.elasticsearch.xpack.core.security.authz.permission.RemoteClusterPermissionGroup; |
34 | 35 | import org.elasticsearch.xpack.core.security.authz.permission.RemoteClusterPermissions;
|
35 | 36 | import org.elasticsearch.xpack.core.security.authz.privilege.ConfigurableClusterPrivilege;
|
36 | 37 | import org.elasticsearch.xpack.core.security.authz.privilege.ConfigurableClusterPrivileges;
|
| 38 | +import org.elasticsearch.xpack.core.security.authz.restriction.Workflow; |
| 39 | +import org.elasticsearch.xpack.core.security.authz.restriction.WorkflowResolver; |
37 | 40 | import org.hamcrest.Matchers;
|
38 | 41 |
|
39 | 42 | import java.io.IOException;
|
|
46 | 49 |
|
47 | 50 | import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;
|
48 | 51 | import static org.elasticsearch.xpack.core.security.authz.RoleDescriptor.WORKFLOWS_RESTRICTION_VERSION;
|
49 |
| -import static org.elasticsearch.xpack.core.security.authz.RoleDescriptorTestHelper.randomIndicesPrivileges; |
50 | 52 | import static org.elasticsearch.xpack.core.security.authz.RoleDescriptorTestHelper.randomIndicesPrivilegesBuilder;
|
51 | 53 | import static org.elasticsearch.xpack.core.security.authz.RoleDescriptorTestHelper.randomRemoteClusterPermissions;
|
52 | 54 | import static org.hamcrest.Matchers.arrayContaining;
|
@@ -1312,37 +1314,191 @@ public void testIsEmpty() {
|
1312 | 1314 | }
|
1313 | 1315 | }
|
1314 | 1316 |
|
1315 |
| - public void testHasPrivilegesOtherThanIndex() { |
| 1317 | + public void testHasUnsupportedPrivilegesInsideAPIKeyConnectedRemoteCluster() { |
| 1318 | + // any index and some cluster privileges are allowed |
1316 | 1319 | assertThat(
|
1317 | 1320 | new RoleDescriptor(
|
1318 | 1321 | "name",
|
| 1322 | + RemoteClusterPermissions.getSupportedRemoteClusterPermissions().toArray(new String[0]), // all of these are allowed |
| 1323 | + new RoleDescriptor.IndicesPrivileges[] { |
| 1324 | + RoleDescriptor.IndicesPrivileges.builder().indices("idx").privileges("foo").build() }, |
| 1325 | + null, |
| 1326 | + null, |
| 1327 | + null, |
| 1328 | + null, |
| 1329 | + null, |
| 1330 | + null, |
| 1331 | + null, |
| 1332 | + null, |
| 1333 | + null |
| 1334 | + ).hasUnsupportedPrivilegesInsideAPIKeyConnectedRemoteCluster(), |
| 1335 | + is(false) |
| 1336 | + ); |
| 1337 | + // any index and some cluster privileges are allowed |
| 1338 | + assertThat( |
| 1339 | + new RoleDescriptor( |
| 1340 | + "name", |
| 1341 | + new String[] { "manage_security" }, // unlikely we will ever support allowing manage security across clusters |
| 1342 | + new RoleDescriptor.IndicesPrivileges[] { |
| 1343 | + RoleDescriptor.IndicesPrivileges.builder().indices("idx").privileges("foo").build() }, |
| 1344 | + null, |
| 1345 | + null, |
| 1346 | + null, |
| 1347 | + null, |
| 1348 | + null, |
| 1349 | + null, |
| 1350 | + null, |
| 1351 | + null, |
| 1352 | + null |
| 1353 | + ).hasUnsupportedPrivilegesInsideAPIKeyConnectedRemoteCluster(), |
| 1354 | + is(true) |
| 1355 | + ); |
| 1356 | + |
| 1357 | + // application privileges are not allowed |
| 1358 | + assertThat( |
| 1359 | + new RoleDescriptor( |
| 1360 | + "name", |
| 1361 | + RemoteClusterPermissions.getSupportedRemoteClusterPermissions().toArray(new String[0]), |
| 1362 | + new RoleDescriptor.IndicesPrivileges[] { |
| 1363 | + RoleDescriptor.IndicesPrivileges.builder().indices("idx").privileges("foo").build() }, |
| 1364 | + new ApplicationResourcePrivileges[] { |
| 1365 | + ApplicationResourcePrivileges.builder().application("app").privileges("foo").resources("res").build() }, |
| 1366 | + null, |
| 1367 | + null, |
| 1368 | + null, |
| 1369 | + null, |
| 1370 | + null, |
| 1371 | + null, |
| 1372 | + null, |
| 1373 | + null |
| 1374 | + ).hasUnsupportedPrivilegesInsideAPIKeyConnectedRemoteCluster(), |
| 1375 | + is(true) |
| 1376 | + ); |
| 1377 | + |
| 1378 | + // configurable cluster privileges are not allowed |
| 1379 | + assertThat( |
| 1380 | + new RoleDescriptor( |
| 1381 | + "name", |
| 1382 | + RemoteClusterPermissions.getSupportedRemoteClusterPermissions().toArray(new String[0]), |
| 1383 | + new RoleDescriptor.IndicesPrivileges[] { |
| 1384 | + RoleDescriptor.IndicesPrivileges.builder().indices("idx").privileges("foo").build() }, |
| 1385 | + null, |
| 1386 | + new ConfigurableClusterPrivilege[] { |
| 1387 | + new ConfigurableClusterPrivileges.ManageApplicationPrivileges(Collections.singleton("foo")) }, |
| 1388 | + null, |
| 1389 | + null, |
| 1390 | + null, |
| 1391 | + null, |
| 1392 | + null, |
| 1393 | + null, |
| 1394 | + null |
| 1395 | + ).hasUnsupportedPrivilegesInsideAPIKeyConnectedRemoteCluster(), |
| 1396 | + is(true) |
| 1397 | + ); |
| 1398 | + |
| 1399 | + // run as is not allowed |
| 1400 | + assertThat( |
| 1401 | + new RoleDescriptor( |
| 1402 | + "name", |
| 1403 | + RemoteClusterPermissions.getSupportedRemoteClusterPermissions().toArray(new String[0]), |
| 1404 | + new RoleDescriptor.IndicesPrivileges[] { |
| 1405 | + RoleDescriptor.IndicesPrivileges.builder().indices("idx").privileges("foo").build() }, |
| 1406 | + null, |
| 1407 | + null, |
| 1408 | + new String[] { "foo" }, |
| 1409 | + null, |
| 1410 | + null, |
| 1411 | + null, |
| 1412 | + null, |
| 1413 | + null, |
| 1414 | + null |
| 1415 | + ).hasUnsupportedPrivilegesInsideAPIKeyConnectedRemoteCluster(), |
| 1416 | + is(true) |
| 1417 | + ); |
| 1418 | + |
| 1419 | + // workflows restriction is not allowed |
| 1420 | + assertThat( |
| 1421 | + new RoleDescriptor( |
| 1422 | + "name", |
| 1423 | + RemoteClusterPermissions.getSupportedRemoteClusterPermissions().toArray(new String[0]), |
| 1424 | + new RoleDescriptor.IndicesPrivileges[] { |
| 1425 | + RoleDescriptor.IndicesPrivileges.builder().indices("idx").privileges("foo").build() }, |
1319 | 1426 | null,
|
1320 |
| - randomBoolean() ? null : randomIndicesPrivileges(1, 5), |
1321 | 1427 | null,
|
1322 | 1428 | null,
|
1323 | 1429 | null,
|
1324 | 1430 | null,
|
1325 | 1431 | null,
|
1326 | 1432 | null,
|
| 1433 | + new RoleDescriptor.Restriction(WorkflowResolver.allWorkflows().stream().map(Workflow::name).toArray(String[]::new)), |
| 1434 | + null |
| 1435 | + ).hasUnsupportedPrivilegesInsideAPIKeyConnectedRemoteCluster(), |
| 1436 | + is(true) |
| 1437 | + ); |
| 1438 | + // remote indices privileges are not allowed |
| 1439 | + assertThat( |
| 1440 | + new RoleDescriptor( |
| 1441 | + "name", |
| 1442 | + RemoteClusterPermissions.getSupportedRemoteClusterPermissions().toArray(new String[0]), |
| 1443 | + new RoleDescriptor.IndicesPrivileges[] { |
| 1444 | + RoleDescriptor.IndicesPrivileges.builder().indices("idx").privileges("foo").build() }, |
| 1445 | + null, |
| 1446 | + null, |
| 1447 | + null, |
| 1448 | + null, |
| 1449 | + null, |
| 1450 | + new RoleDescriptor.RemoteIndicesPrivileges[] { |
| 1451 | + RoleDescriptor.RemoteIndicesPrivileges.builder("rmt").indices("idx").privileges("foo").build() }, |
1327 | 1452 | null,
|
1328 | 1453 | null,
|
1329 | 1454 | null
|
1330 | 1455 | ).hasUnsupportedPrivilegesInsideAPIKeyConnectedRemoteCluster(),
|
| 1456 | + is(true) |
| 1457 | + ); |
| 1458 | + // remote cluster privileges are not allowed |
| 1459 | + assertThat( |
| 1460 | + new RoleDescriptor( |
| 1461 | + "name", |
| 1462 | + RemoteClusterPermissions.getSupportedRemoteClusterPermissions().toArray(new String[0]), |
| 1463 | + new RoleDescriptor.IndicesPrivileges[] { |
| 1464 | + RoleDescriptor.IndicesPrivileges.builder().indices("idx").privileges("foo").build() }, |
| 1465 | + null, |
| 1466 | + null, |
| 1467 | + null, |
| 1468 | + null, |
| 1469 | + null, |
| 1470 | + null, |
| 1471 | + new RemoteClusterPermissions().addGroup( |
| 1472 | + new RemoteClusterPermissionGroup( |
| 1473 | + RemoteClusterPermissions.getSupportedRemoteClusterPermissions().toArray(new String[0]), |
| 1474 | + new String[] { "rmt" } |
| 1475 | + ) |
| 1476 | + ), |
| 1477 | + null, |
| 1478 | + null |
| 1479 | + ).hasUnsupportedPrivilegesInsideAPIKeyConnectedRemoteCluster(), |
| 1480 | + is(true) |
| 1481 | + ); |
| 1482 | + |
| 1483 | + // metadata, transient metadata and description are allowed |
| 1484 | + assertThat( |
| 1485 | + new RoleDescriptor( |
| 1486 | + "name", |
| 1487 | + RemoteClusterPermissions.getSupportedRemoteClusterPermissions().toArray(new String[0]), |
| 1488 | + new RoleDescriptor.IndicesPrivileges[] { |
| 1489 | + RoleDescriptor.IndicesPrivileges.builder().indices("idx").privileges("foo").build() }, |
| 1490 | + null, |
| 1491 | + null, |
| 1492 | + null, |
| 1493 | + Collections.singletonMap("foo", "bar"), |
| 1494 | + Collections.singletonMap("foo", "bar"), |
| 1495 | + null, |
| 1496 | + null, |
| 1497 | + null, |
| 1498 | + "description" |
| 1499 | + ).hasUnsupportedPrivilegesInsideAPIKeyConnectedRemoteCluster(), |
1331 | 1500 | is(false)
|
1332 | 1501 | );
|
1333 |
| - final RoleDescriptor roleDescriptor = RoleDescriptorTestHelper.builder() |
1334 |
| - .allowReservedMetadata(true) |
1335 |
| - .allowRemoteIndices(true) |
1336 |
| - .allowRestriction(true) |
1337 |
| - .allowDescription(true) |
1338 |
| - .allowRemoteClusters(true) |
1339 |
| - .build(); |
1340 |
| - final boolean expected = roleDescriptor.hasClusterPrivileges() |
1341 |
| - || roleDescriptor.hasConfigurableClusterPrivileges() |
1342 |
| - || roleDescriptor.hasApplicationPrivileges() |
1343 |
| - || roleDescriptor.hasRunAs() |
1344 |
| - || roleDescriptor.hasRemoteIndicesPrivileges(); |
1345 |
| - assertThat(roleDescriptor.hasUnsupportedPrivilegesInsideAPIKeyConnectedRemoteCluster(), equalTo(expected)); |
1346 | 1502 | }
|
1347 | 1503 |
|
1348 | 1504 | private static void resetFieldPermssionsCache() {
|
|
0 commit comments