-
Notifications
You must be signed in to change notification settings - Fork 393
Workspace aware sharing records #6374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DarshitChanpura
wants to merge
29
commits into
opensearch-project:main
Choose a base branch
from
DarshitChanpura:workspace-aware-sharing-records
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 18 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
3f53268
Make resource sharing records workspace-aware (spike)
DarshitChanpura e3467f3
Inherit resource access from workspaces on the write path
DarshitChanpura 4672922
Guard workspace access inheritance against container cycles
DarshitChanpura 00bd5d8
Drop version guard on workspaces serialization
DarshitChanpura 76670dd
Batch workspace lookups on the access-check hot path
DarshitChanpura 7412d76
Backfill workspace membership during migration
DarshitChanpura d71f36d
Merge remote-tracking branch 'upstream/main' into workspace-aware-sha…
DarshitChanpura bcc3024
Address Code-Diff-Analyzer findings on workspace sharing
DarshitChanpura 0a7486f
Merge remote-tracking branch 'upstream/main' into workspace-aware-sha…
DarshitChanpura 5333eba
Make ResourceSharing round-trip over the transport wire
DarshitChanpura 19af1df
Backfill workspaces onto already-migrated sharing records
DarshitChanpura 3115d4c
Integration-test workspace backfill during migration
DarshitChanpura 48ccf99
Integration-test workspace-aware live indexing
DarshitChanpura 533c69a
Add SPI seam for trusted workspace-membership resolution
DarshitChanpura 31fde47
Unit-test workspace index-handler + extraction paths
DarshitChanpura 114fdc4
Filter workspace visibility on the resource workspaces field
DarshitChanpura 8db592c
Merge remote-tracking branch 'upstream/main' into workspace-aware-sha…
DarshitChanpura a1dc646
Filter DLS on the provider-declared workspaces field
DarshitChanpura e2f4225
Simplify workspace access checks; address review nits
DarshitChanpura d86d9c6
Make workspace-sharing comments crisp and self-contained
DarshitChanpura 725dfb3
Keep sharing records in sync with resource workspaces
DarshitChanpura 361ec6b
Register workspace container type in sample plugin
DarshitChanpura 1577069
Expect workspace as a shareable type in sample types API
DarshitChanpura e82c018
Make workspace reconciliation monotonic and workspace field trusted
DarshitChanpura eca8bdf
Merge remote-tracking branch 'upstream/main' into workspace-aware-sha…
DarshitChanpura 7c5cf51
Make workspaces guard durable across record rewrites
DarshitChanpura 81f704c
Guard concurrent share/patch against reconcile clobber
DarshitChanpura 8f62005
Restore context on fetch failure; preserve parse cause; strengthen CA…
DarshitChanpura 649432f
Tighten workspace javadoc and inline comments
DarshitChanpura File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -180,7 +180,7 @@ public void testMigrateAPIWithRestAdmin_valid() { | |
| migrateResponse.assertStatusCode(HttpStatus.SC_OK); | ||
| assertThat( | ||
| migrateResponse.bodyAsMap().get("summary"), | ||
| equalTo("Migration complete. migrated 2; skippedNoType 0; skippedExisting 0; failed 0") | ||
| equalTo("Migration complete. migrated 2; backfilledExisting 0; skippedNoType 0; skippedExisting 0; failed 0") | ||
| ); | ||
| assertThat(migrateResponse.bodyAsMap().get("resourcesWithDefaultOwner"), equalTo(List.of(resourceIdNoUser))); | ||
| } | ||
|
|
@@ -215,7 +215,7 @@ public void testMigrateAPIWithSuperAdmin_valid() { | |
| migrateResponse.assertStatusCode(HttpStatus.SC_OK); | ||
| assertThat( | ||
| migrateResponse.bodyAsMap().get("summary"), | ||
| equalTo("Migration complete. migrated 2; skippedNoType 0; skippedExisting 0; failed 0") | ||
| equalTo("Migration complete. migrated 2; backfilledExisting 0; skippedNoType 0; skippedExisting 0; failed 0") | ||
| ); | ||
| assertThat(migrateResponse.bodyAsMap().get("resourcesWithDefaultOwner"), equalTo(List.of(resourceIdNoUser))); | ||
|
|
||
|
|
@@ -247,7 +247,7 @@ public void testMigrateTwice_shouldSkipSecondTime() { | |
| migrateResponse.assertStatusCode(HttpStatus.SC_OK); | ||
| assertThat( | ||
| migrateResponse.bodyAsMap().get("summary"), | ||
| equalTo("Migration complete. migrated 2; skippedNoType 0; skippedExisting 0; failed 0") | ||
| equalTo("Migration complete. migrated 2; backfilledExisting 0; skippedNoType 0; skippedExisting 0; failed 0") | ||
| ); | ||
| assertThat(migrateResponse.bodyAsMap().get("resourcesWithDefaultOwner"), equalTo(List.of(resourceIdNoUser))); | ||
|
|
||
|
|
@@ -273,7 +273,7 @@ public void testMigrateTwice_shouldSkipSecondTime() { | |
| migrateResponse.assertStatusCode(HttpStatus.SC_OK); | ||
| assertThat( | ||
| migrateResponse.bodyAsMap().get("summary"), | ||
| equalTo("Migration complete. migrated 0; skippedNoType 0; skippedExisting 2; failed 0") | ||
| equalTo("Migration complete. migrated 0; backfilledExisting 0; skippedNoType 0; skippedExisting 2; failed 0") | ||
| ); | ||
| assertThat(migrateResponse.bodyAsMap().get("resourcesWithDefaultOwner"), equalTo(List.of(resourceIdNoUser))); | ||
|
|
||
|
|
@@ -294,6 +294,91 @@ public void testMigrateTwice_shouldSkipSecondTime() { | |
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testLiveIndexingStampsWorkspacesOnSharingRecord() { | ||
| // Steady-state: creating a resource with a workspaces field must trigger ResourceIndexListener to | ||
| // extract the (multi-valued) workspaces from the parsed doc via extractMultiValuedFieldFromIndexOp and | ||
| // store them on the sharing record (used by the write-path access-level fan-out). Workspace membership is | ||
| // NOT projected into all_shared_principals; read-path visibility filters the resource's own `workspaces` | ||
| // field in DLS. Also confirms the Lucene getFields() materialization works for the sample plugin's mapping. | ||
| String resourceId = createSampleResourceWithWorkspaces("ws-a", "ws-b"); | ||
|
|
||
| try (TestRestClient client = cluster.getRestClient(cluster.getAdminCertificate())) { | ||
| // The sharing record carries the workspaces field (for the write-path fan-out). | ||
| TestRestClient.HttpResponse sharingDoc = client.get(RESOURCE_SHARING_INDEX + "/_doc/" + resourceId); | ||
| sharingDoc.assertStatusCode(HttpStatus.SC_OK); | ||
| ArrayNode ws = (ArrayNode) sharingDoc.bodyAsJsonNode().get("_source").get("workspaces"); | ||
| List<String> workspaceIds = new ArrayList<>(); | ||
| ws.forEach(n -> workspaceIds.add(n.asString())); | ||
| assertThat(workspaceIds, containsInAnyOrder("ws-a", "ws-b")); | ||
|
|
||
| // all_shared_principals stays usernames/roles only -- no workspace:<id> denormalization. | ||
| TestRestClient.HttpResponse resourceDoc = client.get(RESOURCE_INDEX_NAME + "/_doc/" + resourceId); | ||
| resourceDoc.assertStatusCode(HttpStatus.SC_OK); | ||
| ArrayNode principals = (ArrayNode) resourceDoc.bodyAsJsonNode().get("_source").get("all_shared_principals"); | ||
| List<String> principalList = new ArrayList<>(); | ||
| principals.forEach(n -> principalList.add(n.asString())); | ||
| assertThat(principalList, containsInAnyOrder("user:" + MIGRATION_USER.getName())); | ||
|
|
||
| // The resource doc keeps its own `workspaces` field -- this is what DLS filters on for read visibility. | ||
| ArrayNode docWs = (ArrayNode) resourceDoc.bodyAsJsonNode().get("_source").get("workspaces"); | ||
| List<String> docWorkspaceIds = new ArrayList<>(); | ||
| docWs.forEach(n -> docWorkspaceIds.add(n.asString())); | ||
| assertThat(docWorkspaceIds, containsInAnyOrder("ws-a", "ws-b")); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testMigrateBackfillsWorkspacesOntoExistingRecord() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I'm reading this correctly, the migrate API can now be called multiple times? One from a version before this PR and one afterwards to get the workspace info? |
||
| // A resource whose sharing record already exists (created at resource-creation time) but which has | ||
| // since gained workspace membership on its source doc. Migration should not re-create the record; it | ||
| // should backfill the workspaces field and refresh all_shared_principals. | ||
| String resourceId = createSampleResource(); | ||
|
|
||
| try (TestRestClient client = cluster.getRestClient(cluster.getAdminCertificate())) { | ||
| // Add workspace membership to the resource's source doc (an _update, so no new sharing record is | ||
| // created). The existing sharing record stays workspace-blind until migration backfills it. | ||
| TestRestClient.HttpResponse update = client.postJson( | ||
| RESOURCE_INDEX_NAME + "/_update/" + resourceId + "?refresh=true", | ||
| "{ \"doc\": { \"workspaces\": [\"ws-a\", \"ws-b\"] } }" | ||
| ); | ||
| update.assertStatusCode(HttpStatus.SC_OK); | ||
|
|
||
| // Migrate without clearing: the record exists, so create is skipped; the source doc now has | ||
| // workspaces, so it is backfilled rather than skipped. | ||
| TestRestClient.HttpResponse migrateResponse = client.postJson(RESOURCE_SHARING_MIGRATION_ENDPOINT, migrationPayload_valid()); | ||
| migrateResponse.assertStatusCode(HttpStatus.SC_OK); | ||
| assertThat( | ||
| migrateResponse.bodyAsMap().get("summary"), | ||
| equalTo("Migration complete. migrated 0; backfilledExisting 1; skippedNoType 0; skippedExisting 0; failed 0") | ||
| ); | ||
|
|
||
| // The sharing record now carries the workspaces field. | ||
| TestRestClient.HttpResponse sharingDoc = client.get(RESOURCE_SHARING_INDEX + "/_doc/" + resourceId); | ||
| sharingDoc.assertStatusCode(HttpStatus.SC_OK); | ||
| ArrayNode ws = (ArrayNode) sharingDoc.bodyAsJsonNode().get("_source").get("workspaces"); | ||
| List<String> workspaceIds = new ArrayList<>(); | ||
| ws.forEach(n -> workspaceIds.add(n.asString())); | ||
| assertThat(workspaceIds, containsInAnyOrder("ws-a", "ws-b")); | ||
|
|
||
| // all_shared_principals stays usernames/roles only -- workspace membership is not denormalized here. | ||
| TestRestClient.HttpResponse resourceDoc = client.get(RESOURCE_INDEX_NAME + "/_doc/" + resourceId); | ||
| resourceDoc.assertStatusCode(HttpStatus.SC_OK); | ||
| ArrayNode principals = (ArrayNode) resourceDoc.bodyAsJsonNode().get("_source").get("all_shared_principals"); | ||
| List<String> principalList = new ArrayList<>(); | ||
| principals.forEach(n -> principalList.add(n.asString())); | ||
| assertThat(principalList, containsInAnyOrder("user:" + MIGRATION_USER.getName())); | ||
|
|
||
| // Idempotency: a second migrate with the same workspaces adds nothing new (skipped, not backfilled). | ||
| TestRestClient.HttpResponse secondMigrate = client.postJson(RESOURCE_SHARING_MIGRATION_ENDPOINT, migrationPayload_valid()); | ||
| secondMigrate.assertStatusCode(HttpStatus.SC_OK); | ||
| assertThat( | ||
| secondMigrate.bodyAsMap().get("summary"), | ||
| equalTo("Migration complete. migrated 0; backfilledExisting 0; skippedNoType 0; skippedExisting 1; failed 0") | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testMigrateAPIWithSuperAdmin_valid_withSpecifiedAccessLevel() { | ||
| String resourceId = createSampleResource(); | ||
|
|
@@ -308,7 +393,7 @@ public void testMigrateAPIWithSuperAdmin_valid_withSpecifiedAccessLevel() { | |
| migrateResponse.assertStatusCode(HttpStatus.SC_OK); | ||
| assertThat( | ||
| migrateResponse.bodyAsMap().get("summary"), | ||
| equalTo("Migration complete. migrated 2; skippedNoType 0; skippedExisting 0; failed 0") | ||
| equalTo("Migration complete. migrated 2; backfilledExisting 0; skippedNoType 0; skippedExisting 0; failed 0") | ||
| ); | ||
| assertThat(migrateResponse.bodyAsMap().get("resourcesWithDefaultOwner"), equalTo(List.of(resourceIdNoUser))); | ||
|
|
||
|
|
@@ -395,7 +480,7 @@ public void testMigrateAPIWithSuperAdmin_noDefaultAccessLevel_usesRegisteredDefa | |
| migrateResponse.assertStatusCode(HttpStatus.SC_OK); | ||
| assertThat( | ||
| migrateResponse.bodyAsMap().get("summary"), | ||
| equalTo("Migration complete. migrated 2; skippedNoType 0; skippedExisting 0; failed 0") | ||
| equalTo("Migration complete. migrated 2; backfilledExisting 0; skippedNoType 0; skippedExisting 0; failed 0") | ||
| ); | ||
|
|
||
| TestRestClient.HttpResponse sharingResponse = client.get(RESOURCE_SHARING_INDEX + "/_search"); | ||
|
|
@@ -645,7 +730,7 @@ public void testMigrateAPI_withGarbageParentId() { | |
| migrateResponse.assertStatusCode(HttpStatus.SC_OK); | ||
| assertThat( | ||
| migrateResponse.bodyAsMap().get("summary"), | ||
| equalTo("Migration complete. migrated 1; skippedNoType 0; skippedExisting 0; failed 0") | ||
| equalTo("Migration complete. migrated 1; backfilledExisting 0; skippedNoType 0; skippedExisting 0; failed 0") | ||
| ); | ||
|
|
||
| // The sharing record should be created with the garbage parent_id stored as-is | ||
|
|
@@ -681,7 +766,7 @@ public void testMigrateAPI_withParentHierarchy() { | |
| migrateResponse.assertStatusCode(HttpStatus.SC_OK); | ||
| assertThat( | ||
| migrateResponse.bodyAsMap().get("summary"), | ||
| equalTo("Migration complete. migrated 2; skippedNoType 0; skippedExisting 0; failed 0") | ||
| equalTo("Migration complete. migrated 2; backfilledExisting 0; skippedNoType 0; skippedExisting 0; failed 0") | ||
| ); | ||
|
|
||
| // Verify the sharing record for the resource has parent_type and parent_id set | ||
|
|
@@ -762,6 +847,26 @@ private String createSampleResource() { | |
| } | ||
| } | ||
|
|
||
| private String createSampleResourceWithWorkspaces(String... workspaceIds) { | ||
| try (TestRestClient client = cluster.getRestClient(MIGRATION_USER)) { | ||
| StringBuilder wsArray = new StringBuilder("["); | ||
| for (int i = 0; i < workspaceIds.length; i++) { | ||
| if (i > 0) wsArray.append(","); | ||
| wsArray.append("\"").append(workspaceIds[i]).append("\""); | ||
| } | ||
| wsArray.append("]"); | ||
| String sampleResource = ("{\"name\":\"sample_ws\",\"store_user\":true,\"workspaces\":" + wsArray + "}"); | ||
|
|
||
| TestRestClient.HttpResponse response = client.putJson(SAMPLE_RESOURCE_CREATE_ENDPOINT, sampleResource); | ||
| response.assertStatusCode(HttpStatus.SC_OK); | ||
| String resourceId = response.getTextFromJsonBody("/message").split(":")[1].trim(); | ||
| Awaitility.await() | ||
| .alias("Wait until resource with workspaces is populated") | ||
| .until(() -> client.get(SAMPLE_RESOURCE_GET_ENDPOINT + "/" + resourceId).getStatusCode(), equalTo(200)); | ||
| return resourceId; | ||
| } | ||
| } | ||
|
|
||
| private String createSampleResourceNoUser() { | ||
| try (TestRestClient client = cluster.getRestClient(MIGRATION_USER)) { | ||
| String sampleResource = """ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.