-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[SECURITY_SOLUTIONS] Only query security alerts with current user #174216
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6db785b
only use current user
XavierM d27f3c2
Merge branch 'main' of github.com:elastic/kibana into alert-use-curre…
XavierM 5488066
add test to show how DLS works
XavierM f75e6ca
Merge branch 'main' of github.com:elastic/kibana into alert-use-curre…
XavierM a3d77fb
formatting
XavierM 97caa8a
review
XavierM f54224a
fix tests
XavierM fa3a51d
Merge branch 'main' of github.com:elastic/kibana into alert-use-curre…
XavierM 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 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
147 changes: 147 additions & 0 deletions
147
...on_api_integration/test_suites/detections_response/default_license/alerts/query_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,147 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
const roleToAccessSecuritySolution = { | ||
name: 'sec_all_spaces', | ||
privileges: { | ||
elasticsearch: { | ||
indices: [ | ||
{ | ||
names: ['.alerts-security.alerts-default'], | ||
privileges: ['all'], | ||
}, | ||
], | ||
}, | ||
kibana: [ | ||
{ | ||
feature: { | ||
siem: ['all'], | ||
}, | ||
spaces: ['*'], | ||
}, | ||
], | ||
}, | ||
}; | ||
const roleToAccessSecuritySolutionWithDsl = { | ||
name: 'sec_all_spaces_with_dsl', | ||
privileges: { | ||
elasticsearch: { | ||
indices: [ | ||
{ | ||
names: ['.alerts-security.alerts-default'], | ||
privileges: ['read'], | ||
query: | ||
'{"wildcard" : { "kibana.alert.ancestors.index" : { "value": ".ds-kibana_does_not_exist" } } }', | ||
}, | ||
], | ||
}, | ||
kibana: [ | ||
{ | ||
feature: { | ||
siem: ['all'], | ||
}, | ||
spaces: ['*'], | ||
}, | ||
], | ||
}, | ||
}; | ||
const userAllSec = { | ||
username: 'user_all_sec', | ||
password: 'user_all_sec', | ||
full_name: 'userAllSec', | ||
email: '[email protected]', | ||
roles: [roleToAccessSecuritySolution.name], | ||
}; | ||
const userAllSecWithDsl = { | ||
username: 'user_all_sec_with_dsl', | ||
password: 'user_all_sec_with_dsl', | ||
full_name: 'userAllSecWithDsl', | ||
email: '[email protected]', | ||
roles: [roleToAccessSecuritySolutionWithDsl.name], | ||
}; | ||
|
||
describe('find alert with/without doc level security', () => { | ||
const supertest = getService('supertest'); | ||
const supertestWithoutAuth = getService('supertestWithoutAuth'); | ||
const esArchiver = getService('esArchiver'); | ||
const security = getService('security'); | ||
|
||
before(async () => { | ||
await security.role.create( | ||
roleToAccessSecuritySolution.name, | ||
roleToAccessSecuritySolution.privileges | ||
); | ||
await security.role.create( | ||
roleToAccessSecuritySolutionWithDsl.name, | ||
roleToAccessSecuritySolutionWithDsl.privileges | ||
); | ||
await security.user.create(userAllSec.username, { | ||
password: userAllSec.password, | ||
roles: userAllSec.roles, | ||
full_name: userAllSec.full_name, | ||
email: userAllSec.email, | ||
}); | ||
await security.user.create(userAllSecWithDsl.username, { | ||
password: userAllSecWithDsl.password, | ||
roles: userAllSecWithDsl.roles, | ||
full_name: userAllSecWithDsl.full_name, | ||
email: userAllSecWithDsl.email, | ||
}); | ||
|
||
await esArchiver.load( | ||
'x-pack/test/functional/es_archives/security_solution/alerts/8.8.0_multiple_docs', | ||
{ | ||
useCreate: true, | ||
docsOnly: true, | ||
} | ||
); | ||
}); | ||
|
||
after(async () => { | ||
await security.user.delete(userAllSec.username); | ||
await security.user.delete(userAllSecWithDsl.username); | ||
await security.role.delete(roleToAccessSecuritySolution.name); | ||
await security.role.delete(roleToAccessSecuritySolutionWithDsl.name); | ||
await esArchiver.unload( | ||
'x-pack/test/functional/es_archives/security_solution/alerts/8.8.0_multiple_docs' | ||
); | ||
}); | ||
|
||
it('should return alerts with user who has access to security solution privileges', async () => { | ||
const query = { | ||
query: { | ||
bool: { | ||
should: [{ match_all: {} }], | ||
}, | ||
}, | ||
}; | ||
const { body } = await supertestWithoutAuth | ||
.post(DETECTION_ENGINE_QUERY_SIGNALS_URL) | ||
.auth(userAllSec.username, userAllSec.password) | ||
.set('kbn-xsrf', 'true') | ||
.send(query) | ||
.expect(200); | ||
expect(body.hits.total.value).to.eql(3); | ||
}); | ||
|
||
it('should filter out alerts with user who has access to security solution privileges and document level security', async () => { | ||
const query = { | ||
query: { | ||
bool: { | ||
should: [{ match_all: {} }], | ||
}, | ||
}, | ||
}; | ||
const { body } = await supertestWithoutAuth | ||
.post(DETECTION_ENGINE_QUERY_SIGNALS_URL) | ||
.auth(userAllSecWithDsl.username, userAllSecWithDsl.password) | ||
.set('kbn-xsrf', 'true') | ||
.send(query) | ||
.expect(200); | ||
expect(body.hits.total.value).to.eql(0); | ||
}); | ||
}); |
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.
nit: all instances of
dsl
should bedls
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.
oh Zut, I will change that