Skip to content

Commit

Permalink
Authorized route migration for routes owned by security-threat-huntin…
Browse files Browse the repository at this point in the history
…g-investigations (#198387)

### Authz API migration for authorized routes

This PR migrates `access:<privilege>` tags used in route definitions to
new security configuration.
Please refer to the documentation for more information: [Authorization
API](https://docs.elastic.dev/kibana-dev-docs/key-concepts/security-api-authorization)

### **Before migration:**
Access control tags were defined in the `options` object of the route:

```ts
router.get({
  path: '/api/path',
  options: {
    tags: ['access:<privilege_1>', 'access:<privilege_2>'],
  },
  ...
}, handler);
```

### **After migration:**
Tags have been replaced with the more robust
`security.authz.requiredPrivileges` field under `security`:

```ts
router.get({
  path: '/api/path',
  security: {
    authz: {
      requiredPrivileges: ['<privilege_1>', '<privilege_2>'],
    },
  },
  ...
}, handler);
```

### What to do next?
1. Review the changes in this PR.
2. You might need to update your tests to reflect the new security
configuration:
  - If you have tests that rely on checking `access` tags.
  - If you have snapshot tests that include the route definition.
- If you have FTR tests that rely on checking unauthorized error
message. The error message changed to also include missing privileges.

## Any questions?
If you have any questions or need help with API authorization, please
reach out to the `@elastic/kibana-security` team.
  • Loading branch information
kibanamachine authored Nov 19, 2024
1 parent 302652c commit b3f27a9
Show file tree
Hide file tree
Showing 17 changed files with 70 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ export const cleanDraftTimelinesRoute = (router: SecuritySolutionPluginRouter) =
router.versioned
.post({
path: TIMELINE_DRAFT_URL,
options: {
tags: ['access:securitySolution'],
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
access: 'public',
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ export const getDraftTimelinesRoute = (router: SecuritySolutionPluginRouter) =>
router.versioned
.get({
path: TIMELINE_DRAFT_URL,
options: {
tags: ['access:securitySolution'],
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
access: 'public',
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ export const deleteNoteRoute = (router: SecuritySolutionPluginRouter) => {
router.versioned
.delete({
path: NOTE_URL,
options: {
tags: ['access:securitySolution'],
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
access: 'public',
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ export const getNotesRoute = (
router.versioned
.get({
path: NOTE_URL,
options: {
tags: ['access:securitySolution'],
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
access: 'public',
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ export const persistNoteRoute = (router: SecuritySolutionPluginRouter) => {
router.versioned
.patch({
path: NOTE_URL,
options: {
tags: ['access:securitySolution'],
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
access: 'public',
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ export const persistPinnedEventRoute = (router: SecuritySolutionPluginRouter) =>
router.versioned
.patch({
path: PINNED_EVENT_URL,
options: {
tags: ['access:securitySolution'],
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
access: 'public',
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ export const installPrepackedTimelinesRoute = (
router.versioned
.post({
path: `${TIMELINE_PREPACKAGED_URL}`,
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
options: {
tags: ['access:securitySolution'],
body: {
maxBytes: config.maxTimelineImportPayloadBytes,
output: 'stream',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ export const copyTimelineRoute = (router: SecuritySolutionPluginRouter) => {
router.versioned
.post({
path: TIMELINE_COPY_URL,
options: {
tags: ['access:securitySolution'],
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
access: 'internal',
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ export const createTimelinesRoute = (router: SecuritySolutionPluginRouter) => {
router.versioned
.post({
path: TIMELINE_URL,
options: {
tags: ['access:securitySolution'],
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
access: 'public',
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ export const deleteTimelinesRoute = (router: SecuritySolutionPluginRouter) => {
router.versioned
.delete({
path: TIMELINE_URL,
options: {
tags: ['access:securitySolution'],
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
access: 'public',
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ export const exportTimelinesRoute = (router: SecuritySolutionPluginRouter, confi
router.versioned
.post({
path: TIMELINE_EXPORT_URL,
options: {
tags: ['access:securitySolution'],
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
access: 'public',
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ export const getTimelineRoute = (router: SecuritySolutionPluginRouter) => {
router.versioned
.get({
path: TIMELINE_URL,
options: {
tags: ['access:securitySolution'],
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
access: 'public',
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ export const getTimelinesRoute = (router: SecuritySolutionPluginRouter) => {
router.versioned
.get({
path: TIMELINES_URL,
options: {
tags: ['access:securitySolution'],
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
access: 'public',
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ export const importTimelinesRoute = (router: SecuritySolutionPluginRouter, confi
router.versioned
.post({
path: `${TIMELINE_IMPORT_URL}`,
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
options: {
tags: ['access:securitySolution'],
body: {
maxBytes: config.maxTimelineImportPayloadBytes,
output: 'stream',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ export const patchTimelinesRoute = (router: SecuritySolutionPluginRouter) => {
router.versioned
.patch({
path: TIMELINE_URL,
options: {
tags: ['access:securitySolution'],
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
access: 'public',
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ export const persistFavoriteRoute = (router: SecuritySolutionPluginRouter) => {
router.versioned
.patch({
path: TIMELINE_FAVORITE_URL,
options: {
tags: ['access:securitySolution'],
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
access: 'public',
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ export const resolveTimelineRoute = (router: SecuritySolutionPluginRouter) => {
router.versioned
.get({
path: TIMELINE_RESOLVE_URL,
options: {
tags: ['access:securitySolution'],
security: {
authz: {
requiredPrivileges: ['securitySolution'],
},
},
access: 'public',
})
Expand Down

0 comments on commit b3f27a9

Please sign in to comment.