Skip to content

Commit

Permalink
[8.x] Authorized route migration for routes owned by security-detecti…
Browse files Browse the repository at this point in the history
…on-rule-management (elastic#198383) (elastic#200728)

# Backport

This will backport the following commits from `main` to `8.x`:
- [Authorized route migration for routes owned by
security-detection-rule-management
(elastic#198383)](elastic#198383)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Kibana
Machine","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-19T13:02:43Z","message":"Authorized
route migration for routes owned by security-detection-rule-management
(elastic#198383)\n\n### Authz API migration for authorized routes\r\n\r\nThis
PR migrates `access:<privilege>` tags used in route definitions
to\r\nnew security configuration.\r\nPlease refer to the documentation
for more information:
[Authorization\r\nAPI](https://docs.elastic.dev/kibana-dev-docs/key-concepts/security-api-authorization)\r\n\r\n###
**Before migration:**\r\nAccess control tags were defined in the
`options` object of the route:\r\n\r\n```ts\r\nrouter.get({\r\n path:
'/api/path',\r\n options: {\r\n tags: ['access:<privilege_1>',
'access:<privilege_2>'],\r\n },\r\n ...\r\n},
handler);\r\n```\r\n\r\n### **After migration:**\r\nTags have been
replaced with the more robust\r\n`security.authz.requiredPrivileges`
field under `security`:\r\n\r\n```ts\r\nrouter.get({\r\n path:
'/api/path',\r\n security: {\r\n authz: {\r\n requiredPrivileges:
['<privilege_1>', '<privilege_2>'],\r\n },\r\n },\r\n ...\r\n},
handler);\r\n```\r\n\r\n### What to do next?\r\n1. Review the changes in
this PR.\r\n2. You might need to update your tests to reflect the new
security\r\nconfiguration:\r\n - If you have tests that rely on checking
`access` tags.\r\n - If you have snapshot tests that include the route
definition.\r\n- If you have FTR tests that rely on checking
unauthorized error\r\nmessage. The error message changed to also include
missing privileges.\r\n\r\n## Any questions?\r\nIf you have any
questions or need help with API authorization, please\r\nreach out to
the `@elastic/kibana-security` team.\r\n\r\nCo-authored-by: Maxim
Palenov <[email protected]>\r\nCo-authored-by: Elastic Machine
<[email protected]>\r\nCo-authored-by: Larry
Gregory
<[email protected]>","sha":"6e9520aca268c413b2e2264830791d68dbf7dcc9","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["enhancement","release_note:skip","Feature:Security/Authorization","v9.0.0","Team:Detection
Rule Management","backport:prev-minor","Authz: API
migration"],"title":"Authorized route migration for routes owned by
security-detection-rule-management","number":198383,"url":"https://github.com/elastic/kibana/pull/198383","mergeCommit":{"message":"Authorized
route migration for routes owned by security-detection-rule-management
(elastic#198383)\n\n### Authz API migration for authorized routes\r\n\r\nThis
PR migrates `access:<privilege>` tags used in route definitions
to\r\nnew security configuration.\r\nPlease refer to the documentation
for more information:
[Authorization\r\nAPI](https://docs.elastic.dev/kibana-dev-docs/key-concepts/security-api-authorization)\r\n\r\n###
**Before migration:**\r\nAccess control tags were defined in the
`options` object of the route:\r\n\r\n```ts\r\nrouter.get({\r\n path:
'/api/path',\r\n options: {\r\n tags: ['access:<privilege_1>',
'access:<privilege_2>'],\r\n },\r\n ...\r\n},
handler);\r\n```\r\n\r\n### **After migration:**\r\nTags have been
replaced with the more robust\r\n`security.authz.requiredPrivileges`
field under `security`:\r\n\r\n```ts\r\nrouter.get({\r\n path:
'/api/path',\r\n security: {\r\n authz: {\r\n requiredPrivileges:
['<privilege_1>', '<privilege_2>'],\r\n },\r\n },\r\n ...\r\n},
handler);\r\n```\r\n\r\n### What to do next?\r\n1. Review the changes in
this PR.\r\n2. You might need to update your tests to reflect the new
security\r\nconfiguration:\r\n - If you have tests that rely on checking
`access` tags.\r\n - If you have snapshot tests that include the route
definition.\r\n- If you have FTR tests that rely on checking
unauthorized error\r\nmessage. The error message changed to also include
missing privileges.\r\n\r\n## Any questions?\r\nIf you have any
questions or need help with API authorization, please\r\nreach out to
the `@elastic/kibana-security` team.\r\n\r\nCo-authored-by: Maxim
Palenov <[email protected]>\r\nCo-authored-by: Elastic Machine
<[email protected]>\r\nCo-authored-by: Larry
Gregory
<[email protected]>","sha":"6e9520aca268c413b2e2264830791d68dbf7dcc9"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/198383","number":198383,"mergeCommit":{"message":"Authorized
route migration for routes owned by security-detection-rule-management
(elastic#198383)\n\n### Authz API migration for authorized routes\r\n\r\nThis
PR migrates `access:<privilege>` tags used in route definitions
to\r\nnew security configuration.\r\nPlease refer to the documentation
for more information:
[Authorization\r\nAPI](https://docs.elastic.dev/kibana-dev-docs/key-concepts/security-api-authorization)\r\n\r\n###
**Before migration:**\r\nAccess control tags were defined in the
`options` object of the route:\r\n\r\n```ts\r\nrouter.get({\r\n path:
'/api/path',\r\n options: {\r\n tags: ['access:<privilege_1>',
'access:<privilege_2>'],\r\n },\r\n ...\r\n},
handler);\r\n```\r\n\r\n### **After migration:**\r\nTags have been
replaced with the more robust\r\n`security.authz.requiredPrivileges`
field under `security`:\r\n\r\n```ts\r\nrouter.get({\r\n path:
'/api/path',\r\n security: {\r\n authz: {\r\n requiredPrivileges:
['<privilege_1>', '<privilege_2>'],\r\n },\r\n },\r\n ...\r\n},
handler);\r\n```\r\n\r\n### What to do next?\r\n1. Review the changes in
this PR.\r\n2. You might need to update your tests to reflect the new
security\r\nconfiguration:\r\n - If you have tests that rely on checking
`access` tags.\r\n - If you have snapshot tests that include the route
definition.\r\n- If you have FTR tests that rely on checking
unauthorized error\r\nmessage. The error message changed to also include
missing privileges.\r\n\r\n## Any questions?\r\nIf you have any
questions or need help with API authorization, please\r\nreach out to
the `@elastic/kibana-security` team.\r\n\r\nCo-authored-by: Maxim
Palenov <[email protected]>\r\nCo-authored-by: Elastic Machine
<[email protected]>\r\nCo-authored-by: Larry
Gregory
<[email protected]>","sha":"6e9520aca268c413b2e2264830791d68dbf7dcc9"}}]}]
BACKPORT-->
  • Loading branch information
kibanamachine authored Nov 19, 2024
1 parent 43fa8a5 commit acafd04
Show file tree
Hide file tree
Showing 31 changed files with 144 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ export const getAllIntegrationsRoute = (router: SecuritySolutionPluginRouter) =>
.get({
access: 'internal',
path: GET_ALL_INTEGRATIONS_URL,
options: {
tags: ['access:securitySolution'],
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
})
.addVersion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ export const getInstalledIntegrationsRoute = (router: SecuritySolutionPluginRout
.get({
access: 'internal',
path: GET_INSTALLED_INTEGRATIONS_URL,
options: {
tags: ['access:securitySolution'],
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
})
.addVersion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ export const bootstrapPrebuiltRulesRoute = (router: SecuritySolutionPluginRouter
.post({
access: 'internal',
path: BOOTSTRAP_PREBUILT_RULES_URL,
options: {
tags: ['access:securitySolution'],
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
})
.addVersion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ export const getPrebuiltRulesAndTimelinesStatusRoute = (router: SecuritySolution
.get({
access: 'public',
path: PREBUILT_RULES_STATUS_URL,
options: {
tags: ['access:securitySolution'],
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
})
.addVersion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ export const getPrebuiltRulesStatusRoute = (router: SecuritySolutionPluginRouter
.get({
access: 'internal',
path: GET_PREBUILT_RULES_STATUS_URL,
options: {
tags: ['access:securitySolution'],
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
})
.addVersion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ export const installPrebuiltRulesAndTimelinesRoute = (router: SecuritySolutionPl
.put({
access: 'public',
path: PREBUILT_RULES_URL,
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
options: {
tags: ['access:securitySolution'],
timeout: {
idleSocket: PREBUILT_RULES_OPERATION_SOCKET_TIMEOUT_MS,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ export const performRuleInstallationRoute = (router: SecuritySolutionPluginRoute
.post({
access: 'internal',
path: PERFORM_RULE_INSTALLATION_URL,
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
options: {
tags: ['access:securitySolution'],
timeout: {
idleSocket: PREBUILT_RULES_OPERATION_SOCKET_TIMEOUT_MS,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ export const performRuleUpgradeRoute = (
.post({
access: 'internal',
path: PERFORM_RULE_UPGRADE_URL,
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
options: {
tags: ['access:securitySolution'],
timeout: {
idleSocket: PREBUILT_RULES_OPERATION_SOCKET_TIMEOUT_MS,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ export const reviewRuleInstallationRoute = (router: SecuritySolutionPluginRouter
.post({
access: 'internal',
path: REVIEW_RULE_INSTALLATION_URL,
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
options: {
tags: ['access:securitySolution'],
timeout: {
idleSocket: PREBUILT_RULES_OPERATION_SOCKET_TIMEOUT_MS,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ export const reviewRuleUpgradeRoute = (router: SecuritySolutionPluginRouter) =>
.post({
access: 'internal',
path: REVIEW_RULE_UPGRADE_URL,
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
options: {
tags: ['access:securitySolution'],
timeout: {
idleSocket: PREBUILT_RULES_OPERATION_SOCKET_TIMEOUT_MS,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,13 @@ export const performBulkActionRoute = (
.post({
access: 'public',
path: DETECTION_ENGINE_RULES_BULK_ACTION,
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
options: {
tags: ['access:securitySolution', routeLimitedConcurrencyTag(MAX_ROUTE_CONCURRENCY)],
tags: [routeLimitedConcurrencyTag(MAX_ROUTE_CONCURRENCY)],
timeout: {
idleSocket: RULE_MANAGEMENT_BULK_ACTION_SOCKET_TIMEOUT_MS,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ export const bulkCreateRulesRoute = (router: SecuritySolutionPluginRouter, logge
.post({
access: 'public',
path: DETECTION_ENGINE_RULES_BULK_CREATE,
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
options: {
tags: ['access:securitySolution'],
timeout: {
idleSocket: RULE_MANAGEMENT_BULK_ACTION_SOCKET_TIMEOUT_MS,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ export const bulkPatchRulesRoute = (router: SecuritySolutionPluginRouter, logger
.patch({
access: 'public',
path: DETECTION_ENGINE_RULES_BULK_UPDATE,
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
options: {
tags: ['access:securitySolution'],
timeout: {
idleSocket: RULE_MANAGEMENT_BULK_ACTION_SOCKET_TIMEOUT_MS,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ export const bulkUpdateRulesRoute = (router: SecuritySolutionPluginRouter, logge
.put({
access: 'public',
path: DETECTION_ENGINE_RULES_BULK_UPDATE,
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
options: {
tags: ['access:securitySolution'],
timeout: {
idleSocket: RULE_MANAGEMENT_BULK_ACTION_SOCKET_TIMEOUT_MS,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ export const getCoverageOverviewRoute = (router: SecuritySolutionPluginRouter) =
.post({
access: 'internal',
path: RULE_MANAGEMENT_COVERAGE_OVERVIEW_URL,
options: {
tags: ['access:securitySolution'],
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
})
.addVersion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ export const createRuleRoute = (router: SecuritySolutionPluginRouter): void => {
access: 'public',
path: DETECTION_ENGINE_RULES_URL,

options: {
tags: ['access:securitySolution'],
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
})
.addVersion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ export const deleteRuleRoute = (router: SecuritySolutionPluginRouter) => {
.delete({
access: 'public',
path: DETECTION_ENGINE_RULES_URL,
options: {
tags: ['access:securitySolution'],
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
})
.addVersion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ export const exportRulesRoute = (
.post({
access: 'public',
path: `${DETECTION_ENGINE_RULES_URL}/_export`,
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
options: {
tags: ['access:securitySolution'],
timeout: {
idleSocket: RULE_MANAGEMENT_IMPORT_EXPORT_SOCKET_TIMEOUT_MS,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ export const getRuleManagementFilters = (router: SecuritySolutionPluginRouter) =
.get({
access: 'internal',
path: RULE_MANAGEMENT_FILTERS_URL,
options: {
tags: ['access:securitySolution'],
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
})
.addVersion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ export const findRulesRoute = (router: SecuritySolutionPluginRouter, logger: Log
.get({
access: 'public',
path: DETECTION_ENGINE_RULES_URL_FIND,
options: {
tags: ['access:securitySolution'],
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
})
.addVersion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ export const importRulesRoute = (router: SecuritySolutionPluginRouter, config: C
.post({
access: 'public',
path: `${DETECTION_ENGINE_RULES_URL}/_import`,
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
options: {
tags: ['access:securitySolution'],
body: {
maxBytes: config.maxRuleImportPayloadBytes,
output: 'stream',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ export const patchRuleRoute = (router: SecuritySolutionPluginRouter) => {
.patch({
access: 'public',
path: DETECTION_ENGINE_RULES_URL,
options: {
tags: ['access:securitySolution'],
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
})
.addVersion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ export const readRuleRoute = (router: SecuritySolutionPluginRouter, logger: Logg
.get({
access: 'public',
path: DETECTION_ENGINE_RULES_URL,
options: {
tags: ['access:securitySolution'],
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
})
.addVersion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ export const updateRuleRoute = (router: SecuritySolutionPluginRouter) => {
.put({
access: 'public',
path: DETECTION_ENGINE_RULES_URL,
options: {
tags: ['access:securitySolution'],
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
})
.addVersion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ export const readTagsRoute = (router: SecuritySolutionPluginRouter) => {
.get({
access: 'public',
path: DETECTION_ENGINE_TAGS_URL,
options: {
tags: ['access:securitySolution'],
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
})
.addVersion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ export const getClusterHealthRoute = (router: SecuritySolutionPluginRouter) => {
.get({
access: 'internal',
path: GET_CLUSTER_HEALTH_URL,
options: {
tags: ['access:securitySolution'],
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
})
.addVersion(
Expand All @@ -62,8 +64,10 @@ export const getClusterHealthRoute = (router: SecuritySolutionPluginRouter) => {
.post({
access: 'internal',
path: GET_CLUSTER_HEALTH_URL,
options: {
tags: ['access:securitySolution'],
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
})
.addVersion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ export const getRuleHealthRoute = (router: SecuritySolutionPluginRouter) => {
.post({
access: 'internal',
path: GET_RULE_HEALTH_URL,
options: {
tags: ['access:securitySolution'],
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
})
.addVersion(
Expand Down
Loading

0 comments on commit acafd04

Please sign in to comment.