Skip to content

Commit

Permalink
Authorized route migration for routes owned by @elastic/kibana-presen…
Browse files Browse the repository at this point in the history
…tation (#198193)

### 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.

Co-authored-by: James Gowdy <[email protected]>
  • Loading branch information
kibanamachine and jgowdyelastic authored Nov 13, 2024
1 parent b86dc81 commit 05a9b26
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions x-pack/plugins/file_upload/server/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,16 @@ export function fileUploadRoutes(coreSetup: CoreSetup<StartDeps, unknown>, logge
.post({
path: '/internal/file_upload/analyze_file',
access: 'internal',
security: {
authz: {
requiredPrivileges: ['fileUpload:analyzeFile'],
},
},
options: {
body: {
accepts: ['text/*', 'application/json'],
maxBytes: MAX_FILE_SIZE_BYTES,
},
tags: ['access:fileUpload:analyzeFile'],
},
})
.addVersion(
Expand Down Expand Up @@ -260,8 +264,10 @@ export function fileUploadRoutes(coreSetup: CoreSetup<StartDeps, unknown>, logge
.post({
path: '/internal/file_upload/time_field_range',
access: 'internal',
options: {
tags: ['access:fileUpload:analyzeFile'],
security: {
authz: {
requiredPrivileges: ['fileUpload:analyzeFile'],
},
},
})
.addVersion(
Expand Down Expand Up @@ -313,8 +319,10 @@ export function fileUploadRoutes(coreSetup: CoreSetup<StartDeps, unknown>, logge
.post({
path: '/internal/file_upload/preview_index_time_range',
access: 'internal',
options: {
tags: ['access:fileUpload:analyzeFile'],
security: {
authz: {
requiredPrivileges: ['fileUpload:analyzeFile'],
},
},
})
.addVersion(
Expand Down Expand Up @@ -356,8 +364,12 @@ export function fileUploadRoutes(coreSetup: CoreSetup<StartDeps, unknown>, logge
.post({
path: '/internal/file_upload/preview_tika_contents',
access: 'internal',
security: {
authz: {
requiredPrivileges: ['fileUpload:analyzeFile'],
},
},
options: {
tags: ['access:fileUpload:analyzeFile'],
body: {
accepts: ['application/json'],
maxBytes: MAX_TIKA_FILE_SIZE_BYTES,
Expand Down

0 comments on commit 05a9b26

Please sign in to comment.