-
Notifications
You must be signed in to change notification settings - Fork 132
Onboards Alerting Plugin to Centralized Resource Authz #2180
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
Draft
DarshitChanpura
wants to merge
34
commits into
opensearch-project:main
Choose a base branch
from
DarshitChanpura:onbaord-resource-authz
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.
Draft
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
cba6f83
Onboards to Resource Sharing and Authorization
DarshitChanpura b8fba5f
Adds tests for resource sharing feature
DarshitChanpura 2576e6b
Fix resource types
DarshitChanpura eaa005a
Filter alerts by accessible monitor IDs when resource sharing is en…
DarshitChanpura cd35539
Merge remote-tracking branch 'upstream/main' into onbaord-resource-authz
DarshitChanpura ef94b4c
Adds a default access level
DarshitChanpura ed0997a
Removes duplicate sec plugin zip loading
DarshitChanpura 4959318
Route access control through resource-sharing framework when enabled
DarshitChanpura 1150f6d
Merge remote-tracking branch 'upstream/main' into onbaord-resource-authz
DarshitChanpura c405ac4
Avoid capturing ResourceSharingClient in lambdas to prevent NoClassDe…
DarshitChanpura fee8e21
Route shared-resource searches through PluginClient when
DarshitChanpura 39e6af8
Expand resource-sharing IT coverage over transport-level interception
DarshitChanpura fccd755
Decouple ResourceSharingClientAccessor from security-spi type at clas…
DarshitChanpura 132ab70
Gate resource-sharing paths on isFeatureEnabledForType
DarshitChanpura 3423f88
Cover full access-level matrix in resource-sharing ITs
DarshitChanpura f181725
Expand resource-sharing IT coverage to a full behavior matrix
DarshitChanpura 9c29f1b
Fix resource-sharing IT setup: batch role mapping, add index perms
DarshitChanpura cf5e603
Require explicit resourceType arg to shouldUseResourceAuthz
DarshitChanpura 7cf03da
Configure protected_types for resource sharing in integTest cluster
DarshitChanpura 8162e18
Bump common-utils dependency to track opensearch_build (3.8.0.0)
DarshitChanpura 77a1998
Wire monitors and workflows into resource-sharing framework
DarshitChanpura f8d0e6d
Fix RSC IT suite: local helpers, revoke via PATCH, downgrade sequencing
DarshitChanpura 4a43f4b
Remove RSC_MIGRATION.md scratch design doc
DarshitChanpura a550f12
Add POST /_plugins/_alerting/_migrate_to_rsc for RSC upgrade path
DarshitChanpura 6560893
Purge legacy metadata docs during migrate + add E2E lifecycle IT
DarshitChanpura 161502a
JobSweeper: skip ancillary top-level fields when detecting job type
DarshitChanpura 1eab1cd
Drop top-level resource_type; classify via nested type paths
DarshitChanpura 04e7d5f
Drop _migrate_to_rsc endpoint; rely on security plugin's classifier
DarshitChanpura 99c95b9
Post-review cleanups: extension tests cover workflow provider; drop s…
DarshitChanpura 1f7076a
Accept 403|404 on post-delete GET; ignore flaky alerts-inherit test
DarshitChanpura a01d541
Fix schema-version test expectation and restore stash pattern for com…
DarshitChanpura c507456
Unwrap CompletionException in SdkClient await so REST status survives
DarshitChanpura e7e43f5
Run RSC accessible-resource lookups under caller context; harden comm…
DarshitChanpura d8f115e
Initialize alerts index mapping in comment ITs so RSC monitor_id filt…
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
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
50 changes: 50 additions & 0 deletions
50
alerting/src/main/kotlin/org/opensearch/alerting/AlertingResourceSharingExtension.kt
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 |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.alerting | ||
|
|
||
| import org.opensearch.commons.alerting.model.ScheduledJob.Companion.SCHEDULED_JOBS_INDEX | ||
| import org.opensearch.security.spi.resources.ResourceProvider | ||
| import org.opensearch.security.spi.resources.ResourceSharingExtension | ||
| import org.opensearch.security.spi.resources.client.ResourceSharingClient | ||
|
|
||
| class AlertingResourceSharingExtension : ResourceSharingExtension { | ||
| /** | ||
| * Monitors and workflows share [SCHEDULED_JOBS_INDEX]. Each provider declares its own | ||
| * type-specific field paths so the security plugin can distinguish them without a | ||
| * top-level discriminator on the stored doc: | ||
| * | ||
| * - [ResourceProvider.typeField] — used by the postIndex hook to classify new writes. | ||
| * `monitor.type` is present on monitor docs and absent on workflow docs (and vice versa), | ||
| * so the framework iterates matching providers and picks the one whose typeField | ||
| * resolves non-null. | ||
| * - [ResourceProvider.ownerNamePath] / [ResourceProvider.ownerBackendRolesPath] — used by | ||
| * the security plugin's `POST /_plugins/_security/api/resources/migrate` endpoint when | ||
| * seeding sharing entries for legacy docs, so a single admin call can attribute owners | ||
| * across both types without pre-processing. | ||
| */ | ||
| override fun getResourceProviders(): Set<ResourceProvider> { | ||
| return setOf( | ||
| object : ResourceProvider { | ||
| override fun resourceType(): String = ResourceSharingUtils.MONITOR_RESOURCE_TYPE | ||
| override fun resourceIndexName(): String = SCHEDULED_JOBS_INDEX | ||
| override fun typeField(): String = "monitor.type" | ||
| override fun ownerNamePath(): String = "/monitor/user/name" | ||
| override fun ownerBackendRolesPath(): String = "/monitor/user/backend_roles" | ||
| }, | ||
| object : ResourceProvider { | ||
| override fun resourceType(): String = ResourceSharingUtils.WORKFLOW_RESOURCE_TYPE | ||
| override fun resourceIndexName(): String = SCHEDULED_JOBS_INDEX | ||
| override fun typeField(): String = "workflow.type" | ||
| override fun ownerNamePath(): String = "/workflow/user/name" | ||
| override fun ownerBackendRolesPath(): String = "/workflow/user/backend_roles" | ||
| } | ||
| ) | ||
| } | ||
|
|
||
| override fun assignResourceSharingClient(client: ResourceSharingClient?) { | ||
| ResourceSharingClientAccessor.setResourceSharingClient(client) | ||
| } | ||
| } | ||
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
46 changes: 46 additions & 0 deletions
46
alerting/src/main/kotlin/org/opensearch/alerting/ResourceSharingClientAccessor.kt
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 |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| package org.opensearch.alerting | ||
|
|
||
| import org.opensearch.security.spi.resources.client.ResourceSharingClient | ||
|
|
||
| /** | ||
| * Accessor for resource sharing client. | ||
| * | ||
| * The internal field is typed as [Any?] so that loading this class does NOT trigger resolution of | ||
| * [ResourceSharingClient] — which lives in the security-spi jar and is absent at runtime when the | ||
| * security plugin is not installed. Callers that need methods on the client cast the result. | ||
| */ | ||
| object ResourceSharingClientAccessor { | ||
|
|
||
| @Volatile | ||
| private var client: Any? = null | ||
|
|
||
| /** | ||
| * Set the resource sharing client. Only called by [AlertingResourceSharingExtension.assignResourceSharingClient] | ||
| * which is invoked by the security plugin — so [ResourceSharingClient] is guaranteed to be on the classpath | ||
| * at that point. | ||
| */ | ||
| @JvmStatic | ||
| fun setResourceSharingClient(client: ResourceSharingClient?) { | ||
| this.client = client | ||
| } | ||
|
|
||
| /** | ||
| * Get the resource sharing client, or null if the security plugin is not loaded / resource sharing is disabled. | ||
| * Returns [Any?] to avoid linking [ResourceSharingClient] in callers when the security plugin is absent. | ||
| * Callers that need to invoke methods should cast: `getResourceSharingClient() as ResourceSharingClient`. | ||
| */ | ||
| @JvmStatic | ||
| fun getResourceSharingClient(): Any? = client | ||
|
|
||
| /** | ||
| * Clear the client (useful in tests). | ||
| */ | ||
| @JvmStatic | ||
| fun clear() { | ||
| client = null | ||
| } | ||
| } |
34 changes: 34 additions & 0 deletions
34
alerting/src/main/kotlin/org/opensearch/alerting/ResourceSharingUtils.kt
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 |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| package org.opensearch.alerting | ||
|
|
||
| import org.opensearch.security.spi.resources.client.ResourceSharingClient | ||
|
|
||
| /** | ||
| * Shared helpers for the resource-sharing framework. | ||
| * | ||
| * The [ResourceSharingClient] class is referenced only inside method bodies (never as a field type) | ||
| * so this object can be class-loaded when the security plugin is absent without triggering | ||
| * [NoClassDefFoundError]. Callers should invoke [shouldUseResourceAuthz] rather than reading the | ||
| * accessor directly. | ||
| */ | ||
| internal object ResourceSharingUtils { | ||
|
|
||
| /** Resource type registered by [AlertingResourceSharingExtension] for monitors. */ | ||
| const val MONITOR_RESOURCE_TYPE = "monitor" | ||
|
|
||
| /** Resource type registered by [AlertingResourceSharingExtension] for workflows. */ | ||
| const val WORKFLOW_RESOURCE_TYPE = "workflow" | ||
|
|
||
| /** | ||
| * Returns true only when the security plugin is loaded AND the resource-sharing feature is enabled | ||
| * for [resourceType]. A non-null accessor client alone is insufficient — the plugin may be present | ||
| * with the RSC feature flag disabled. | ||
| */ | ||
| fun shouldUseResourceAuthz(resourceType: String): Boolean { | ||
| val client = ResourceSharingClientAccessor.getResourceSharingClient() ?: return false | ||
| return (client as ResourceSharingClient).isFeatureEnabledForType(resourceType) | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about alerts and comments which are stored in different indices?
Alerts: https://github.com/opensearch-project/alerting/blob/main/alerting/src/main/kotlin/org/opensearch/alerting/alerts/AlertIndices.kt#L116-L154
Comments: https://github.com/opensearch-project/alerting/blob/main/alerting/src/main/kotlin/org/opensearch/alerting/comments/CommentsIndices.kt#L66-L84
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alerts and comments are treated as subordinate resources rather than registered resource types, so we don't register their indices with the sharing framework. Instead, access is inherited from the underlying monitor:
TransportGetAlertsAction/TransportGetWorkflowAlertsActioncallrsc.getAccessibleResourceIds("monitor", ...)and add amonitor_idterms filter to the alert search.TransportSearchAlertingCommentActiondoes the same via alert IDs derived from accessible monitors.TransportIndexAlertingCommentAction/TransportDeleteAlertingCommentActionrely on the ActionFilter blocking the underlying alert fetch (viaDocRequeston the requests, which points at the monitor).New tests
bob cannot see alice's monitor alerts without shareandbob can see alice's monitor alerts after shareinSecureResourceSharingMonitorRestApiITcover this.