Skip to content

Commit

Permalink
Authorized route migration for routes owned by @elastic/kibana-cloud-…
Browse files Browse the repository at this point in the history
…security-posture (#198189)

### 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: Paulo Silva <[email protected]>
  • Loading branch information
kibanamachine and opauloh authored Nov 19, 2024
1 parent 75be9c3 commit 2dc1ce3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ export const defineGetPoliciesRoute = (router: CloudDefendRouter) =>
.get({
access: 'internal',
path: POLICIES_ROUTE_PATH,
options: {
tags: ['access:cloud-defend-read'],
security: {
authz: {
requiredPrivileges: ['cloud-defend-read'],
},
},
})
.addVersion(
Expand Down
6 changes: 4 additions & 2 deletions x-pack/plugins/cloud_defend/server/routes/status/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,10 @@ export const defineGetCloudDefendStatusRoute = (router: CloudDefendRouter) =>
.get({
access: 'internal',
path: STATUS_ROUTE_PATH,
options: {
tags: ['access:cloud-defend-read'],
security: {
authz: {
requiredPrivileges: ['cloud-defend-read'],
},
},
})
.addVersion({ version: '1', validate: {} }, async (context, request, response) => {
Expand Down

0 comments on commit 2dc1ce3

Please sign in to comment.