Skip to content
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

Support to specify backend roles for monitors #635

Merged
merged 6 commits into from
Nov 4, 2022

Conversation

lezzago
Copy link
Member

@lezzago lezzago commented Nov 2, 2022

Signed-off-by: Ashish Agrawal [email protected]

Issue #, if available:
#138

Description of changes:
Support specify backend roles for monitors
New Scenarios:

  • Create monitor scenario:

    • User specified backend roles
      • Admin user: use all the specified backend roles to associate to the monitor
      • Normal user: use all the specified backend roles (that the user already has in their list of backend roles) to associate to the monitor
    • User did not specify backend roles:
      • Copy user’s backend roles and associate them to the monitor
  • Update monitor scenario:

    • User specified backend roles
      • Admin user: Remove all the backend roles associate to the monitor and then use all the specified backend roles to associate to the monitor
      • Normal user: Remove backend roles associated to the monitor that the user has access to, but didn’t specify. Then add all the other specified backend roles (that the user already has in their list of backend roles) to the monitor
    • User did not specify backend roles:
      • Don’t update the backend roles on the monitor
  • Empty list is considered as removing all permissions the user has access to or create a monitor with no backend roles

  • Throw exceptions if a user tries to associate roles that they do not have access to

  • Only admin users can pass in an empty list. Non-admin users need to pass in at least 1 backend role so they dont remove their access from the monitor for mistakes

Example of new create/update monitor request (rbac_roles is the new optional parameter):

POST _plugins/_alerting/monitors
{
  "type": "monitor",
  "name": "test-monitor",
  "monitor_type": "query_level_monitor",
  "enabled": true,
  "schedule": {
    "period": {
      "interval": 1,
      "unit": "MINUTES"
    }
  },
  "inputs": [{
    "search": {
      "indices": ["movies"],
      "query": {
        "size": 0,
        "aggregations": {},
        "query": {
          "bool": {
            "filter": {
              "range": {
                "@timestamp": {
                  "gte": "{{period_end}}||-1h",
                  "lte": "{{period_end}}",
                  "format": "epoch_millis"
                }
              }
            }
          }
        }
      }
    }
  }],
  "triggers": [{
    "name": "test-trigger",
    "severity": "1",
    "condition": {
      "script": {
        "source": "ctx.results[0].hits.total.value > 0",
        "lang": "painless"
      }
    },
    "actions": [{
      "name": "test-action",
      "destination_id": "ld7912sBlQ5JUWWFThoW",
      "message_template": {
        "source": "This is my message body."
      },
      "throttle_enabled": true,
      "throttle": {
        "value": 27,
        "unit": "MINUTES"
      },
      "subject_template": {
        "source": "TheSubject"
      }
    }]
  }],
  "rbac_roles": ["role1", "role2"]
}

CheckList:
[X] Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Ashish Agrawal <[email protected]>
Signed-off-by: Ashish Agrawal <[email protected]>
@codecov-commenter
Copy link

codecov-commenter commented Nov 3, 2022

Codecov Report

Attention: Patch coverage is 14.28571% with 36 lines in your changes missing coverage. Please review.

Project coverage is 76.00%. Comparing base (c6c12db) to head (afc0aaf).
Report is 193 commits behind head on main.

Files with missing lines Patch % Lines
.../alerting/transport/TransportIndexMonitorAction.kt 10.00% 32 Missing and 4 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main     #635      +/-   ##
============================================
- Coverage     76.37%   76.00%   -0.38%     
  Complexity      116      116              
============================================
  Files           124      124              
  Lines          6443     6485      +42     
  Branches        942      956      +14     
============================================
+ Hits           4921     4929       +8     
- Misses         1040     1069      +29     
- Partials        482      487       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Ashish Agrawal <[email protected]>
@brijos brijos changed the title Support specificy backend roles for monitors Support to specify backend roles for monitors Nov 3, 2022
@lezzago lezzago added the documentation Improvements or additions to documentation label Nov 3, 2022
Signed-off-by: Ashish Agrawal <[email protected]>
Signed-off-by: Ashish Agrawal <[email protected]>
@lezzago lezzago merged commit f986238 into opensearch-project:main Nov 4, 2022
opensearch-trigger-bot bot pushed a commit that referenced this pull request Nov 4, 2022
* Support specify backend roles for monitors

Signed-off-by: Ashish Agrawal <[email protected]>
(cherry picked from commit f986238)
opensearch-trigger-bot bot pushed a commit that referenced this pull request Nov 4, 2022
* Support specify backend roles for monitors

Signed-off-by: Ashish Agrawal <[email protected]>
(cherry picked from commit f986238)
lezzago added a commit that referenced this pull request Nov 4, 2022
* Support specify backend roles for monitors

Signed-off-by: Ashish Agrawal <[email protected]>
(cherry picked from commit f986238)

Co-authored-by: Ashish Agrawal <[email protected]>
lezzago added a commit that referenced this pull request Nov 4, 2022
* Support specify backend roles for monitors

Signed-off-by: Ashish Agrawal <[email protected]>
(cherry picked from commit f986238)

Co-authored-by: Ashish Agrawal <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x backport 2.4 documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants