@@ -11,8 +11,23 @@ import { MDSEnabledClientService } from './MDSEnabledClientService';
1111import { DEFAULT_HEADERS } from './utils/constants' ;
1212
1313export default class MonitorService extends MDSEnabledClientService {
14+
15+ /**
16+ * Checks workspace ACL and returns an unauthorized response if check fails.
17+ * Returns null if authorized, or a response object if unauthorized.
18+ */
19+ _enforceWorkspaceAcl = async ( context , req , res , permissionModes ) => {
20+ const authorized = await this . checkWorkspaceAcl ( context , req , permissionModes ) ;
21+ if ( ! authorized ) {
22+ return res . ok ( { body : { ok : false , resp : 'Workspace ACL check failed: unauthorized' } } ) ;
23+ }
24+ return null ;
25+ } ;
26+
1427 createMonitor = async ( context , req , res ) => {
1528 try {
29+ const aclResponse = await this . _enforceWorkspaceAcl ( context , req , res , [ 'library_write' ] ) ;
30+ if ( aclResponse ) return aclResponse ;
1631 const params = { body : req . body } ;
1732 const client = this . getClientBasedOnDataSource ( context , req ) ;
1833 const createResponse = await client ( 'alerting.createMonitor' , params ) ;
@@ -35,6 +50,8 @@ export default class MonitorService extends MDSEnabledClientService {
3550
3651 createWorkflow = async ( context , req , res ) => {
3752 try {
53+ const aclResponse = await this . _enforceWorkspaceAcl ( context , req , res , [ 'library_write' ] ) ;
54+ if ( aclResponse ) return aclResponse ;
3855 const params = { body : req . body } ;
3956 const client = this . getClientBasedOnDataSource ( context , req ) ;
4057 const createResponse = await client ( 'alerting.createWorkflow' , params ) ;
@@ -57,6 +74,8 @@ export default class MonitorService extends MDSEnabledClientService {
5774
5875 deleteMonitor = async ( context , req , res ) => {
5976 try {
77+ const aclResponse = await this . _enforceWorkspaceAcl ( context , req , res , [ 'library_write' ] ) ;
78+ if ( aclResponse ) return aclResponse ;
6079 const { id } = req . params ;
6180 const params = { monitorId : id } ;
6281 const client = this . getClientBasedOnDataSource ( context , req ) ;
@@ -80,6 +99,8 @@ export default class MonitorService extends MDSEnabledClientService {
8099
81100 deleteWorkflow = async ( context , req , res ) => {
82101 try {
102+ const aclResponse = await this . _enforceWorkspaceAcl ( context , req , res , [ 'library_write' ] ) ;
103+ if ( aclResponse ) return aclResponse ;
83104 const { id } = req . params ;
84105 const params = { workflowId : id } ;
85106 const client = this . getClientBasedOnDataSource ( context , req ) ;
@@ -103,6 +124,11 @@ export default class MonitorService extends MDSEnabledClientService {
103124
104125 getMonitor = async ( context , req , res ) => {
105126 try {
127+ const aclResponse = await this . _enforceWorkspaceAcl ( context , req , res , [
128+ 'library_write' ,
129+ 'library_read' ,
130+ ] ) ;
131+ if ( aclResponse ) return aclResponse ;
106132 const { id } = req . params ;
107133 const params = { monitorId : id , headers : DEFAULT_HEADERS } ;
108134 const client = this . getClientBasedOnDataSource ( context , req ) ;
@@ -185,6 +211,11 @@ export default class MonitorService extends MDSEnabledClientService {
185211
186212 getWorkflow = async ( context , req , res ) => {
187213 try {
214+ const aclResponse = await this . _enforceWorkspaceAcl ( context , req , res , [
215+ 'library_write' ,
216+ 'library_read' ,
217+ ] ) ;
218+ if ( aclResponse ) return aclResponse ;
188219 const { id } = req . params ;
189220 const params = { monitorId : id } ;
190221 const client = this . getClientBasedOnDataSource ( context , req ) ;
@@ -225,6 +256,8 @@ export default class MonitorService extends MDSEnabledClientService {
225256
226257 updateMonitor = async ( context , req , res ) => {
227258 try {
259+ const aclResponse = await this . _enforceWorkspaceAcl ( context , req , res , [ 'library_write' ] ) ;
260+ if ( aclResponse ) return aclResponse ;
228261 const { id } = req . params ;
229262 const params = { monitorId : id , body : req . body , refresh : 'wait_for' } ;
230263 const { type } = req . body ;
@@ -262,6 +295,11 @@ export default class MonitorService extends MDSEnabledClientService {
262295
263296 getMonitors = async ( context , req , res ) => {
264297 try {
298+ const aclResponse = await this . _enforceWorkspaceAcl ( context , req , res , [
299+ 'library_write' ,
300+ 'library_read' ,
301+ ] ) ;
302+ if ( aclResponse ) return aclResponse ;
265303 const { from, size, search, sortDirection, sortField, state, monitorIds } = req . query ;
266304
267305 let must = { match_all : { } } ;
@@ -508,6 +546,8 @@ export default class MonitorService extends MDSEnabledClientService {
508546
509547 acknowledgeAlerts = async ( context , req , res ) => {
510548 try {
549+ const aclResponse = await this . _enforceWorkspaceAcl ( context , req , res , [ 'library_write' ] ) ;
550+ if ( aclResponse ) return aclResponse ;
511551 const { id } = req . params ;
512552 const params = {
513553 monitorId : id ,
@@ -534,6 +574,8 @@ export default class MonitorService extends MDSEnabledClientService {
534574
535575 acknowledgeChainedAlerts = async ( context , req , res ) => {
536576 try {
577+ const aclResponse = await this . _enforceWorkspaceAcl ( context , req , res , [ 'library_write' ] ) ;
578+ if ( aclResponse ) return aclResponse ;
537579 const { id } = req . params ;
538580 const params = {
539581 workflowId : id ,
@@ -565,6 +607,8 @@ export default class MonitorService extends MDSEnabledClientService {
565607
566608 executeMonitor = async ( context , req , res ) => {
567609 try {
610+ const aclResponse = await this . _enforceWorkspaceAcl ( context , req , res , [ 'library_write' ] ) ;
611+ if ( aclResponse ) return aclResponse ;
568612 const { dryrun = 'true' } = req . query ;
569613 const params = {
570614 body : req . body ,
@@ -592,6 +636,11 @@ export default class MonitorService extends MDSEnabledClientService {
592636 //TODO: This is temporarily a pass through call which needs to be deprecated
593637 searchMonitors = async ( context , req , res ) => {
594638 try {
639+ const aclResponse = await this . _enforceWorkspaceAcl ( context , req , res , [
640+ 'library_write' ,
641+ 'library_read' ,
642+ ] ) ;
643+ if ( aclResponse ) return aclResponse ;
595644 const { query : queryBody , index, size, ...rest } = req . body || { } ;
596645 const body = { ...( queryBody ?? { } ) , ...rest } ;
597646 if ( size !== undefined ) {
0 commit comments