-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds kibana security feature privileges and updates alerts actions to…
… include space id in constructor rather than parameter as a part of the get since the spaceId will be available to us in the start phase of the plugin
- Loading branch information
Showing
4 changed files
with
269 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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 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
207 changes: 207 additions & 0 deletions
207
...plugins/security/server/authorization/privileges/feature_privilege_builder/alerts.test.ts
This file contains 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,207 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { FeatureKibanaPrivileges } from '../../../../../features/server'; | ||
import { KibanaFeature } from '../../../../../features/server'; | ||
import { Actions } from '../../actions'; | ||
import { FeaturePrivilegeAlertsBuilder } from './alerts'; | ||
|
||
const version = '1.0.0-zeta1'; | ||
|
||
describe(`alerts`, () => { | ||
describe(`feature_privilege_builder`, () => { | ||
it('grants no privileges by default', () => { | ||
const actions = new Actions(version); | ||
const alertsFeaturePrivileges = new FeaturePrivilegealertsBuilder(actions); | ||
|
||
const privilege: FeatureKibanaPrivileges = { | ||
savedObject: { | ||
all: [], | ||
read: [], | ||
}, | ||
ui: [], | ||
}; | ||
|
||
const feature = new KibanaFeature({ | ||
id: 'my-feature', | ||
name: 'my-feature', | ||
app: [], | ||
category: { id: 'foo', label: 'foo' }, | ||
privileges: { | ||
all: privilege, | ||
read: privilege, | ||
}, | ||
}); | ||
|
||
expect(alertsFeaturePrivileges.getActions(privilege, feature)).toEqual([]); | ||
}); | ||
|
||
describe(`within feature`, () => { | ||
it('grants `read` privileges under feature', () => { | ||
const actions = new Actions(version); | ||
const alertsFeaturePrivilege = new FeaturePrivilegealertsBuilder(actions); | ||
|
||
const privilege: FeatureKibanaPrivileges = { | ||
alerts: { | ||
read: ['observability'], | ||
}, | ||
|
||
savedObject: { | ||
all: [], | ||
read: [], | ||
}, | ||
ui: [], | ||
}; | ||
|
||
const feature = new KibanaFeature({ | ||
id: 'my-feature', | ||
name: 'my-feature', | ||
app: [], | ||
category: { id: 'foo', label: 'foo' }, | ||
privileges: { | ||
all: privilege, | ||
read: privilege, | ||
}, | ||
}); | ||
|
||
expect(alertsFeaturePrivilege.getActions(privilege, feature)).toMatchInlineSnapshot(` | ||
Array [ | ||
"alerts:1.0.0-zeta1:observability/get", | ||
"alerts:1.0.0-zeta1:observability/find", | ||
] | ||
`); | ||
}); | ||
|
||
it('grants `all` privileges under feature', () => { | ||
const actions = new Actions(version); | ||
const alertsFeaturePrivilege = new FeaturePrivilegealertsBuilder(actions); | ||
|
||
const privilege: FeatureKibanaPrivileges = { | ||
alerts: { | ||
all: ['security'], | ||
}, | ||
|
||
savedObject: { | ||
all: [], | ||
read: [], | ||
}, | ||
ui: [], | ||
}; | ||
|
||
const feature = new KibanaFeature({ | ||
id: 'my-feature', | ||
name: 'my-feature', | ||
app: [], | ||
category: { id: 'foo', label: 'foo' }, | ||
privileges: { | ||
all: privilege, | ||
read: privilege, | ||
}, | ||
}); | ||
|
||
expect(alertsFeaturePrivilege.getActions(privilege, feature)).toMatchInlineSnapshot(` | ||
Array [ | ||
"alerts:1.0.0-zeta1:security/get", | ||
"alerts:1.0.0-zeta1:security/find", | ||
"alerts:1.0.0-zeta1:security/create", | ||
"alerts:1.0.0-zeta1:security/delete", | ||
"alerts:1.0.0-zeta1:security/update", | ||
] | ||
`); | ||
}); | ||
|
||
it('grants both `all` and `read` privileges under feature', () => { | ||
const actions = new Actions(version); | ||
const alertsFeaturePrivilege = new FeaturePrivilegealertsBuilder(actions); | ||
|
||
const privilege: FeatureKibanaPrivileges = { | ||
alerts: { | ||
all: ['security'], | ||
read: ['obs'], | ||
}, | ||
|
||
savedObject: { | ||
all: [], | ||
read: [], | ||
}, | ||
ui: [], | ||
}; | ||
|
||
const feature = new KibanaFeature({ | ||
id: 'my-feature', | ||
name: 'my-feature', | ||
app: [], | ||
category: { id: 'foo', label: 'foo' }, | ||
privileges: { | ||
all: privilege, | ||
read: privilege, | ||
}, | ||
}); | ||
|
||
expect(alertsFeaturePrivilege.getActions(privilege, feature)).toMatchInlineSnapshot(` | ||
Array [ | ||
"alerts:1.0.0-zeta1:security/get", | ||
"alerts:1.0.0-zeta1:security/find", | ||
"alerts:1.0.0-zeta1:security/create", | ||
"alerts:1.0.0-zeta1:security/delete", | ||
"alerts:1.0.0-zeta1:security/update", | ||
"alerts:1.0.0-zeta1:obs/get", | ||
"alerts:1.0.0-zeta1:obs/find", | ||
] | ||
`); | ||
}); | ||
|
||
it('grants both `all` and `read` privileges under feature with multiple values in alerts array', () => { | ||
const actions = new Actions(version); | ||
const alertsFeaturePrivilege = new FeaturePrivilegealertsBuilder(actions); | ||
|
||
const privilege: FeatureKibanaPrivileges = { | ||
alerts: { | ||
all: ['security', 'other-security'], | ||
read: ['obs', 'other-obs'], | ||
}, | ||
|
||
savedObject: { | ||
all: [], | ||
read: [], | ||
}, | ||
ui: [], | ||
}; | ||
|
||
const feature = new KibanaFeature({ | ||
id: 'my-feature', | ||
name: 'my-feature', | ||
app: [], | ||
category: { id: 'foo', label: 'foo' }, | ||
privileges: { | ||
all: privilege, | ||
read: privilege, | ||
}, | ||
}); | ||
|
||
expect(alertsFeaturePrivilege.getActions(privilege, feature)).toMatchInlineSnapshot(` | ||
Array [ | ||
"alerts:1.0.0-zeta1:security/get", | ||
"alerts:1.0.0-zeta1:security/find", | ||
"alerts:1.0.0-zeta1:security/create", | ||
"alerts:1.0.0-zeta1:security/delete", | ||
"alerts:1.0.0-zeta1:security/update", | ||
"alerts:1.0.0-zeta1:other-security/get", | ||
"alerts:1.0.0-zeta1:other-security/find", | ||
"alerts:1.0.0-zeta1:other-security/create", | ||
"alerts:1.0.0-zeta1:other-security/delete", | ||
"alerts:1.0.0-zeta1:other-security/update", | ||
"alerts:1.0.0-zeta1:obs/get", | ||
"alerts:1.0.0-zeta1:obs/find", | ||
"alerts:1.0.0-zeta1:other-obs/get", | ||
"alerts:1.0.0-zeta1:other-obs/find", | ||
] | ||
`); | ||
}); | ||
}); | ||
}); | ||
}); |
30 changes: 30 additions & 0 deletions
30
x-pack/plugins/security/server/authorization/privileges/feature_privilege_builder/alerts.ts
This file contains 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,30 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { uniq } from 'lodash'; | ||
|
||
import type { FeatureKibanaPrivileges } from '../../../../../features/server'; | ||
import { BaseFeaturePrivilegeBuilder } from './feature_privilege_builder'; | ||
|
||
const readOperations: string[] = ['get', 'find']; | ||
const writeOperations: string[] = ['update']; | ||
const allOperations: string[] = [...readOperations, ...writeOperations]; | ||
|
||
export class FeaturePrivilegeAlertsBuilder extends BaseFeaturePrivilegeBuilder { | ||
public getActions(privilegeDefinition: FeatureKibanaPrivileges): string[] { | ||
const getAlertsPrivilege = (operations: string[], owners: readonly string[]) => { | ||
return owners.flatMap((owner) => | ||
operations.map((operation) => this.actions.alerts.get(operation, owner)) | ||
); | ||
}; | ||
|
||
return uniq([ | ||
...getAlertsPrivilege(allOperations, privilegeDefinition.alerts?.all ?? []), | ||
...getAlertsPrivilege(readOperations, privilegeDefinition.alerts?.read ?? []), | ||
]); | ||
} | ||
} |