-
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
[ResponseOps][Alerting] Fix stackAlerts plugin missing rac API auth scope #193948
Merged
umbopepato
merged 4 commits into
elastic:main
from
umbopepato:fix-stack-alerts-endpoints-authentication
Oct 7, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
869f01c
Fix stackAlerts plugin missing rac API auth scope
umbopepato 37fdc74
Add get_alerts_index test with only stackAlerts:read privilege
umbopepato 996d3c7
Merge branch 'main' into fix-stack-alerts-endpoints-authentication
umbopepato 452c99a
Merge branch 'main' into fix-stack-alerts-endpoints-authentication
umbopepato 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
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
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 |
---|---|---|
|
@@ -7,7 +7,12 @@ | |
|
||
import expect from '@kbn/expect'; | ||
|
||
import { superUser, obsOnlySpacesAll, secOnlyRead } from '../../../common/lib/authentication/users'; | ||
import { | ||
superUser, | ||
obsOnlySpacesAll, | ||
secOnlyRead, | ||
stackAlertsOnlyReadSpacesAll, | ||
} from '../../../common/lib/authentication/users'; | ||
import type { User } from '../../../common/lib/authentication/types'; | ||
import { FtrProviderContext } from '../../../common/ftr_provider_context'; | ||
import { getSpaceUrlPrefix } from '../../../common/lib/authentication/spaces'; | ||
|
@@ -22,27 +27,19 @@ export default ({ getService }: FtrProviderContext) => { | |
const SPACE1 = 'space1'; | ||
const APM_ALERT_INDEX = '.alerts-observability.apm.alerts-default'; | ||
const SECURITY_SOLUTION_ALERT_INDEX = '.alerts-security.alerts'; | ||
const STACK_ALERT_INDEX = '.alerts-stack.alerts-default'; | ||
|
||
const getAPMIndexName = async (user: User, space: string, expectedStatusCode: number = 200) => { | ||
const resp = await supertestWithoutAuth | ||
.get(`${getSpaceUrlPrefix(space)}${ALERTS_INDEX_URL}?features=apm`) | ||
.auth(user.username, user.password) | ||
.set('kbn-xsrf', 'true') | ||
.expect(expectedStatusCode); | ||
return resp.body.index_name as string[]; | ||
}; | ||
|
||
const getSecuritySolutionIndexName = async ( | ||
const getIndexName = async ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reduced similar functions to a single one parametrized based on featureIds |
||
featureIds: string[], | ||
user: User, | ||
space: string, | ||
expectedStatusCode: number = 200 | ||
) => { | ||
const resp = await supertestWithoutAuth | ||
.get(`${getSpaceUrlPrefix(space)}${ALERTS_INDEX_URL}?features=siem`) | ||
.get(`${getSpaceUrlPrefix(space)}${ALERTS_INDEX_URL}?features=${featureIds.join(',')}`) | ||
.auth(user.username, user.password) | ||
.set('kbn-xsrf', 'true') | ||
.expect(expectedStatusCode); | ||
|
||
return resp.body.index_name as string[]; | ||
}; | ||
|
||
|
@@ -52,24 +49,33 @@ export default ({ getService }: FtrProviderContext) => { | |
}); | ||
describe('Users:', () => { | ||
it(`${obsOnlySpacesAll.username} should be able to access the APM alert in ${SPACE1}`, async () => { | ||
const indexNames = await getAPMIndexName(obsOnlySpacesAll, SPACE1); | ||
const indexNames = await getIndexName(['apm'], obsOnlySpacesAll, SPACE1); | ||
expect(indexNames.includes(APM_ALERT_INDEX)).to.eql(true); // assert this here so we can use constants in the dynamically-defined test cases below | ||
}); | ||
|
||
it(`${superUser.username} should be able to access the APM alert in ${SPACE1}`, async () => { | ||
const indexNames = await getAPMIndexName(superUser, SPACE1); | ||
const indexNames = await getIndexName(['apm'], superUser, SPACE1); | ||
expect(indexNames.includes(APM_ALERT_INDEX)).to.eql(true); // assert this here so we can use constants in the dynamically-defined test cases below | ||
}); | ||
|
||
it(`${secOnlyRead.username} should NOT be able to access the APM alert in ${SPACE1}`, async () => { | ||
const indexNames = await getAPMIndexName(secOnlyRead, SPACE1); | ||
const indexNames = await getIndexName(['apm'], secOnlyRead, SPACE1); | ||
expect(indexNames?.length).to.eql(0); | ||
}); | ||
|
||
it(`${secOnlyRead.username} should be able to access the security solution alert in ${SPACE1}`, async () => { | ||
const indexNames = await getSecuritySolutionIndexName(secOnlyRead, SPACE1); | ||
const indexNames = await getIndexName(['siem'], secOnlyRead, SPACE1); | ||
expect(indexNames.includes(`${SECURITY_SOLUTION_ALERT_INDEX}-${SPACE1}`)).to.eql(true); // assert this here so we can use constants in the dynamically-defined test cases below | ||
}); | ||
|
||
it(`${stackAlertsOnlyReadSpacesAll.username} should be able to access the stack alert in ${SPACE1}`, async () => { | ||
const indexNames = await getIndexName( | ||
['stackAlerts'], | ||
stackAlertsOnlyReadSpacesAll, | ||
SPACE1 | ||
); | ||
expect(indexNames.includes(STACK_ALERT_INDEX)).to.eql(true); | ||
}); | ||
}); | ||
}); | ||
}; |
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
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.
What is the reason for adding this?
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.
See #193948 (comment)
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.
But before it was working without it, why does this role (
alerts_and_actions_role
) need extra permission? Did some tests start failing because we added therac
API privilege?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.
But before it was working without it, why does this role (
alerts_and_actions_role
) need extra permission? Did some tests start failing because we added therac
API privilege?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.
I just added it to simulate a correct scenario (currently the user needs access to the index to be able to see the controls bar) but if we don't mind seeing the error toast in the functional test I can remove it, the other tests work just fine
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.
I think is fine what I do not get is why the
alerts_and_actions_role
role needs it and not thestackAlertsOnlyReadSpacesAll
which is used by the tests. I am sure I am missing something 🙂.