Skip to content

Enforce realm and asset scoping for rule alarms - #3459

Open
ebariaux wants to merge 15 commits into
mainfrom
bugfix/rules-alarm-facade-scoping
Open

ebariaux wants to merge 15 commits into
mainfrom
bugfix/rules-alarm-facade-scoping

Conversation

@ebariaux

@ebariaux ebariaux commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Alarm rules could create or extend alarms outside their asset scope and assign users without validating access. Global rules also failed because creation and linking required an engine realm.

This PR adds validation before alarms or links are persisted:

  • Asset-scoped rules may target only the scoped asset or its descendants. Creation requires targets; linking requires existing links, with every existing and requested asset in scope.
  • Assignees remain optional and must belong to the alarm’s realm. Restricted assignees need explicit links to every target; unrestricted assignees need no asset links.
  • Global creation uses the supplied realm or infers it from targets, validating all targets against that realm. Global linking uses the existing alarm’s realm. Reusable global alarm definitions are preserved.
  • Automatic notifications for unassigned HIGH alarms exclude restricted users without access to every linked asset, including alarms without asset links.
  • Rejected requests leave alarms and links unchanged. Existing validation errors, duplicate-link handling, and link timestamps are preserved.

Part of the rules facade scoping review tracked in #2675.

@ebariaux ebariaux added the Bug Error or issue in the system label Oct 20, 2026
@ebariaux
ebariaux marked this pull request as ready for review October 21, 2026 08:47
@ebariaux
ebariaux requested a review from a team October 21, 2026 08:48

@wborn wborn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an initial AI-assisted review.

The scope validation and expanded integration tests provide good coverage of the intended behavior.

One concern remains: synchronous Keycloak role lookups during automatic alarm notification processing introduce an external dependency that can cause alarm creation to fail after the alarm has already been persisted. This should be addressed before merging.

// Both notification channels include all linked assets, so partial access is insufficient.
users.removeIf(
user ->
Arrays.asList(identityProvider.getUserRealmRoles(alarm.getRealm(), user.getId()))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduces a synchronous Keycloak Admin API request for every potential notification recipient. These requests are serialized by KeycloakIdentityProvider.getRealms(), and a Keycloak failure can cause sendAlarm() to fail after the alarm has already been persisted.

Could recipient filtering avoid these synchronous external requests so that notification processing cannot cause an otherwise successful alarm operation to fail?

@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Error or issue in the system

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants